#include <lutil_sha1.h>
#include "ldap_defaults.h"
+#include "slap.h"
static int verbose = 0;
" -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"
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 */
return EXIT_FAILURE;
} else {
- scheme = strdup( optarg );
+ scheme = ch_strdup( optarg );
}
break;
+ case 'n':
+ newline = "";
+ break;
+
case 's': /* new password (secret) */
if ( pwfile != NULL ) {
fprintf( stderr, "Option -s incompatible with -T\n" );
} else {
char* p;
- newpw = strdup( optarg );
+ newpw = ch_strdup( optarg );
for( p = optarg; *p != '\0'; p++ ) {
*p = '\0';
if( newpw == NULL ) {
/* prompt for new password */
char *cknewpw;
- newpw = strdup(getpassphrase("New password: "));
+ newpw = ch_strdup(getpassphrase("New password: "));
cknewpw = getpassphrase("Re-enter new password: ");
if( strcmp( newpw, cknewpw )) {
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 );
return EXIT_FAILURE;
}
- printf( "%s\n" , hash.bv_val );
+print_pw:;
+ printf( "%s%s" , hash.bv_val, newline );
return EXIT_SUCCESS;
}