X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Ftools%2Fslappasswd.c;h=cc4d4332629b4e51281fc77efdbd893c8cd375ef;hb=113727ba53c91ab6f1b0880c5908eca43b89ec4e;hp=64b7a1be5e2889a83cc56cfc623032f933012990;hpb=ba37cbc233a791cde63b4e9e08b8fb5e95963ba4;p=openldap diff --git a/servers/slapd/tools/slappasswd.c b/servers/slapd/tools/slappasswd.c index 64b7a1be5e..cc4d433262 100644 --- a/servers/slapd/tools/slappasswd.c +++ b/servers/slapd/tools/slappasswd.c @@ -1,7 +1,21 @@ /* $OpenLDAP$ */ -/* - * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2003 The OpenLDAP Foundation. + * Portions Copyright 1998-2003 Kurt D. Zeilenga. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This work was initially developed by Kurt Zeilenga for inclusion + * in OpenLDAP Software. */ #include "portable.h" @@ -31,8 +45,10 @@ usage(const char *s) "Usage: %s [options]\n" " -h hash\tpassword scheme\n" " -s secret\tnew password\n" - " -u\t\tgenerate RFC2307 values\n" + " -c format\tcrypt(3) salt format\n" + " -u\t\tgenerate RFC2307 values (default)\n" " -v\t\tincrease verbosity\n" + " -T file\tread file for new password\n" , s ); exit( EXIT_FAILURE ); @@ -41,33 +57,40 @@ usage(const char *s) int main( int argc, char *argv[] ) { - int rc; char *scheme = "{SSHA}"; char *newpw = NULL; + char *pwfile = NULL; + const char *text; int i; - int version = -1; struct berval passwd; struct berval *hash = NULL; while( (i = getopt( argc, argv, - "d:h:s:vu" )) != EOF ) + "c:d:h:s:T:vu" )) != EOF ) { switch (i) { + case 'c': /* crypt salt format */ + scheme = "{CRYPT}"; + lutil_salt_format( optarg ); + break; + case 'h': /* scheme */ - scheme = strdup (optarg); + scheme = strdup( optarg ); break; case 's': /* new password (secret) */ - newpw = strdup (optarg); - { char* p; + newpw = strdup( optarg ); for( p = optarg; *p != '\0'; p++ ) { *p = '\0'; } - } + } break; + + case 'T': /* password file */ + pwfile = optarg; break; case 'u': /* RFC2307 userPassword */ @@ -86,30 +109,38 @@ main( int argc, char *argv[] ) usage( argv[0] ); } - if( newpw == NULL ) { - /* prompt for new password */ - char *cknewpw; - newpw = strdup(getpassphrase("New password: ")); - cknewpw = getpassphrase("Re-enter new password: "); - - if( strncmp( newpw, cknewpw, strlen(newpw) )) { - fprintf( stderr, "Password values do not match\n" ); + if( pwfile != NULL ) { + if( lutil_get_filed_password( pwfile, &passwd )) { return EXIT_FAILURE; } - } + } else { + if( newpw == NULL ) { + /* prompt for new password */ + char *cknewpw; + newpw = strdup(getpassphrase("New password: ")); + cknewpw = getpassphrase("Re-enter new password: "); + + if( strcmp( newpw, cknewpw )) { + fprintf( stderr, "Password values do not match\n" ); + return EXIT_FAILURE; + } + } - passwd.bv_val = newpw; - passwd.bv_len = strlen(passwd.bv_val); + passwd.bv_val = newpw; + passwd.bv_len = strlen(passwd.bv_val); + } - hash = lutil_passwd_hash( &passwd, scheme ); + hash = lutil_passwd_hash( &passwd, scheme, &text ); if( hash == NULL || hash->bv_val == NULL ) { - fprintf( stderr, "Password generation failed.\n"); + fprintf( stderr, "Password generation failed. %s\n", + text ? text : "" ); return EXIT_FAILURE; } - if( lutil_passwd( hash, &passwd, NULL ) ) { - fprintf( stderr, "Password verification failed.\n"); + if( lutil_passwd( hash, &passwd, NULL, &text ) ) { + fprintf( stderr, "Password verification failed. %s\n", + text ? text : "" ); return EXIT_FAILURE; }