pwd_init.c 15 KB

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