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 " -v\t\tincrease verbosity\n"
41 main( int argc, char *argv[] )
44 char *scheme = "{SSHA}";
50 struct berval *hash = NULL;
52 while( (i = getopt( argc, argv,
56 case 'h': /* scheme */
57 scheme = strdup (optarg);
59 case 's': /* new password (secret) */
60 newpw = strdup (optarg);
65 for( p = optarg; *p == '\0'; p++ ) {
71 case 'v': /* verbose */
80 if( argc - optind != 0 ) {
85 /* prompt for new password */
87 newpw = strdup(getpassphrase("New password: "));
88 cknewpw = getpassphrase("Re-enter new password: ");
90 if( strncmp( newpw, cknewpw, strlen(newpw) )) {
91 fprintf( stderr, "passwords do not match\n" );
96 passwd.bv_val = newpw;
97 passwd.bv_len = strlen(passwd.bv_val);
99 hash = lutil_passwd_hash( &passwd, scheme );
101 if( hash == NULL || hash->bv_val == NULL ) {
102 fprintf( stderr, "Password generation failed.\n");
106 if( lutil_passwd( hash, &passwd, NULL ) ) {
107 fprintf( stderr, "Password verificaiton failed.\n");
111 printf( "%s\n" , hash->bv_val );