rever.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <sys/types.h>
  15. #include "rever.h"
  16. static Slapi_PluginDesc pdesc_aes = { "aes-storage-scheme", VENDOR, DS_PACKAGE_VERSION, "AES storage scheme plugin" };
  17. static Slapi_PluginDesc pdesc_des = { "des-storage-scheme", VENDOR, DS_PACKAGE_VERSION, "DES storage scheme plugin" };
  18. static char *plugin_name = "ReverStoragePlugin";
  19. #define AES_MECH 1
  20. #define DES_MECH 2
  21. int
  22. aes_cmp( char *userpwd, char *dbpwd )
  23. {
  24. char *cipher = NULL;
  25. int rc = 0;
  26. if ( encode(userpwd, &cipher, AES_MECH) != 0 ){
  27. rc = 1;
  28. } else {
  29. rc = strcmp(cipher, dbpwd);
  30. }
  31. slapi_ch_free_string(&cipher);
  32. return rc;
  33. }
  34. char *
  35. aes_enc( char *pwd )
  36. {
  37. char *cipher = NULL;
  38. if ( encode(pwd, &cipher, AES_MECH) != 0 ){
  39. return(NULL);
  40. } else {
  41. return( cipher );
  42. }
  43. }
  44. char *
  45. aes_dec( char *pwd, char *alg )
  46. {
  47. char *plain = NULL;
  48. if ( decode(pwd, &plain, AES_MECH, alg) != 0 ){
  49. return(NULL);
  50. } else {
  51. return( plain );
  52. }
  53. }
  54. int
  55. aes_init( Slapi_PBlock *pb)
  56. {
  57. char *name = slapi_ch_strdup(AES_REVER_SCHEME_NAME);
  58. int rc;
  59. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> aes_init\n" );
  60. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, (void *) SLAPI_PLUGIN_VERSION_01 );
  61. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&pdesc_aes );
  62. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN, (void *) aes_enc);
  63. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN, (void *) aes_cmp );
  64. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_DEC_FN, (void *) aes_dec );
  65. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME, name );
  66. init_pbe_plugin();
  67. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= aes_init %d\n", rc );
  68. return( rc );
  69. }
  70. int
  71. des_cmp( char *userpwd, char *dbpwd )
  72. {
  73. char *cipher = NULL;
  74. int rc = 0;
  75. if ( encode(userpwd, &cipher, DES_MECH) != 0 ){
  76. rc = 1;
  77. } else {
  78. rc = strcmp(cipher, dbpwd);
  79. }
  80. slapi_ch_free_string(&cipher);
  81. return rc;
  82. }
  83. char *
  84. des_enc( char *pwd )
  85. {
  86. char *cipher = NULL;
  87. if ( encode(pwd, &cipher, DES_MECH ) != 0 ){
  88. return(NULL);
  89. } else {
  90. return( cipher );
  91. }
  92. }
  93. char *
  94. des_dec( char *pwd )
  95. {
  96. char *plain = NULL;
  97. if ( decode(pwd, &plain, DES_MECH, NULL) != 0 ){
  98. return(NULL);
  99. } else {
  100. return( plain );
  101. }
  102. }
  103. int
  104. des_init( Slapi_PBlock *pb )
  105. {
  106. char *name = slapi_ch_strdup(DES_REVER_SCHEME_NAME);
  107. int rc;
  108. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> des_init\n" );
  109. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, (void *) SLAPI_PLUGIN_VERSION_01 );
  110. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&pdesc_des );
  111. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN, (void *) des_enc);
  112. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN, (void *) des_cmp );
  113. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_DEC_FN, (void *) des_dec );
  114. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME, name );
  115. init_pbe_plugin();
  116. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= des_init %d\n", rc );
  117. return( rc );
  118. }