rever.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 "rever.h"
  45. static Slapi_PluginDesc pdesc_aes = { "aes-storage-scheme", VENDOR, DS_PACKAGE_VERSION, "AES storage scheme plugin" };
  46. static Slapi_PluginDesc pdesc_des = { "des-storage-scheme", VENDOR, DS_PACKAGE_VERSION, "DES storage scheme plugin" };
  47. static char *plugin_name = "ReverStoragePlugin";
  48. #define AES_MECH 1
  49. #define DES_MECH 2
  50. int
  51. aes_cmp( char *userpwd, char *dbpwd )
  52. {
  53. char *cipher = NULL;
  54. int rc = 0;
  55. if ( encode(userpwd, &cipher, AES_MECH) != 0 ){
  56. rc = 1;
  57. } else {
  58. rc = strcmp(cipher, dbpwd);
  59. }
  60. slapi_ch_free_string(&cipher);
  61. return rc;
  62. }
  63. char *
  64. aes_enc( char *pwd )
  65. {
  66. char *cipher = NULL;
  67. if ( encode(pwd, &cipher, AES_MECH) != 0 ){
  68. return(NULL);
  69. } else {
  70. return( cipher );
  71. }
  72. }
  73. char *
  74. aes_dec( char *pwd, char *alg )
  75. {
  76. char *plain = NULL;
  77. if ( decode(pwd, &plain, AES_MECH, alg) != 0 ){
  78. return(NULL);
  79. } else {
  80. return( plain );
  81. }
  82. }
  83. int
  84. aes_init( Slapi_PBlock *pb)
  85. {
  86. char *name = slapi_ch_strdup(AES_REVER_SCHEME_NAME);
  87. int rc;
  88. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> aes_init\n" );
  89. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, (void *) SLAPI_PLUGIN_VERSION_01 );
  90. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&pdesc_aes );
  91. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN, (void *) aes_enc);
  92. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN, (void *) aes_cmp );
  93. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_DEC_FN, (void *) aes_dec );
  94. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME, name );
  95. init_pbe_plugin();
  96. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= aes_init %d\n", rc );
  97. return( rc );
  98. }
  99. int
  100. des_cmp( char *userpwd, char *dbpwd )
  101. {
  102. char *cipher = NULL;
  103. int rc = 0;
  104. if ( encode(userpwd, &cipher, DES_MECH) != 0 ){
  105. rc = 1;
  106. } else {
  107. rc = strcmp(cipher, dbpwd);
  108. }
  109. slapi_ch_free_string(&cipher);
  110. return rc;
  111. }
  112. char *
  113. des_enc( char *pwd )
  114. {
  115. char *cipher = NULL;
  116. if ( encode(pwd, &cipher, DES_MECH ) != 0 ){
  117. return(NULL);
  118. } else {
  119. return( cipher );
  120. }
  121. }
  122. char *
  123. des_dec( char *pwd )
  124. {
  125. char *plain = NULL;
  126. if ( decode(pwd, &plain, DES_MECH, NULL) != 0 ){
  127. return(NULL);
  128. } else {
  129. return( plain );
  130. }
  131. }
  132. int
  133. des_init( Slapi_PBlock *pb )
  134. {
  135. char *name = slapi_ch_strdup(DES_REVER_SCHEME_NAME);
  136. int rc;
  137. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "=> des_init\n" );
  138. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, (void *) SLAPI_PLUGIN_VERSION_01 );
  139. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&pdesc_des );
  140. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN, (void *) des_enc);
  141. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN, (void *) des_cmp );
  142. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_DEC_FN, (void *) des_dec );
  143. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME, name );
  144. init_pbe_plugin();
  145. slapi_log_error( SLAPI_LOG_PLUGIN, plugin_name, "<= des_init %d\n", rc );
  146. return( rc );
  147. }