pwd_init.c 15 KB

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