Back to index

openldap  2.4.31
ptest.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in the file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 
00016 #include "portable.h"
00017 
00018 #include <stdio.h>
00019 
00020 #include <ac/stdlib.h>
00021 
00022 #include <ac/ctype.h>
00023 #include <ac/signal.h>
00024 #include <ac/socket.h>
00025 #include <ac/string.h>
00026 #include <ac/time.h>
00027 
00028 #include <lber.h>
00029 
00030 #include "lutil.h"
00031 
00032 /*
00033  * Password Test Program
00034  */
00035 
00036 static char *hash[] = {
00037 #ifdef SLAP_AUTHPASSWD
00038        "SHA1", "MD5",
00039 #else
00040 #ifdef SLAPD_CRYPT
00041        "{CRYPT}",
00042 #endif
00043        "{SSHA}", "{SMD5}",
00044        "{SHA}", "{MD5}",
00045        "{BOGUS}",
00046 #endif
00047        NULL
00048 };
00049 
00050 static struct berval pw[] = {
00051        { sizeof("secret")-1,                     "secret" },
00052        { sizeof("binary\0secret")-1,      "binary\0secret" },
00053        { 0, NULL }
00054 };
00055 
00056 int
00057 main( int argc, char *argv[] )
00058 {
00059        int i, j, rc;
00060        struct berval *passwd;
00061 #ifdef SLAP_AUTHPASSWD
00062        struct berval *salt;
00063 #endif
00064        struct berval bad;
00065        bad.bv_val = "bad password";
00066        bad.bv_len = sizeof("bad password")-1;
00067 
00068        for( i= 0; hash[i]; i++ ) {
00069               for( j = 0; pw[j].bv_len; j++ ) {
00070 #ifdef SLAP_AUTHPASSWD
00071                      rc = lutil_authpasswd_hash( &pw[j],
00072                             &passwd, &salt, hash[i] );
00073 
00074                      if( rc )
00075 #else
00076                      passwd = lutil_passwd_hash( &pw[j], hash[i] );
00077 
00078                      if( passwd == NULL )
00079 #endif
00080                      {
00081                             printf("%s generate fail: %s (%d)\n", 
00082                                    hash[i], pw[j].bv_val, pw[j].bv_len );
00083                             continue;
00084                      }
00085 
00086 
00087 #ifdef SLAP_AUTHPASSWD
00088                      rc = lutil_authpasswd( &pw[j], passwd, salt, NULL );
00089 #else
00090                      rc = lutil_passwd( passwd, &pw[j], NULL );
00091 #endif
00092 
00093                      printf("%s (%d): %s (%d)\t(%d) %s\n",
00094                             pw[j].bv_val, pw[j].bv_len, passwd->bv_val, passwd->bv_len,
00095                             rc, rc == 0 ? "OKAY" : "BAD" );
00096 
00097 #ifdef SLAP_AUTHPASSWD
00098                      rc = lutil_authpasswd( passwd, salt, &bad, NULL );
00099 #else
00100                      rc = lutil_passwd( passwd, &bad, NULL );
00101 #endif
00102 
00103                      printf("%s (%d): %s (%d)\t(%d) %s\n",
00104                             bad.bv_val, bad.bv_len, passwd->bv_val, passwd->bv_len,
00105                             rc, rc != 0 ? "OKAY" : "BAD" );
00106               }
00107 
00108               printf("\n");
00109        }
00110 
00111        return EXIT_SUCCESS;
00112 }