2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 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>
36 #include <lutil_sha1.h>
38 #include "ldap_defaults.h"
40 static int verbose = 0;
46 "Usage: %s [options]\n"
47 " -h hash\tpassword scheme\n"
48 " -s secret\tnew password\n"
49 " -c format\tcrypt(3) salt format\n"
50 " -u\t\tgenerate RFC2307 values (default)\n"
51 " -v\t\tincrease verbosity\n"
52 " -T file\tread file for new password\n"
59 slappasswd( int argc, char *argv[] )
61 #ifdef LUTIL_SHA1_BYTES
62 char *scheme = "{SSHA}";
64 char *scheme = "{SMD5}";
70 const char *progname = "slappasswd";
76 while( (i = getopt( argc, argv,
77 "c:d:h:s:T:vu" )) != EOF )
80 case 'c': /* crypt salt format */
82 lutil_salt_format( optarg );
85 case 'h': /* scheme */
86 scheme = strdup( optarg );
89 case 's': /* new password (secret) */
92 newpw = strdup( optarg );
94 for( p = optarg; *p != '\0'; p++ ) {
99 case 'T': /* password file */
103 case 'u': /* RFC2307 userPassword */
106 case 'v': /* verbose */
115 if( argc - optind != 0 ) {
119 if( pwfile != NULL ) {
120 if( lutil_get_filed_password( pwfile, &passwd )) {
124 if( newpw == NULL ) {
125 /* prompt for new password */
127 newpw = strdup(getpassphrase("New password: "));
128 cknewpw = getpassphrase("Re-enter new password: ");
130 if( strcmp( newpw, cknewpw )) {
131 fprintf( stderr, "Password values do not match\n" );
136 passwd.bv_val = newpw;
137 passwd.bv_len = strlen(passwd.bv_val);
140 lutil_passwd_hash( &passwd, scheme, &hash, &text );
141 if( hash.bv_val == NULL ) {
143 "Password generation failed for scheme %s: %s\n",
144 scheme, text ? text : "" );
148 if( lutil_passwd( &hash, &passwd, NULL, &text ) ) {
149 fprintf( stderr, "Password verification failed. %s\n",
154 printf( "%s\n" , hash.bv_val );