diff options
Diffstat (limited to 'src/usr.bin/openssl/openssl.c')
-rw-r--r-- | src/usr.bin/openssl/openssl.c | 157 |
1 files changed, 51 insertions, 106 deletions
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 @@ | |||
1 | /* $OpenBSD: openssl.c,v 1.30 2019/11/04 15:25:54 jsing Exp $ */ | 1 | /* $OpenBSD: openssl.c,v 1.31 2022/11/11 17:07:39 joshua Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -137,8 +137,6 @@ | |||
137 | #define FUNC_TYPE_MD_ALG 5 | 137 | #define FUNC_TYPE_MD_ALG 5 |
138 | #define FUNC_TYPE_CIPHER_ALG 6 | 138 | #define FUNC_TYPE_CIPHER_ALG 6 |
139 | 139 | ||
140 | int single_execution = 0; | ||
141 | |||
142 | typedef struct { | 140 | typedef struct { |
143 | int type; | 141 | int type; |
144 | const char *name; | 142 | const char *name; |
@@ -349,6 +347,7 @@ static void openssl_shutdown(void); | |||
349 | 347 | ||
350 | static LHASH_OF(FUNCTION) *prog_init(void); | 348 | static LHASH_OF(FUNCTION) *prog_init(void); |
351 | static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]); | 349 | static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]); |
350 | static void print_help(void); | ||
352 | static void list_pkey(BIO * out); | 351 | static void list_pkey(BIO * out); |
353 | static void list_cipher(BIO * out); | 352 | static void list_cipher(BIO * out); |
354 | static void list_md(BIO * out); | 353 | static void list_md(BIO * out); |
@@ -385,13 +384,8 @@ int | |||
385 | main(int argc, char **argv) | 384 | main(int argc, char **argv) |
386 | { | 385 | { |
387 | ARGS arg; | 386 | ARGS arg; |
388 | #define PROG_NAME_SIZE 39 | ||
389 | char pname[PROG_NAME_SIZE + 1]; | ||
390 | FUNCTION f, *fp; | ||
391 | const char *prompt; | ||
392 | char buf[1024]; | ||
393 | char *to_free = NULL; | 387 | char *to_free = NULL; |
394 | int n, i, ret = 0; | 388 | int i, ret = 0; |
395 | char *p; | 389 | char *p; |
396 | LHASH_OF(FUNCTION) * prog = NULL; | 390 | LHASH_OF(FUNCTION) * prog = NULL; |
397 | long errline; | 391 | long errline; |
@@ -453,74 +447,21 @@ main(int argc, char **argv) | |||
453 | 447 | ||
454 | prog = prog_init(); | 448 | prog = prog_init(); |
455 | 449 | ||
456 | /* first check the program name */ | ||
457 | program_name(argv[0], pname, sizeof pname); | ||
458 | |||
459 | f.name = pname; | ||
460 | fp = lh_FUNCTION_retrieve(prog, &f); | ||
461 | if (fp != NULL) { | ||
462 | argv[0] = pname; | ||
463 | |||
464 | single_execution = 1; | ||
465 | ret = fp->func(argc, argv); | ||
466 | goto end; | ||
467 | } | ||
468 | /* | 450 | /* |
469 | * ok, now check that there are not arguments, if there are, run with | 451 | * ok, now check that there are not arguments, if there are, run with |
470 | * them, shifting the ssleay off the front | 452 | * them, shifting the executable name off the front |
471 | */ | 453 | */ |
472 | if (argc != 1) { | 454 | argc--; |
473 | argc--; | 455 | argv++; |
474 | argv++; | 456 | |
475 | 457 | if (argc < 1) { | |
476 | single_execution = 1; | 458 | print_help(); |
477 | ret = do_cmd(prog, argc, argv); | ||
478 | if (ret < 0) | ||
479 | ret = 0; | ||
480 | goto end; | 459 | goto end; |
481 | } | 460 | } |
482 | /* ok, lets enter the old 'OpenSSL>' mode */ | ||
483 | 461 | ||
484 | for (;;) { | 462 | ret = do_cmd(prog, argc, argv); |
463 | if (ret < 0) | ||
485 | ret = 0; | 464 | ret = 0; |
486 | p = buf; | ||
487 | n = sizeof buf; | ||
488 | i = 0; | ||
489 | for (;;) { | ||
490 | p[0] = '\0'; | ||
491 | if (i++) | ||
492 | prompt = ">"; | ||
493 | else | ||
494 | prompt = "OpenSSL> "; | ||
495 | fputs(prompt, stdout); | ||
496 | fflush(stdout); | ||
497 | if (!fgets(p, n, stdin)) | ||
498 | goto end; | ||
499 | if (p[0] == '\0') | ||
500 | goto end; | ||
501 | i = strlen(p); | ||
502 | if (i <= 1) | ||
503 | break; | ||
504 | if (p[i - 2] != '\\') | ||
505 | break; | ||
506 | i -= 2; | ||
507 | p += i; | ||
508 | n -= i; | ||
509 | } | ||
510 | if (!chopup_args(&arg, buf, &argc, &argv)) | ||
511 | break; | ||
512 | |||
513 | ret = do_cmd(prog, argc, argv); | ||
514 | if (ret < 0) { | ||
515 | ret = 0; | ||
516 | goto end; | ||
517 | } | ||
518 | if (ret != 0) | ||
519 | BIO_printf(bio_err, "error in %s\n", argv[0]); | ||
520 | (void) BIO_flush(bio_err); | ||
521 | } | ||
522 | BIO_printf(bio_err, "bad exit\n"); | ||
523 | ret = 1; | ||
524 | 465 | ||
525 | end: | 466 | end: |
526 | free(to_free); | 467 | free(to_free); |
@@ -554,7 +495,7 @@ static int | |||
554 | do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[]) | 495 | do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[]) |
555 | { | 496 | { |
556 | FUNCTION f, *fp; | 497 | FUNCTION f, *fp; |
557 | int i, ret = 1, tp, nl; | 498 | int ret = 1; |
558 | 499 | ||
559 | if ((argc <= 0) || (argv[0] == NULL)) { | 500 | if ((argc <= 0) || (argv[0] == NULL)) { |
560 | ret = 0; | 501 | ret = 0; |
@@ -585,12 +526,6 @@ do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[]) | |||
585 | BIO_printf(bio_stdout, "%s\n", argv[0] + 3); | 526 | BIO_printf(bio_stdout, "%s\n", argv[0] + 3); |
586 | BIO_free_all(bio_stdout); | 527 | BIO_free_all(bio_stdout); |
587 | goto end; | 528 | goto end; |
588 | } else if ((strcmp(argv[0], "quit") == 0) || | ||
589 | (strcmp(argv[0], "q") == 0) || | ||
590 | (strcmp(argv[0], "exit") == 0) || | ||
591 | (strcmp(argv[0], "bye") == 0)) { | ||
592 | ret = -1; | ||
593 | goto end; | ||
594 | } else if ((strcmp(argv[0], LIST_STANDARD_COMMANDS) == 0) || | 529 | } else if ((strcmp(argv[0], LIST_STANDARD_COMMANDS) == 0) || |
595 | (strcmp(argv[0], LIST_MESSAGE_DIGEST_COMMANDS) == 0) || | 530 | (strcmp(argv[0], LIST_MESSAGE_DIGEST_COMMANDS) == 0) || |
596 | (strcmp(argv[0], LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) || | 531 | (strcmp(argv[0], LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) || |
@@ -633,44 +568,54 @@ do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[]) | |||
633 | BIO_printf(bio_err, | 568 | BIO_printf(bio_err, |
634 | "openssl:Error: '%s' is an invalid command.\n", | 569 | "openssl:Error: '%s' is an invalid command.\n", |
635 | argv[0]); | 570 | argv[0]); |
636 | BIO_printf(bio_err, "\nStandard commands"); | 571 | print_help(); |
637 | i = 0; | 572 | ret = 0; |
638 | tp = 0; | 573 | } |
639 | for (fp = functions; fp->name != NULL; fp++) { | 574 | end: |
640 | nl = 0; | 575 | return (ret); |
576 | } | ||
577 | |||
578 | static void | ||
579 | print_help(void) | ||
580 | { | ||
581 | FUNCTION *fp; | ||
582 | int i = 0; | ||
583 | int tp = 0; | ||
584 | int nl; | ||
585 | |||
586 | BIO_printf(bio_err, "\nStandard commands"); | ||
587 | for (fp = functions; fp->name != NULL; fp++) { | ||
588 | nl = 0; | ||
641 | #ifdef OPENSSL_NO_CAMELLIA | 589 | #ifdef OPENSSL_NO_CAMELLIA |
642 | if (((i++) % 5) == 0) | 590 | if (((i++) % 5) == 0) |
643 | #else | 591 | #else |
644 | if (((i++) % 4) == 0) | 592 | if (((i++) % 4) == 0) |
645 | #endif | 593 | #endif |
646 | { | 594 | { |
595 | BIO_printf(bio_err, "\n"); | ||
596 | nl = 1; | ||
597 | } | ||
598 | if (fp->type != tp) { | ||
599 | tp = fp->type; | ||
600 | if (!nl) | ||
647 | BIO_printf(bio_err, "\n"); | 601 | BIO_printf(bio_err, "\n"); |
648 | nl = 1; | 602 | if (tp == FUNC_TYPE_MD) { |
649 | } | 603 | i = 1; |
650 | if (fp->type != tp) { | 604 | BIO_printf(bio_err, |
651 | tp = fp->type; | 605 | "\nMessage Digest commands (see the `dgst' command for more details)\n"); |
652 | if (!nl) | 606 | } else if (tp == FUNC_TYPE_CIPHER) { |
653 | BIO_printf(bio_err, "\n"); | 607 | i = 1; |
654 | if (tp == FUNC_TYPE_MD) { | 608 | BIO_printf(bio_err, "\nCipher commands (see the `enc' command for more details)\n"); |
655 | i = 1; | ||
656 | BIO_printf(bio_err, | ||
657 | "\nMessage Digest commands (see the `dgst' command for more details)\n"); | ||
658 | } else if (tp == FUNC_TYPE_CIPHER) { | ||
659 | i = 1; | ||
660 | BIO_printf(bio_err, "\nCipher commands (see the `enc' command for more details)\n"); | ||
661 | } | ||
662 | } | 609 | } |
610 | } | ||
663 | #ifdef OPENSSL_NO_CAMELLIA | 611 | #ifdef OPENSSL_NO_CAMELLIA |
664 | BIO_printf(bio_err, "%-15s", fp->name); | 612 | BIO_printf(bio_err, "%-15s", fp->name); |
665 | #else | 613 | #else |
666 | BIO_printf(bio_err, "%-18s", fp->name); | 614 | BIO_printf(bio_err, "%-18s", fp->name); |
667 | #endif | 615 | #endif |
668 | } | ||
669 | BIO_printf(bio_err, "\n\n"); | ||
670 | ret = 0; | ||
671 | } | 616 | } |
672 | end: | 617 | |
673 | return (ret); | 618 | BIO_printf(bio_err, "\n\n"); |
674 | } | 619 | } |
675 | 620 | ||
676 | static int | 621 | static int |