pwd_init.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. static Slapi_PluginDesc sha256_pdesc = { "sha256-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Secure Hashing Algorithm (SHA256)" };
  46. static Slapi_PluginDesc ssha256_pdesc = { "ssha256-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Salted Secure Hashing Algorithm (SSHA256)" };
  47. static Slapi_PluginDesc sha384_pdesc = { "sha384-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Secure Hashing Algorithm (SHA384)" };
  48. static Slapi_PluginDesc ssha384_pdesc = { "ssha384-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Salted Secure Hashing Algorithm (SSHA384)" };
  49. static Slapi_PluginDesc sha512_pdesc = { "sha512-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Secure Hashing Algorithm (SHA512)" };
  50. static Slapi_PluginDesc ssha512_pdesc = { "ssha512-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Salted Secure Hashing Algorithm (SSHA512)" };
  51. #ifndef _WIN32
  52. static Slapi_PluginDesc crypt_pdesc = { "crypt-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Unix crypt algorithm (CRYPT)" };
  53. #endif
  54. static Slapi_PluginDesc clear_pdesc = { "clear-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "No encryption (CLEAR)" };
  55. static Slapi_PluginDesc ns_mta_md5_pdesc = { "NS-MTA-MD5-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Netscape MD5 (NS-MTA-MD5)" };
  56. static Slapi_PluginDesc md5_pdesc = { "md5-password-storage-scheme", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "MD5 hash algorithm (MD5)" };
  57. static char *plugin_name = "NSPwdStoragePlugin";
  58. int
  59. sha_pwd_storage_scheme_init( Slapi_PBlock *pb )
  60. {
  61. int rc;
  62. char *name;
  63. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> sha_pwd_storage_scheme_init\n" );
  64. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  65. (void *) SLAPI_PLUGIN_VERSION_01 );
  66. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  67. (void *)&sha_pdesc );
  68. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  69. (void *) sha1_pw_enc);
  70. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  71. (void *) sha1_pw_cmp );
  72. name = slapi_ch_strdup("SHA");
  73. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  74. name );
  75. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= sha_pwd_storage_scheme_init %d\n\n", rc );
  76. return( rc );
  77. }
  78. int
  79. ssha_pwd_storage_scheme_init( Slapi_PBlock *pb )
  80. {
  81. int rc;
  82. char *name;
  83. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> ssha_pwd_storage_scheme_init\n" );
  84. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  85. (void *) SLAPI_PLUGIN_VERSION_01 );
  86. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  87. (void *)&ssha_pdesc );
  88. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  89. (void *) salted_sha1_pw_enc );
  90. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  91. (void *) sha1_pw_cmp );
  92. name = slapi_ch_strdup("SSHA");
  93. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  94. name );
  95. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= ssha_pwd_storage_scheme_init %d\n\n", rc );
  96. return( rc );
  97. }
  98. int
  99. sha256_pwd_storage_scheme_init( Slapi_PBlock *pb )
  100. {
  101. int rc;
  102. char *name;
  103. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> sha256_pwd_storage_scheme_init\n" );
  104. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  105. (void *) SLAPI_PLUGIN_VERSION_01 );
  106. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  107. (void *)&sha256_pdesc );
  108. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  109. (void *) sha256_pw_enc);
  110. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  111. (void *) sha256_pw_cmp );
  112. name = slapi_ch_strdup("SHA256");
  113. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  114. name );
  115. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= sha256_pwd_storage_scheme_init %d\n\n", rc );
  116. return( rc );
  117. }
  118. int
  119. ssha256_pwd_storage_scheme_init( Slapi_PBlock *pb )
  120. {
  121. int rc;
  122. char *name;
  123. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> ssha256_pwd_storage_scheme_init\n" );
  124. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  125. (void *) SLAPI_PLUGIN_VERSION_01 );
  126. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  127. (void *)&ssha256_pdesc );
  128. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  129. (void *) salted_sha256_pw_enc );
  130. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  131. (void *) sha256_pw_cmp );
  132. name = slapi_ch_strdup("SSHA256");
  133. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  134. name );
  135. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= ssha256_pwd_storage_scheme_init %d\n\n", rc );
  136. return( rc );
  137. }
  138. int
  139. sha384_pwd_storage_scheme_init( Slapi_PBlock *pb )
  140. {
  141. int rc;
  142. char *name;
  143. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> sha384_pwd_storage_scheme_init\n" );
  144. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  145. (void *) SLAPI_PLUGIN_VERSION_01 );
  146. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  147. (void *)&sha384_pdesc );
  148. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  149. (void *) sha384_pw_enc);
  150. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  151. (void *) sha384_pw_cmp );
  152. name = slapi_ch_strdup("SHA384");
  153. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  154. name );
  155. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= sha384_pwd_storage_scheme_init %d\n\n", rc );
  156. return( rc );
  157. }
  158. int
  159. ssha384_pwd_storage_scheme_init( Slapi_PBlock *pb )
  160. {
  161. int rc;
  162. char *name;
  163. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> ssha384_pwd_storage_scheme_init\n" );
  164. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  165. (void *) SLAPI_PLUGIN_VERSION_01 );
  166. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  167. (void *)&ssha384_pdesc );
  168. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  169. (void *) salted_sha384_pw_enc );
  170. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  171. (void *) sha384_pw_cmp );
  172. name = slapi_ch_strdup("SSHA384");
  173. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  174. name );
  175. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= ssha384_pwd_storage_scheme_init %d\n\n", rc );
  176. return( rc );
  177. }
  178. int
  179. sha512_pwd_storage_scheme_init( Slapi_PBlock *pb )
  180. {
  181. int rc;
  182. char *name;
  183. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> sha512_pwd_storage_scheme_init\n" );
  184. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  185. (void *) SLAPI_PLUGIN_VERSION_01 );
  186. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  187. (void *)&sha512_pdesc );
  188. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  189. (void *) sha512_pw_enc);
  190. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  191. (void *) sha512_pw_cmp );
  192. name = slapi_ch_strdup("SHA512");
  193. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  194. name );
  195. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= sha512_pwd_storage_scheme_init %d\n\n", rc );
  196. return( rc );
  197. }
  198. int
  199. ssha512_pwd_storage_scheme_init( Slapi_PBlock *pb )
  200. {
  201. int rc;
  202. char *name;
  203. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> ssha512_pwd_storage_scheme_init\n" );
  204. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  205. (void *) SLAPI_PLUGIN_VERSION_01 );
  206. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  207. (void *)&ssha512_pdesc );
  208. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  209. (void *) salted_sha512_pw_enc );
  210. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  211. (void *) sha512_pw_cmp );
  212. name = slapi_ch_strdup("SSHA512");
  213. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  214. name );
  215. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= ssha512_pwd_storage_scheme_init %d\n\n", rc );
  216. return( rc );
  217. }
  218. #ifndef _WIN32
  219. int
  220. crypt_pwd_storage_scheme_init( Slapi_PBlock *pb )
  221. {
  222. int rc;
  223. char *name;
  224. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> crypt_pwd_storage_scheme_init\n" );
  225. crypt_init();
  226. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  227. (void *) SLAPI_PLUGIN_VERSION_01 );
  228. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  229. (void *)&crypt_pdesc );
  230. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  231. (void *) crypt_pw_enc );
  232. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  233. (void *) crypt_pw_cmp );
  234. name = slapi_ch_strdup("CRYPT");
  235. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  236. name );
  237. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= crypt_pwd_storage_scheme_init %d\n\n", rc );
  238. return( rc );
  239. }
  240. #endif
  241. int
  242. clear_pwd_storage_scheme_init( Slapi_PBlock *pb )
  243. {
  244. int rc;
  245. char *name;
  246. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> clear_pwd_storage_scheme_init\n" );
  247. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  248. (void *) SLAPI_PLUGIN_VERSION_01 );
  249. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  250. (void *)&clear_pdesc );
  251. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  252. (void *) clear_pw_enc );
  253. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  254. (void *) clear_pw_cmp );
  255. name = slapi_ch_strdup("CLEAR");
  256. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  257. name );
  258. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= clear_pwd_storage_scheme_init %d\n\n", rc );
  259. return( rc );
  260. }
  261. int
  262. ns_mta_md5_pwd_storage_scheme_init( Slapi_PBlock *pb )
  263. {
  264. int rc;
  265. char *name;
  266. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> ns_mta_md5_pwd_storage_scheme_init\n" );
  267. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  268. (void *) SLAPI_PLUGIN_VERSION_01 );
  269. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  270. (void *)&ns_mta_md5_pdesc );
  271. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  272. (void *) NULL );
  273. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  274. (void *) ns_mta_md5_pw_cmp );
  275. name = slapi_ch_strdup("NS-MTA-MD5");
  276. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  277. name );
  278. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= ns_mta_md5_pwd_storage_scheme_init %d\n\n", rc );
  279. return( rc );
  280. }
  281. int
  282. md5_pwd_storage_scheme_init( Slapi_PBlock *pb )
  283. {
  284. int rc;
  285. char *name;
  286. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> md5_pwd_storage_scheme_init\n" );
  287. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  288. (void *) SLAPI_PLUGIN_VERSION_01 );
  289. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  290. (void *)&md5_pdesc );
  291. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN,
  292. (void *) md5_pw_enc );
  293. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN,
  294. (void *) md5_pw_cmp );
  295. name = slapi_ch_strdup("MD5");
  296. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME,
  297. name );
  298. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= md5_pwd_storage_scheme_init %d\n\n", rc );
  299. return( rc );
  300. }