2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2003 The OpenLDAP Foundation.
5 * Portions Copyright 1998-2003 Kurt D. Zeilenga.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Kurt Zeilenga for inclusion
18 * in OpenLDAP Software.
25 #include <ac/stdlib.h>
28 #include <ac/signal.h>
29 #include <ac/socket.h>
30 #include <ac/string.h>
32 #include <ac/unistd.h>
37 #include "ldap_defaults.h"
39 static int verbose = 0;
45 "Usage: %s [options]\n"
46 " -h hash\tpassword scheme\n"
47 " -s secret\tnew password\n"
48 " -c format\tcrypt(3) salt format\n"
49 " -u\t\tgenerate RFC2307 values (default)\n"
50 " -v\t\tincrease verbosity\n"
51 " -T file\tread file for new password\n"
58 main( int argc, char *argv[] )
60 char *scheme = "{SSHA}";
67 struct berval *hash = NULL;
69 while( (i = getopt( argc, argv,
70 "c:d:h:s:T:vu" )) != EOF )
73 case 'c': /* crypt salt format */
75 lutil_salt_format( optarg );
78 case 'h': /* scheme */
79 scheme = strdup( optarg );
82 case 's': /* new password (secret) */
85 newpw = strdup( optarg );
87 for( p = optarg; *p != '\0'; p++ ) {
92 case 'T': /* password file */
96 case 'u': /* RFC2307 userPassword */
99 case 'v': /* verbose */
108 if( argc - optind != 0 ) {
112 if( pwfile != NULL ) {
113 if( lutil_get_filed_password( pwfile, &passwd )) {
117 if( newpw == NULL ) {
118 /* prompt for new password */
120 newpw = strdup(getpassphrase("New password: "));
121 cknewpw = getpassphrase("Re-enter new password: ");
123 if( strcmp( newpw, cknewpw )) {
124 fprintf( stderr, "Password values do not match\n" );
129 passwd.bv_val = newpw;
130 passwd.bv_len = strlen(passwd.bv_val);
133 hash = lutil_passwd_hash( &passwd, scheme, &text );
135 if( hash == NULL || hash->bv_val == NULL ) {
136 fprintf( stderr, "Password generation failed. %s\n",
141 if( lutil_passwd( hash, &passwd, NULL, &text ) ) {
142 fprintf( stderr, "Password verification failed. %s\n",
147 printf( "%s\n" , hash->bv_val );