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] dn\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;
55 while( (i = getopt( argc, argv,
59 case 'h': /* scheme */
60 scheme = strdup (optarg);
62 case 's': /* new password (secret) */
63 newpw = strdup (optarg);
68 for( p = optarg; *p == '\0'; p++ ) {
74 case 'v': /* verbose */
83 if( argc - optind != 0 ) {
88 /* prompt for new password */
90 newpw = strdup(getpass("New password: "));
91 cknewpw = getpass("Re-enter new password: ");
93 if( strncmp( newpw, cknewpw, strlen(newpw) )) {
94 fprintf( stderr, "passwords do not match\n" );
99 passwd.bv_val = newpw;
100 passwd.bv_len = strlen(passwd.bv_val);
102 hash = lutil_passwd_hash( &passwd, scheme );
104 if( hash == NULL || hash->bv_val == NULL ) {
105 fprintf( stderr, "Password generation failed.\n");
109 if( lutil_passwd( hash, &passwd, NULL ) ) {
110 fprintf( stderr, "Password verificaiton failed.\n");
114 printf( "%s\n" , hash->bv_val );