2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 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 slappasswd( int argc, char *argv[] )
60 char *scheme = "{SSHA}";
64 const char *progname = "slappasswd";
70 while( (i = getopt( argc, argv,
71 "c:d:h:s:T:vu" )) != EOF )
74 case 'c': /* crypt salt format */
76 lutil_salt_format( optarg );
79 case 'h': /* scheme */
80 scheme = strdup( optarg );
83 case 's': /* new password (secret) */
86 newpw = strdup( optarg );
88 for( p = optarg; *p != '\0'; p++ ) {
93 case 'T': /* password file */
97 case 'u': /* RFC2307 userPassword */
100 case 'v': /* verbose */
109 if( argc - optind != 0 ) {
113 if( pwfile != NULL ) {
114 if( lutil_get_filed_password( pwfile, &passwd )) {
118 if( newpw == NULL ) {
119 /* prompt for new password */
121 newpw = strdup(getpassphrase("New password: "));
122 cknewpw = getpassphrase("Re-enter new password: ");
124 if( strcmp( newpw, cknewpw )) {
125 fprintf( stderr, "Password values do not match\n" );
130 passwd.bv_val = newpw;
131 passwd.bv_len = strlen(passwd.bv_val);
134 lutil_passwd_hash( &passwd, scheme, &hash, &text );
135 if( hash.bv_val == NULL ) {
137 "Password generation failed for scheme %s: %s\n",
138 scheme, text ? text : "" );
142 if( lutil_passwd( &hash, &passwd, NULL, &text ) ) {
143 fprintf( stderr, "Password verification failed. %s\n",
148 printf( "%s\n" , hash.bv_val );