rever.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. int rc;
  58. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> aes_init\n" );
  59. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, (void *) SLAPI_PLUGIN_VERSION_01 );
  60. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&pdesc_aes );
  61. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN, (void *) aes_enc);
  62. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN, (void *) aes_cmp );
  63. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_DEC_FN, (void *) aes_dec );
  64. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME, AES_REVER_SCHEME_NAME );
  65. init_pbe_plugin();
  66. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= aes_init %d\n", rc );
  67. return( rc );
  68. }
  69. int
  70. des_cmp( char *userpwd, char *dbpwd )
  71. {
  72. char *cipher = NULL;
  73. int rc = 0;
  74. if ( encode(userpwd, &cipher, DES_MECH) != 0 ){
  75. rc = 1;
  76. } else {
  77. rc = strcmp(cipher, dbpwd);
  78. }
  79. slapi_ch_free_string(&cipher);
  80. return rc;
  81. }
  82. char *
  83. des_enc( char *pwd )
  84. {
  85. char *cipher = NULL;
  86. if ( encode(pwd, &cipher, DES_MECH ) != 0 ){
  87. return(NULL);
  88. } else {
  89. return( cipher );
  90. }
  91. }
  92. char *
  93. des_dec( char *pwd )
  94. {
  95. char *plain = NULL;
  96. if ( decode(pwd, &plain, DES_MECH, NULL) != 0 ){
  97. return(NULL);
  98. } else {
  99. return( plain );
  100. }
  101. }
  102. int
  103. des_init( Slapi_PBlock *pb )
  104. {
  105. int rc;
  106. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> des_init\n" );
  107. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, (void *) SLAPI_PLUGIN_VERSION_01 );
  108. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&pdesc_des );
  109. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN, (void *) des_enc);
  110. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN, (void *) des_cmp );
  111. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_DEC_FN, (void *) des_dec );
  112. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME, DES_REVER_SCHEME_NAME );
  113. init_pbe_plugin();
  114. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= des_init %d\n", rc );
  115. return( rc );
  116. }