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 " -c format\tcrypt(3) salt format\n"
35 " -u\t\tgenerate RFC2307 values (default)\n"
36 " -v\t\tincrease verbosity\n"
43 main( int argc, char *argv[] )
46 char *scheme = "{SSHA}";
52 struct berval *hash = NULL;
54 while( (i = getopt( argc, argv,
55 "c:d:h:s:vu" )) != EOF )
58 case 'c': /* crypt salt format */
60 lutil_salt_format( optarg );
63 case 'h': /* scheme */
64 scheme = strdup( optarg );
67 case 's': /* new password (secret) */
70 newpw = strdup( optarg );
72 for( p = optarg; *p != '\0'; p++ ) {
78 case 'u': /* RFC2307 userPassword */
81 case 'v': /* verbose */
90 if( argc - optind != 0 ) {
95 /* prompt for new password */
97 newpw = strdup(getpassphrase("New password: "));
98 cknewpw = getpassphrase("Re-enter new password: ");
100 if( strncmp( newpw, cknewpw, strlen(newpw) )) {
101 fprintf( stderr, "Password values do not match\n" );
106 passwd.bv_val = newpw;
107 passwd.bv_len = strlen(passwd.bv_val);
109 hash = lutil_passwd_hash( &passwd, scheme );
111 if( hash == NULL || hash->bv_val == NULL ) {
112 fprintf( stderr, "Password generation failed.\n");
116 if( lutil_passwd( hash, &passwd, NULL ) ) {
117 fprintf( stderr, "Password verification failed.\n");
121 printf( "%s\n" , hash->bv_val );