]> git.sur5r.net Git - openldap/blob - libraries/liblutil/ptest.c
cleanup
[openldap] / libraries / liblutil / ptest.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2002 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 /*
24  * Password Test Program
25  */
26
27 static char *hash[] = {
28 #ifdef SLAP_AUTHPASSWD
29         "SHA1", "MD5",
30 #else
31 #ifdef SLAPD_CRYPT
32         "{CRYPT}",
33 #endif
34         "{SSHA}", "{SMD5}",
35         "{SHA}", "{MD5}",
36         "{BOGUS}",
37 #endif
38         NULL
39 };
40
41 static struct berval pw[] = {
42         { sizeof("secret")-1,                   "secret" },
43         { sizeof("binary\0secret")-1,   "binary\0secret" },
44         { 0, NULL }
45 };
46
47 int
48 main( int argc, char *argv[] )
49 {
50         int i, j, rc;
51         struct berval *passwd;
52 #ifdef SLAP_AUTHPASSWD
53         struct berval *salt;
54 #endif
55         struct berval bad;
56         bad.bv_val = "bad password";
57         bad.bv_len = sizeof("bad password")-1;
58
59         for( i= 0; hash[i]; i++ ) {
60                 for( j = 0; pw[j].bv_len; j++ ) {
61 #ifdef SLAP_AUTHPASSWD
62                         rc = lutil_authpasswd_hash( &pw[j],
63                                 &passwd, &salt, hash[i] );
64
65                         if( rc )
66 #else
67                         passwd = lutil_passwd_hash( &pw[j], hash[i] );
68
69                         if( passwd == NULL )
70 #endif
71                         {
72                                 printf("%s generate fail: %s (%d)\n", 
73                                         hash[i], pw[j].bv_val, pw[j].bv_len );
74                                 continue;
75                         }
76
77
78 #ifdef SLAP_AUTHPASSWD
79                         rc = lutil_authpasswd( &pw[j], passwd, salt, NULL );
80 #else
81                         rc = lutil_passwd( passwd, &pw[j], NULL );
82 #endif
83
84                         printf("%s (%d): %s (%d)\t(%d) %s\n",
85                                 pw[j].bv_val, pw[j].bv_len, passwd->bv_val, passwd->bv_len,
86                                 rc, rc == 0 ? "OKAY" : "BAD" );
87
88 #ifdef SLAP_AUTHPASSWD
89                         rc = lutil_authpasswd( passwd, salt, &bad, NULL );
90 #else
91                         rc = lutil_passwd( passwd, &bad, NULL );
92 #endif
93
94                         printf("%s (%d): %s (%d)\t(%d) %s\n",
95                                 bad.bv_val, bad.bv_len, passwd->bv_val, passwd->bv_len,
96                                 rc, rc != 0 ? "OKAY" : "BAD" );
97                 }
98
99                 printf("\n");
100         }
101
102         return EXIT_SUCCESS;
103 }