pwd_init.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <sys/types.h>
  41. #include "pwdstorage.h"
  42. #include "dirver.h"
  43. static Slapi_PluginDesc sha_pdesc = { "sha-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Secure Hashing Algorithm (SHA)" };
  44. static Slapi_PluginDesc ssha_pdesc = { "ssha-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Salted Secure Hashing Algorithm (SSHA)" };
  45. #ifndef _WIN32
  46. static Slapi_PluginDesc crypt_pdesc = { "crypt-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Unix crypt algorithm (CRYPT)" };
  47. #endif
  48. static Slapi_PluginDesc clear_pdesc = { "clear-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "No encryption (CLEAR)" };
  49. static Slapi_PluginDesc ns_mta_md5_pdesc = { "NS-MTA-MD5-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Netscape MD5 (NS-MTA-MD5)" };
  50. static char *plugin_name = "NSPwdStoragePlugin";
  51. int
  52. sha_pwd_storage_scheme_init( Slapi_PBlock *pb )
  53. {
  54. int rc;
  55. char *name;
  56. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> sha_pwd_storage_scheme_init\n" );
  57. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  58. (void *) SLAPI_PLUGIN_VERSION_01 );
  59. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  60. (void *)&sha_pdesc );
  61. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  62. (void *) sha1_pw_enc);
  63. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  64. (void *) sha1_pw_cmp );
  65. name = slapi_ch_strdup("SHA");
  66. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  67. name );
  68. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= sha_pwd_storage_scheme_init %d\n\n", rc );
  69. return( rc );
  70. }
  71. int
  72. ssha_pwd_storage_scheme_init( Slapi_PBlock *pb )
  73. {
  74. int rc;
  75. char *name;
  76. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> ssha_pwd_storage_scheme_init\n" );
  77. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  78. (void *) SLAPI_PLUGIN_VERSION_01 );
  79. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  80. (void *)&ssha_pdesc );
  81. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  82. (void *) salted_sha1_pw_enc );
  83. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  84. (void *) sha1_pw_cmp );
  85. name = slapi_ch_strdup("SSHA");
  86. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  87. name );
  88. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= ssha_pwd_storage_scheme_init %d\n\n", rc );
  89. return( rc );
  90. }
  91. #ifndef _WIN32
  92. int
  93. crypt_pwd_storage_scheme_init( Slapi_PBlock *pb )
  94. {
  95. int rc;
  96. char *name;
  97. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> crypt_pwd_storage_scheme_init\n" );
  98. crypt_init();
  99. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  100. (void *) SLAPI_PLUGIN_VERSION_01 );
  101. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  102. (void *)&crypt_pdesc );
  103. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  104. (void *) crypt_pw_enc );
  105. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  106. (void *) crypt_pw_cmp );
  107. name = slapi_ch_strdup("CRYPT");
  108. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  109. name );
  110. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= crypt_pwd_storage_scheme_init %d\n\n", rc );
  111. return( rc );
  112. }
  113. #endif
  114. int
  115. clear_pwd_storage_scheme_init( Slapi_PBlock *pb )
  116. {
  117. int rc;
  118. char *name;
  119. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> clear_pwd_storage_scheme_init\n" );
  120. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  121. (void *) SLAPI_PLUGIN_VERSION_01 );
  122. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  123. (void *)&clear_pdesc );
  124. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  125. (void *) clear_pw_enc );
  126. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  127. (void *) clear_pw_cmp );
  128. name = slapi_ch_strdup("CLEAR");
  129. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  130. name );
  131. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= clear_pwd_storage_scheme_init %d\n\n", rc );
  132. return( rc );
  133. }
  134. int
  135. ns_mta_md5_pwd_storage_scheme_init( Slapi_PBlock *pb )
  136. {
  137. int rc;
  138. char *name;
  139. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> ns_mta_md5_pwd_storage_scheme_init\n" );
  140. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  141. (void *) SLAPI_PLUGIN_VERSION_01 );
  142. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  143. (void *)&ns_mta_md5_pdesc );
  144. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  145. (void *) NULL );
  146. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  147. (void *) ns_mta_md5_pw_cmp );
  148. name = slapi_ch_strdup("NS-MTA-MD5");
  149. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  150. name );
  151. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= ns_mta_md5_pwd_storage_scheme_init %d\n\n", rc );
  152. return( rc );
  153. }