X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=apps%2Fpasswd.c;h=898831337563488b4e40d2f1f0e867f9ba2a7437;hp=3c6fd5204e22afdf74fba18ce229aba587326343;hb=8f6f1441a368b984b739658778f53db1bf71a543;hpb=7e1b7485706c2b11091b5fa897fe496a2faa56cc diff --git a/apps/passwd.c b/apps/passwd.c index 3c6fd5204e..8988313375 100644 --- a/apps/passwd.c +++ b/apps/passwd.c @@ -53,7 +53,6 @@ #if !defined(OPENSSL_NO_DES) || !defined(NO_MD5CRYPT_1) -# include # include # include "apps.h" @@ -101,6 +100,8 @@ OPTIONS passwd_options[] = { {"quiet", OPT_QUIET, '-', "No warnings"}, {"table", OPT_TABLE, '-', "Format output as table"}, {"reverse", OPT_REVERSE, '-', "Switch table columns"}, + {"salt", OPT_SALT, 's', "Use provided salt"}, + {"stdin", OPT_STDIN, '-', "Read passwords from stdin"}, # ifndef NO_MD5CRYPT_1 {"apr1", OPT_APR1, '-', "MD5-based password algorithm, Apache variant"}, {"1", OPT_1, '-', "MD5-based password algorithm"}, @@ -108,8 +109,6 @@ OPTIONS passwd_options[] = { # ifndef OPENSSL_NO_DES {"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"}, # endif - {"salt", OPT_SALT, 's', "Use provided salt"}, - {"stdin", OPT_STDIN, '-', "Read passwords from stdin"}, {NULL} }; @@ -202,12 +201,15 @@ int passwd_main(int argc, char **argv) goto opthelp; # endif + if (!app_load_modules(NULL)) + goto end; + if (infile && in_stdin) { BIO_printf(bio_err, "%s: Can't combine -in and -stdin\n", prog); goto end; } - in = bio_open_default(infile, "r"); + in = bio_open_default(infile, 'r', FORMAT_TEXT); if (in == NULL) goto end; @@ -221,12 +223,9 @@ int passwd_main(int argc, char **argv) /* no passwords on the command line */ passwd_malloc_size = pw_maxlen + 2; - /* - * longer than necessary so that we can warn about truncation - */ - passwd = passwd_malloc = OPENSSL_malloc(passwd_malloc_size); - if (passwd_malloc == NULL) - goto end; + /* longer than necessary so that we can warn about truncation */ + passwd = passwd_malloc = + app_malloc(passwd_malloc_size, "password buffer"); } if ((in == NULL) && (passwds == NULL)) { @@ -287,10 +286,8 @@ int passwd_main(int argc, char **argv) end: ERR_print_errors(bio_err); - if (salt_malloc) - OPENSSL_free(salt_malloc); - if (passwd_malloc) - OPENSSL_free(passwd_malloc); + OPENSSL_free(salt_malloc); + OPENSSL_free(passwd_malloc); BIO_free(in); return (ret); } @@ -426,9 +423,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p, # ifndef OPENSSL_NO_DES if (usecrypt) { if (*salt_malloc_p == NULL) { - *salt_p = *salt_malloc_p = OPENSSL_malloc(3); - if (*salt_malloc_p == NULL) - goto end; + *salt_p = *salt_malloc_p = app_malloc(3, "salt buffer"); } if (RAND_bytes((unsigned char *)*salt_p, 2) <= 0) goto end; @@ -447,9 +442,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p, int i; if (*salt_malloc_p == NULL) { - *salt_p = *salt_malloc_p = OPENSSL_malloc(9); - if (*salt_malloc_p == NULL) - goto end; + *salt_p = *salt_malloc_p = app_malloc(9, "salt buffer"); } if (RAND_bytes((unsigned char *)*salt_p, 8) <= 0) goto end; @@ -502,7 +495,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p, int passwd_main(int argc, char **argv) { - fputs("Program not available.\n", stderr) - return (1); + BIO_printf(bio_err, "Program not available.\n"); + return (1); } #endif