From 914bf9926f2111f18afd175af6ff62cb7e65f71f Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 11 May 2006 14:36:20 +0000 Subject: [PATCH] add "-n" to omit trailing newline --- doc/man/man8/slappasswd.8 | 5 +++++ servers/slapd/slappasswd.c | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/man/man8/slappasswd.8 b/doc/man/man8/slappasswd.8 index b480d5ccfc..9750da398a 100644 --- a/doc/man/man8/slappasswd.8 +++ b/doc/man/man8/slappasswd.8 @@ -11,6 +11,7 @@ slappasswd \- OpenLDAP password utility .B [\-g|\-s secret|\-T file] .B [\-h hash] .B [\-c salt-format] +.B [\-n] .B .LP .SH DESCRIPTION @@ -131,6 +132,10 @@ provides a two character salt and '$1$%.8s' tells some versions of crypt(3) to use an MD5 algorithm and provides 8 random characters of salt. The default is '%s', which provides 31 characters of salt. +.TP +.BI \-n +Omit the trailing newline; useful to pipe the credentials +into a command. .SH LIMITATIONS The practice storing hashed passwords in userPassword violates Standard Track (RFC 2256) schema specifications and may hinder diff --git a/servers/slapd/slappasswd.c b/servers/slapd/slappasswd.c index 02de9ee93e..ea77df719d 100644 --- a/servers/slapd/slappasswd.c +++ b/servers/slapd/slappasswd.c @@ -48,6 +48,7 @@ usage(const char *s) " -c format\tcrypt(3) salt format\n" " -g\t\tgenerate random password\n" " -h hash\tpassword scheme\n" + " -n\t\tomit trailing newline\n" " -s secret\tnew password\n" " -u\t\tgenerate RFC2307 values (default)\n" " -v\t\tincrease verbosity\n" @@ -73,11 +74,12 @@ slappasswd( int argc, char *argv[] ) const char *progname = "slappasswd"; int i; + char *newline = "\n"; struct berval passwd = BER_BVNULL; struct berval hash; while( (i = getopt( argc, argv, - "c:d:gh:s:T:vu" )) != EOF ) + "c:d:gh:ns:T:vu" )) != EOF ) { switch (i) { case 'c': /* crypt salt format */ @@ -110,6 +112,10 @@ slappasswd( int argc, char *argv[] ) } break; + case 'n': + newline = ""; + break; + case 's': /* new password (secret) */ if ( pwfile != NULL ) { fprintf( stderr, "Option -s incompatible with -T\n" ); @@ -178,9 +184,8 @@ slappasswd( int argc, char *argv[] ) passwd.bv_val = newpw; passwd.bv_len = strlen(passwd.bv_val); } else { - /* Omit trailing newline so it may be directed to a pwfile */ - printf( "%s", passwd.bv_val ); - return EXIT_SUCCESS; + hash = passwd; + goto print_pw; } lutil_passwd_hash( &passwd, scheme, &hash, &text ); @@ -197,6 +202,7 @@ slappasswd( int argc, char *argv[] ) return EXIT_FAILURE; } - printf( "%s\n" , hash.bv_val ); +print_pw:; + printf( "%s%s" , hash.bv_val, newline ); return EXIT_SUCCESS; } -- 2.39.5