]> git.sur5r.net Git - openldap/blob - libraries/liblutil/ptest.c
Merge remote-tracking branch 'origin/mdb.master'
[openldap] / libraries / liblutil / ptest.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2013 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19
20 #include <ac/stdlib.h>
21
22 #include <ac/ctype.h>
23 #include <ac/signal.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
26 #include <ac/time.h>
27
28 #include <lber.h>
29
30 #include "lutil.h"
31
32 /*
33  * Password Test Program
34  */
35
36 static char *hash[] = {
37 #ifdef SLAP_AUTHPASSWD
38         "SHA1", "MD5",
39 #else
40 #ifdef SLAPD_CRYPT
41         "{CRYPT}",
42 #endif
43         "{SSHA}", "{SMD5}",
44         "{SHA}", "{MD5}",
45         "{BOGUS}",
46 #endif
47         NULL
48 };
49
50 static struct berval pw[] = {
51         { sizeof("secret")-1,                   "secret" },
52         { sizeof("binary\0secret")-1,   "binary\0secret" },
53         { 0, NULL }
54 };
55
56 int
57 main( int argc, char *argv[] )
58 {
59         int i, j, rc;
60         struct berval *passwd;
61 #ifdef SLAP_AUTHPASSWD
62         struct berval *salt;
63 #endif
64         struct berval bad;
65         bad.bv_val = "bad password";
66         bad.bv_len = sizeof("bad password")-1;
67
68         for( i= 0; hash[i]; i++ ) {
69                 for( j = 0; pw[j].bv_len; j++ ) {
70 #ifdef SLAP_AUTHPASSWD
71                         rc = lutil_authpasswd_hash( &pw[j],
72                                 &passwd, &salt, hash[i] );
73
74                         if( rc )
75 #else
76                         passwd = lutil_passwd_hash( &pw[j], hash[i] );
77
78                         if( passwd == NULL )
79 #endif
80                         {
81                                 printf("%s generate fail: %s (%d)\n", 
82                                         hash[i], pw[j].bv_val, pw[j].bv_len );
83                                 continue;
84                         }
85
86
87 #ifdef SLAP_AUTHPASSWD
88                         rc = lutil_authpasswd( &pw[j], passwd, salt, NULL );
89 #else
90                         rc = lutil_passwd( passwd, &pw[j], NULL );
91 #endif
92
93                         printf("%s (%d): %s (%d)\t(%d) %s\n",
94                                 pw[j].bv_val, pw[j].bv_len, passwd->bv_val, passwd->bv_len,
95                                 rc, rc == 0 ? "OKAY" : "BAD" );
96
97 #ifdef SLAP_AUTHPASSWD
98                         rc = lutil_authpasswd( passwd, salt, &bad, NULL );
99 #else
100                         rc = lutil_passwd( passwd, &bad, NULL );
101 #endif
102
103                         printf("%s (%d): %s (%d)\t(%d) %s\n",
104                                 bad.bv_val, bad.bv_len, passwd->bv_val, passwd->bv_len,
105                                 rc, rc != 0 ? "OKAY" : "BAD" );
106                 }
107
108                 printf("\n");
109         }
110
111         return EXIT_SUCCESS;
112 }