mirror of https://github.com/openssl/openssl.git
apps/passwd.c: Fix code layout
Reviewed-by: Andy Polyakov <appro@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/4229)
This commit is contained in:
parent
16583e9179
commit
17621bc2bc
|
@ -7,19 +7,19 @@
|
||||||
* https://www.openssl.org/source/license.html
|
* https://www.openssl.org/source/license.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
# include "apps.h"
|
#include "apps.h"
|
||||||
|
|
||||||
# include <openssl/bio.h>
|
#include <openssl/bio.h>
|
||||||
# include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
# include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
# include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
# ifndef OPENSSL_NO_DES
|
#ifndef OPENSSL_NO_DES
|
||||||
# include <openssl/des.h>
|
# include <openssl/des.h>
|
||||||
# endif
|
#endif
|
||||||
# include <openssl/md5.h>
|
#include <openssl/md5.h>
|
||||||
# include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
static unsigned const char cov_2char[64] = {
|
static unsigned const char cov_2char[64] = {
|
||||||
/* from crypto/des/fcrypt.c */
|
/* from crypto/des/fcrypt.c */
|
||||||
|
@ -70,9 +70,9 @@ const OPTIONS passwd_options[] = {
|
||||||
{"apr1", OPT_APR1, '-', "MD5-based password algorithm, Apache variant"},
|
{"apr1", OPT_APR1, '-', "MD5-based password algorithm, Apache variant"},
|
||||||
{"1", OPT_1, '-', "MD5-based password algorithm"},
|
{"1", OPT_1, '-', "MD5-based password algorithm"},
|
||||||
{"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
|
{"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
|
||||||
# ifndef OPENSSL_NO_DES
|
#ifndef OPENSSL_NO_DES
|
||||||
{"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"},
|
{"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"},
|
||||||
# endif
|
#endif
|
||||||
OPT_R_OPTIONS,
|
OPT_R_OPTIONS,
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
@ -84,9 +84,9 @@ int passwd_main(int argc, char **argv)
|
||||||
char *salt_malloc = NULL, *passwd_malloc = NULL, *prog;
|
char *salt_malloc = NULL, *passwd_malloc = NULL, *prog;
|
||||||
OPTION_CHOICE o;
|
OPTION_CHOICE o;
|
||||||
int in_stdin = 0, pw_source_defined = 0;
|
int in_stdin = 0, pw_source_defined = 0;
|
||||||
# ifndef OPENSSL_NO_UI_CONSOLE
|
#ifndef OPENSSL_NO_UI_CONSOLE
|
||||||
int in_noverify = 0;
|
int in_noverify = 0;
|
||||||
# endif
|
#endif
|
||||||
int passed_salt = 0, quiet = 0, table = 0, reverse = 0;
|
int passed_salt = 0, quiet = 0, table = 0, reverse = 0;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
passwd_modes mode = passwd_unset;
|
passwd_modes mode = passwd_unset;
|
||||||
|
@ -113,9 +113,9 @@ int passwd_main(int argc, char **argv)
|
||||||
pw_source_defined = 1;
|
pw_source_defined = 1;
|
||||||
break;
|
break;
|
||||||
case OPT_NOVERIFY:
|
case OPT_NOVERIFY:
|
||||||
# ifndef OPENSSL_NO_UI_CONSOLE
|
#ifndef OPENSSL_NO_UI_CONSOLE
|
||||||
in_noverify = 1;
|
in_noverify = 1;
|
||||||
# endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case OPT_QUIET:
|
case OPT_QUIET:
|
||||||
quiet = 1;
|
quiet = 1;
|
||||||
|
@ -152,9 +152,11 @@ int passwd_main(int argc, char **argv)
|
||||||
mode = passwd_aixmd5;
|
mode = passwd_aixmd5;
|
||||||
break;
|
break;
|
||||||
case OPT_CRYPT:
|
case OPT_CRYPT:
|
||||||
|
#ifndef OPENSSL_NO_DES
|
||||||
if (mode != passwd_unset)
|
if (mode != passwd_unset)
|
||||||
goto opthelp;
|
goto opthelp;
|
||||||
mode = passwd_crypt;
|
mode = passwd_crypt;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case OPT_SALT:
|
case OPT_SALT:
|
||||||
passed_salt = 1;
|
passed_salt = 1;
|
||||||
|
@ -187,10 +189,10 @@ int passwd_main(int argc, char **argv)
|
||||||
mode = passwd_crypt;
|
mode = passwd_crypt;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef OPENSSL_NO_DES
|
#ifdef OPENSSL_NO_DES
|
||||||
if (mode == passwd_crypt)
|
if (mode == passwd_crypt)
|
||||||
goto opthelp;
|
goto opthelp;
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
if (infile != NULL && in_stdin) {
|
if (infile != NULL && in_stdin) {
|
||||||
BIO_printf(bio_err, "%s: Can't combine -in and -stdin\n", prog);
|
BIO_printf(bio_err, "%s: Can't combine -in and -stdin\n", prog);
|
||||||
|
@ -226,7 +228,7 @@ int passwd_main(int argc, char **argv)
|
||||||
* avoid rot of not-frequently-used code.
|
* avoid rot of not-frequently-used code.
|
||||||
*/
|
*/
|
||||||
if (1) {
|
if (1) {
|
||||||
# ifndef OPENSSL_NO_UI_CONSOLE
|
#ifndef OPENSSL_NO_UI_CONSOLE
|
||||||
/* build a null-terminated list */
|
/* build a null-terminated list */
|
||||||
static char *passwds_static[2] = { NULL, NULL };
|
static char *passwds_static[2] = { NULL, NULL };
|
||||||
|
|
||||||
|
@ -239,7 +241,7 @@ int passwd_main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
passwds[0] = passwd_malloc;
|
passwds[0] = passwd_malloc;
|
||||||
} else {
|
} else {
|
||||||
# endif
|
#endif
|
||||||
BIO_printf(bio_err, "password required\n");
|
BIO_printf(bio_err, "password required\n");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -722,7 +724,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
|
||||||
|
|
||||||
/* first make sure we have a salt */
|
/* first make sure we have a salt */
|
||||||
if (!passed_salt) {
|
if (!passed_salt) {
|
||||||
# ifndef OPENSSL_NO_DES
|
#ifndef OPENSSL_NO_DES
|
||||||
if (mode == passwd_crypt) {
|
if (mode == passwd_crypt) {
|
||||||
if (*salt_malloc_p == NULL)
|
if (*salt_malloc_p == NULL)
|
||||||
*salt_p = *salt_malloc_p = app_malloc(3, "salt buffer");
|
*salt_p = *salt_malloc_p = app_malloc(3, "salt buffer");
|
||||||
|
@ -736,7 +738,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
|
||||||
* to ASCII */
|
* to ASCII */
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
# endif /* !OPENSSL_NO_DES */
|
#endif /* !OPENSSL_NO_DES */
|
||||||
|
|
||||||
if (mode == passwd_md5 || mode == passwd_apr1 || mode == passwd_aixmd5) {
|
if (mode == passwd_md5 || mode == passwd_apr1 || mode == passwd_aixmd5) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -781,10 +783,10 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
|
||||||
assert(strlen(passwd) <= pw_maxlen);
|
assert(strlen(passwd) <= pw_maxlen);
|
||||||
|
|
||||||
/* now compute password hash */
|
/* now compute password hash */
|
||||||
# ifndef OPENSSL_NO_DES
|
#ifndef OPENSSL_NO_DES
|
||||||
if (mode == passwd_crypt)
|
if (mode == passwd_crypt)
|
||||||
hash = DES_crypt(passwd, *salt_p);
|
hash = DES_crypt(passwd, *salt_p);
|
||||||
# endif
|
#endif
|
||||||
if (mode == passwd_md5 || mode == passwd_apr1)
|
if (mode == passwd_md5 || mode == passwd_apr1)
|
||||||
hash = md5crypt(passwd, (mode == passwd_md5 ? "1" : "apr1"), *salt_p);
|
hash = md5crypt(passwd, (mode == passwd_md5 ? "1" : "apr1"), *salt_p);
|
||||||
if (mode == passwd_aixmd5)
|
if (mode == passwd_aixmd5)
|
||||||
|
|
Loading…
Reference in New Issue