1999-12-08 14:44:22 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
1999-12-08 14:44:22 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/signal.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
1999-12-09 09:11:16 +08:00
|
|
|
#include <lber.h>
|
|
|
|
|
1999-12-08 14:44:22 +08:00
|
|
|
#include "lutil.h"
|
|
|
|
|
1999-12-12 13:06:36 +08:00
|
|
|
/*
|
|
|
|
* Password Test Program
|
|
|
|
*/
|
1999-12-09 09:11:16 +08:00
|
|
|
|
2001-12-24 14:36:44 +08:00
|
|
|
static char *hash[] = {
|
2000-04-25 21:28:03 +08:00
|
|
|
#ifdef SLAP_AUTHPASSWD
|
|
|
|
"SHA1", "MD5",
|
|
|
|
#else
|
1999-12-12 13:06:36 +08:00
|
|
|
#ifdef SLAPD_CRYPT
|
|
|
|
"{CRYPT}",
|
2000-04-25 21:28:03 +08:00
|
|
|
#endif
|
|
|
|
"{SSHA}", "{SMD5}",
|
|
|
|
"{SHA}", "{MD5}",
|
|
|
|
"{BOGUS}",
|
1999-12-12 13:06:36 +08:00
|
|
|
#endif
|
1999-12-08 14:44:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
1999-12-09 09:11:16 +08:00
|
|
|
static struct berval pw[] = {
|
|
|
|
{ sizeof("secret")-1, "secret" },
|
2000-04-25 21:28:03 +08:00
|
|
|
{ sizeof("binary\0secret")-1, "binary\0secret" },
|
1999-12-09 09:11:16 +08:00
|
|
|
{ 0, NULL }
|
1999-12-08 14:44:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
int i, j, rc;
|
1999-12-09 09:11:16 +08:00
|
|
|
struct berval *passwd;
|
2000-04-25 21:28:03 +08:00
|
|
|
#ifdef SLAP_AUTHPASSWD
|
|
|
|
struct berval *salt;
|
|
|
|
#endif
|
|
|
|
struct berval bad;
|
|
|
|
bad.bv_val = "bad password";
|
|
|
|
bad.bv_len = sizeof("bad password")-1;
|
1999-12-08 14:44:22 +08:00
|
|
|
|
|
|
|
for( i= 0; hash[i]; i++ ) {
|
1999-12-09 09:11:16 +08:00
|
|
|
for( j = 0; pw[j].bv_len; j++ ) {
|
2000-04-25 21:28:03 +08:00
|
|
|
#ifdef SLAP_AUTHPASSWD
|
|
|
|
rc = lutil_authpasswd_hash( &pw[j],
|
|
|
|
&passwd, &salt, hash[i] );
|
|
|
|
|
|
|
|
if( rc )
|
|
|
|
#else
|
1999-12-12 13:06:36 +08:00
|
|
|
passwd = lutil_passwd_hash( &pw[j], hash[i] );
|
2000-04-25 21:28:03 +08:00
|
|
|
|
|
|
|
if( passwd == NULL )
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
printf("%s generate fail: %s (%d)\n",
|
|
|
|
hash[i], pw[j].bv_val, pw[j].bv_len );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SLAP_AUTHPASSWD
|
|
|
|
rc = lutil_authpasswd( &pw[j], passwd, salt, NULL );
|
|
|
|
#else
|
1999-12-09 09:11:16 +08:00
|
|
|
rc = lutil_passwd( passwd, &pw[j], NULL );
|
2000-04-25 21:28:03 +08:00
|
|
|
#endif
|
1999-12-08 14:44:22 +08:00
|
|
|
|
2000-04-25 21:28:03 +08:00
|
|
|
printf("%s (%d): %s (%d)\t(%d) %s\n",
|
1999-12-09 09:11:16 +08:00
|
|
|
pw[j].bv_val, pw[j].bv_len, passwd->bv_val, passwd->bv_len,
|
2000-04-25 21:28:03 +08:00
|
|
|
rc, rc == 0 ? "OKAY" : "BAD" );
|
|
|
|
|
|
|
|
#ifdef SLAP_AUTHPASSWD
|
|
|
|
rc = lutil_authpasswd( passwd, salt, &bad, NULL );
|
|
|
|
#else
|
|
|
|
rc = lutil_passwd( passwd, &bad, NULL );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("%s (%d): %s (%d)\t(%d) %s\n",
|
|
|
|
bad.bv_val, bad.bv_len, passwd->bv_val, passwd->bv_len,
|
|
|
|
rc, rc != 0 ? "OKAY" : "BAD" );
|
1999-12-08 14:44:22 +08:00
|
|
|
}
|
2000-04-25 21:28:03 +08:00
|
|
|
|
|
|
|
printf("\n");
|
1999-12-08 14:44:22 +08:00
|
|
|
}
|
2000-04-25 21:28:03 +08:00
|
|
|
|
1999-12-08 14:44:22 +08:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|