1 /* $NetBSD: ptest.c,v 1.2 2020/08/11 13:15:39 christos Exp $ */ 2 3 /* $OpenLDAP$ */ 4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 1998-2020 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 <sys/cdefs.h> 19 __RCSID("$NetBSD: ptest.c,v 1.2 2020/08/11 13:15:39 christos Exp $"); 20 21 #include "portable.h" 22 23 #include <stdio.h> 24 25 #include <ac/stdlib.h> 26 27 #include <ac/ctype.h> 28 #include <ac/signal.h> 29 #include <ac/socket.h> 30 #include <ac/string.h> 31 #include <ac/time.h> 32 33 #include <lber.h> 34 35 #include "lutil.h" 36 37 /* 38 * Password Test Program 39 */ 40 41 static char *hash[] = { 42 #ifdef SLAP_AUTHPASSWD 43 "SHA1", "MD5", 44 #else 45 #ifdef SLAPD_CRYPT 46 "{CRYPT}", 47 #endif 48 "{SSHA}", "{SMD5}", 49 "{SHA}", "{MD5}", 50 "{BOGUS}", 51 #endif 52 NULL 53 }; 54 55 static struct berval pw[] = { 56 { sizeof("secret")-1, "secret" }, 57 { sizeof("binary\0secret")-1, "binary\0secret" }, 58 { 0, NULL } 59 }; 60 61 int 62 main( int argc, char *argv[] ) 63 { 64 int i, j, rc; 65 struct berval *passwd; 66 #ifdef SLAP_AUTHPASSWD 67 struct berval *salt; 68 #endif 69 struct berval bad; 70 bad.bv_val = "bad password"; 71 bad.bv_len = sizeof("bad password")-1; 72 73 for( i= 0; hash[i]; i++ ) { 74 for( j = 0; pw[j].bv_len; j++ ) { 75 #ifdef SLAP_AUTHPASSWD 76 rc = lutil_authpasswd_hash( &pw[j], 77 &passwd, &salt, hash[i] ); 78 79 if( rc ) 80 #else 81 passwd = lutil_passwd_hash( &pw[j], hash[i] ); 82 83 if( passwd == NULL ) 84 #endif 85 { 86 printf("%s generate fail: %s (%d)\n", 87 hash[i], pw[j].bv_val, pw[j].bv_len ); 88 continue; 89 } 90 91 92 #ifdef SLAP_AUTHPASSWD 93 rc = lutil_authpasswd( &pw[j], passwd, salt, NULL ); 94 #else 95 rc = lutil_passwd( passwd, &pw[j], NULL ); 96 #endif 97 98 printf("%s (%d): %s (%d)\t(%d) %s\n", 99 pw[j].bv_val, pw[j].bv_len, passwd->bv_val, passwd->bv_len, 100 rc, rc == 0 ? "OKAY" : "BAD" ); 101 102 #ifdef SLAP_AUTHPASSWD 103 rc = lutil_authpasswd( passwd, salt, &bad, NULL ); 104 #else 105 rc = lutil_passwd( passwd, &bad, NULL ); 106 #endif 107 108 printf("%s (%d): %s (%d)\t(%d) %s\n", 109 bad.bv_val, bad.bv_len, passwd->bv_val, passwd->bv_len, 110 rc, rc != 0 ? "OKAY" : "BAD" ); 111 } 112 113 printf("\n"); 114 } 115 116 return EXIT_SUCCESS; 117 } 118