=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/openssl/openssl.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- src/usr.bin/openssl/openssl.c 2019/11/04 15:25:54 1.30 +++ src/usr.bin/openssl/openssl.c 2022/11/11 17:07:39 1.31 @@ -1,4 +1,4 @@ -/* $OpenBSD: openssl.c,v 1.30 2019/11/04 15:25:54 jsing Exp $ */ +/* $OpenBSD: openssl.c,v 1.31 2022/11/11 17:07:39 joshua Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -137,8 +137,6 @@ #define FUNC_TYPE_MD_ALG 5 #define FUNC_TYPE_CIPHER_ALG 6 -int single_execution = 0; - typedef struct { int type; const char *name; @@ -349,6 +347,7 @@ static LHASH_OF(FUNCTION) *prog_init(void); static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]); +static void print_help(void); static void list_pkey(BIO * out); static void list_cipher(BIO * out); static void list_md(BIO * out); @@ -385,13 +384,8 @@ main(int argc, char **argv) { ARGS arg; -#define PROG_NAME_SIZE 39 - char pname[PROG_NAME_SIZE + 1]; - FUNCTION f, *fp; - const char *prompt; - char buf[1024]; char *to_free = NULL; - int n, i, ret = 0; + int i, ret = 0; char *p; LHASH_OF(FUNCTION) * prog = NULL; long errline; @@ -453,75 +447,22 @@ prog = prog_init(); - /* first check the program name */ - program_name(argv[0], pname, sizeof pname); - - f.name = pname; - fp = lh_FUNCTION_retrieve(prog, &f); - if (fp != NULL) { - argv[0] = pname; - - single_execution = 1; - ret = fp->func(argc, argv); - goto end; - } /* * ok, now check that there are not arguments, if there are, run with - * them, shifting the ssleay off the front + * them, shifting the executable name off the front */ - if (argc != 1) { - argc--; - argv++; + argc--; + argv++; - single_execution = 1; - ret = do_cmd(prog, argc, argv); - if (ret < 0) - ret = 0; + if (argc < 1) { + print_help(); goto end; } - /* ok, lets enter the old 'OpenSSL>' mode */ - for (;;) { + ret = do_cmd(prog, argc, argv); + if (ret < 0) ret = 0; - p = buf; - n = sizeof buf; - i = 0; - for (;;) { - p[0] = '\0'; - if (i++) - prompt = ">"; - else - prompt = "OpenSSL> "; - fputs(prompt, stdout); - fflush(stdout); - if (!fgets(p, n, stdin)) - goto end; - if (p[0] == '\0') - goto end; - i = strlen(p); - if (i <= 1) - break; - if (p[i - 2] != '\\') - break; - i -= 2; - p += i; - n -= i; - } - if (!chopup_args(&arg, buf, &argc, &argv)) - break; - ret = do_cmd(prog, argc, argv); - if (ret < 0) { - ret = 0; - goto end; - } - if (ret != 0) - BIO_printf(bio_err, "error in %s\n", argv[0]); - (void) BIO_flush(bio_err); - } - BIO_printf(bio_err, "bad exit\n"); - ret = 1; - end: free(to_free); @@ -554,7 +495,7 @@ do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[]) { FUNCTION f, *fp; - int i, ret = 1, tp, nl; + int ret = 1; if ((argc <= 0) || (argv[0] == NULL)) { ret = 0; @@ -585,12 +526,6 @@ BIO_printf(bio_stdout, "%s\n", argv[0] + 3); BIO_free_all(bio_stdout); goto end; - } else if ((strcmp(argv[0], "quit") == 0) || - (strcmp(argv[0], "q") == 0) || - (strcmp(argv[0], "exit") == 0) || - (strcmp(argv[0], "bye") == 0)) { - ret = -1; - goto end; } else if ((strcmp(argv[0], LIST_STANDARD_COMMANDS) == 0) || (strcmp(argv[0], LIST_MESSAGE_DIGEST_COMMANDS) == 0) || (strcmp(argv[0], LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) || @@ -633,44 +568,54 @@ BIO_printf(bio_err, "openssl:Error: '%s' is an invalid command.\n", argv[0]); - BIO_printf(bio_err, "\nStandard commands"); - i = 0; - tp = 0; - for (fp = functions; fp->name != NULL; fp++) { - nl = 0; + print_help(); + ret = 0; + } + end: + return (ret); +} + +static void +print_help(void) +{ + FUNCTION *fp; + int i = 0; + int tp = 0; + int nl; + + BIO_printf(bio_err, "\nStandard commands"); + for (fp = functions; fp->name != NULL; fp++) { + nl = 0; #ifdef OPENSSL_NO_CAMELLIA - if (((i++) % 5) == 0) + if (((i++) % 5) == 0) #else - if (((i++) % 4) == 0) + if (((i++) % 4) == 0) #endif - { + { + BIO_printf(bio_err, "\n"); + nl = 1; + } + if (fp->type != tp) { + tp = fp->type; + if (!nl) BIO_printf(bio_err, "\n"); - nl = 1; + if (tp == FUNC_TYPE_MD) { + i = 1; + BIO_printf(bio_err, + "\nMessage Digest commands (see the `dgst' command for more details)\n"); + } else if (tp == FUNC_TYPE_CIPHER) { + i = 1; + BIO_printf(bio_err, "\nCipher commands (see the `enc' command for more details)\n"); } - if (fp->type != tp) { - tp = fp->type; - if (!nl) - BIO_printf(bio_err, "\n"); - if (tp == FUNC_TYPE_MD) { - i = 1; - BIO_printf(bio_err, - "\nMessage Digest commands (see the `dgst' command for more details)\n"); - } else if (tp == FUNC_TYPE_CIPHER) { - i = 1; - BIO_printf(bio_err, "\nCipher commands (see the `enc' command for more details)\n"); - } - } + } #ifdef OPENSSL_NO_CAMELLIA - BIO_printf(bio_err, "%-15s", fp->name); + BIO_printf(bio_err, "%-15s", fp->name); #else - BIO_printf(bio_err, "%-18s", fp->name); + BIO_printf(bio_err, "%-18s", fp->name); #endif - } - BIO_printf(bio_err, "\n\n"); - ret = 0; } - end: - return (ret); + + BIO_printf(bio_err, "\n\n"); } static int