home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ldapsdk.zip / libraries / liblutil / ptest.c < prev    next >
C/C++ Source or Header  |  2000-06-14  |  2KB  |  105 lines

  1. /* $OpenLDAP: pkg/ldap/libraries/liblutil/ptest.c,v 1.5.2.1 2000/06/13 17:57:26 kurt Exp $ */
  2. /*
  3.  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
  4.  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  5.  */
  6.  
  7. #include "portable.h"
  8.  
  9. #include <stdio.h>
  10.  
  11. #include <ac/stdlib.h>
  12.  
  13. #include <ac/ctype.h>
  14. #include <ac/signal.h>
  15. #include <ac/socket.h>
  16. #include <ac/string.h>
  17. #include <ac/time.h>
  18.  
  19. #include <lber.h>
  20.  
  21. #include "lutil.h"
  22.  
  23. // #define SLAP_AUTHPASSWD 1
  24.  
  25. /*
  26.  * Password Test Program
  27.  */
  28.  
  29. char *hash[] = {
  30. #ifdef SLAP_AUTHPASSWD
  31.     "SHA1", "MD5",
  32. #else
  33. #ifdef SLAPD_CRYPT
  34.     "{CRYPT}",
  35. #endif
  36.     "{SSHA}", "{SMD5}",
  37.     "{SHA}", "{MD5}",
  38.     "{BOGUS}",
  39. #endif
  40.     NULL
  41. };
  42.  
  43. static struct berval pw[] = {
  44.     { sizeof("secret")-1,            "secret" },
  45.     { sizeof("binary\0secret")-1,    "binary\0secret" },
  46.     { 0, NULL }
  47. };
  48.  
  49. int
  50. main( int argc, char *argv[] )
  51. {
  52.     int i, j, rc;
  53.     struct berval *passwd;
  54. #ifdef SLAP_AUTHPASSWD
  55.     struct berval *salt;
  56. #endif
  57.     struct berval bad;
  58.     bad.bv_val = "bad password";
  59.     bad.bv_len = sizeof("bad password")-1;
  60.  
  61.     for( i= 0; hash[i]; i++ ) {
  62.         for( j = 0; pw[j].bv_len; j++ ) {
  63. #ifdef SLAP_AUTHPASSWD
  64.             rc = lutil_authpasswd_hash( &pw[j],
  65.                 &passwd, &salt, hash[i] );
  66.  
  67.             if( rc )
  68. #else
  69.             passwd = lutil_passwd_hash( &pw[j], hash[i] );
  70.  
  71.             if( passwd == NULL )
  72. #endif
  73.             {
  74.                 printf("%s generate fail: %s (%d)\n", 
  75.                     hash[i], pw[j].bv_val, pw[j].bv_len );
  76.                 continue;
  77.             }
  78.  
  79.  
  80. #ifdef SLAP_AUTHPASSWD
  81.             rc = lutil_authpasswd( &pw[j], passwd, salt, NULL );
  82. #else
  83.             rc = lutil_passwd( passwd, &pw[j], NULL );
  84. #endif
  85.  
  86.             printf("%s (%d): %s (%d)\t(%d) %s\n",
  87.                 pw[j].bv_val, pw[j].bv_len, passwd->bv_val, passwd->bv_len,
  88.                 rc, rc == 0 ? "OKAY" : "BAD" );
  89.  
  90. #ifdef SLAP_AUTHPASSWD
  91.             rc = lutil_authpasswd( passwd, salt, &bad, NULL );
  92. #else
  93.             rc = lutil_passwd( passwd, &bad, NULL );
  94. #endif
  95.  
  96.             printf("%s (%d): %s (%d)\t(%d) %s\n",
  97.                 bad.bv_val, bad.bv_len, passwd->bv_val, passwd->bv_len,
  98.                 rc, rc != 0 ? "OKAY" : "BAD" );
  99.         }
  100.  
  101.         printf("\n");
  102.     }
  103.  
  104.     return EXIT_SUCCESS;
  105. }