3 * Copyright 1998-2002 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[] )
45 char *scheme = "{SSHA}";
50 struct berval *hash = NULL;
52 while( (i = getopt( argc, argv,
53 "c:d:h:s:vu" )) != EOF )
56 case 'c': /* crypt salt format */
58 lutil_salt_format( optarg );
61 case 'h': /* scheme */
62 scheme = strdup( optarg );
65 case 's': /* new password (secret) */
68 newpw = strdup( optarg );
70 for( p = optarg; *p != '\0'; p++ ) {
76 case 'u': /* RFC2307 userPassword */
79 case 'v': /* verbose */
88 if( argc - optind != 0 ) {
93 /* prompt for new password */
95 newpw = strdup(getpassphrase("New password: "));
96 cknewpw = getpassphrase("Re-enter new password: ");
98 if( strcmp( newpw, cknewpw )) {
99 fprintf( stderr, "Password values do not match\n" );
104 passwd.bv_val = newpw;
105 passwd.bv_len = strlen(passwd.bv_val);
107 hash = lutil_passwd_hash( &passwd, scheme );
109 if( hash == NULL || hash->bv_val == NULL ) {
110 fprintf( stderr, "Password generation failed.\n");
114 if( lutil_passwd( hash, &passwd, NULL ) ) {
115 fprintf( stderr, "Password verification failed.\n");
119 printf( "%s\n" , hash->bv_val );