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