3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/stdlib.h>
14 #include <ac/signal.h>
15 #include <ac/socket.h>
16 #include <ac/string.h>
18 #include <ac/unistd.h>
23 #include "ldap_defaults.h"
25 static int verbose = 0;
31 "Usage: %s [options]\n"
32 " -h hash\tpassword scheme\n"
33 " -s secret\tnew password\n"
34 " -u\t\tgenerate RFC2307 values\n"
35 " -v\t\tincrease verbosity\n"
42 main( int argc, char *argv[] )
45 char *scheme = "{SSHA}";
51 struct berval *hash = NULL;
53 while( (i = getopt( argc, argv,
54 "d:h:s:vu" )) != EOF )
57 case 'h': /* scheme */
58 scheme = strdup (optarg);
60 case 's': /* new password (secret) */
61 newpw = strdup (optarg);
66 for( p = optarg; *p == '\0'; p++ ) {
72 case 'u': /* RFC2307 userPassword */
75 case 'v': /* verbose */
84 if( argc - optind != 0 ) {
89 /* prompt for new password */
91 newpw = strdup(getpassphrase("New password: "));
92 cknewpw = getpassphrase("Re-enter new password: ");
94 if( strncmp( newpw, cknewpw, strlen(newpw) )) {
95 fprintf( stderr, "Password values do not match\n" );
100 passwd.bv_val = newpw;
101 passwd.bv_len = strlen(passwd.bv_val);
103 hash = lutil_passwd_hash( &passwd, scheme );
105 if( hash == NULL || hash->bv_val == NULL ) {
106 fprintf( stderr, "Password generation failed.\n");
110 if( lutil_passwd( hash, &passwd, NULL ) ) {
111 fprintf( stderr, "Password verification failed.\n");
115 printf( "%s\n" , hash->bv_val );