]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/slappasswd.c
Changes from HEAD for beta
[openldap] / servers / slapd / tools / slappasswd.c
index 639b8a3f2dfe87643315bd283b8a0ab87c6ff304..372377f084da38ebbe7fdb2eedd6f47c9fc26350 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -34,6 +34,7 @@ usage(const char *s)
                "  -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 );
@@ -42,17 +43,17 @@ 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,
-               "c:d:h:s:vu" )) != EOF )
+               "c:d:h:s:T:vu" )) != EOF )
        {
                switch (i) {
                case 'c':       /* crypt salt format */
@@ -72,9 +73,12 @@ main( int argc, char *argv[] )
                                for( p = optarg; *p != '\0'; p++ ) {
                                        *p = '\0';
                                }
-
                        } break;
 
+               case 'T':       /* password file */
+                       pwfile = optarg;
+                       break;
+
                case 'u':       /* RFC2307 userPassword */
                        break;
 
@@ -91,30 +95,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( strcmp( newpw, cknewpw )) {
-                       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;
        }