pwd_init.c 13 KB

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