From f8749b129444d560b9e645a68ec7b045800243ed Mon Sep 17 00:00:00 2001 From: joshua <> Date: Fri, 11 Nov 2022 17:07:39 +0000 Subject: Remove the legacy interactive mode from openssl(1). This removes the legacy interactive mode from openssl(1) since it is rarely used, complicates the code, and has also been removed from OpenSSL in version 3.x.x. ok tb@ jsing@ --- src/usr.bin/openssl/openssl.c | 157 ++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 106 deletions(-) (limited to 'src/usr.bin/openssl/openssl.c') diff --git a/src/usr.bin/openssl/openssl.c b/src/usr.bin/openssl/openssl.c index 42b9b91b7a..e931b7a33e 100644 --- a/src/usr.bin/openssl/openssl.c +++ b/src/usr.bin/openssl/openssl.c @@ -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 void openssl_shutdown(void); 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 @@ int 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,74 +447,21 @@ main(int argc, char **argv) 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++; - - single_execution = 1; - ret = do_cmd(prog, argc, argv); - if (ret < 0) - ret = 0; + argc--; + argv++; + + 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 @@ static int 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 @@ do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[]) 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 @@ do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[]) 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 (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"); - } + 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 -- cgit v1.2.3-55-g6feb