diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ui/ui_lib.c | 153 |
1 files changed, 89 insertions, 64 deletions
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c index 8811bf86c7..546540ad83 100644 --- a/src/lib/libcrypto/ui/ui_lib.c +++ b/src/lib/libcrypto/ui/ui_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ui_lib.c,v 1.49 2022/12/23 02:27:47 jsing Exp $ */ | 1 | /* $OpenBSD: ui_lib.c,v 1.50 2022/12/23 02:31:56 jsing Exp $ */ |
2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL |
3 | * project 2001. | 3 | * project 2001. |
4 | */ | 4 | */ |
@@ -117,6 +117,7 @@ UI_free(UI *ui) | |||
117 | { | 117 | { |
118 | if (ui == NULL) | 118 | if (ui == NULL) |
119 | return; | 119 | return; |
120 | |||
120 | sk_UI_STRING_pop_free(ui->strings, free_string); | 121 | sk_UI_STRING_pop_free(ui->strings, free_string); |
121 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data); | 122 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data); |
122 | free(ui); | 123 | free(ui); |
@@ -379,6 +380,7 @@ UI_add_user_data(UI *ui, void *user_data) | |||
379 | void *old_data = ui->user_data; | 380 | void *old_data = ui->user_data; |
380 | 381 | ||
381 | ui->user_data = user_data; | 382 | ui->user_data = user_data; |
383 | |||
382 | return old_data; | 384 | return old_data; |
383 | } | 385 | } |
384 | LCRYPTO_ALIAS(UI_add_user_data) | 386 | LCRYPTO_ALIAS(UI_add_user_data) |
@@ -486,6 +488,7 @@ UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)) | |||
486 | UIerror(ERR_R_PASSED_NULL_PARAMETER); | 488 | UIerror(ERR_R_PASSED_NULL_PARAMETER); |
487 | return -1; | 489 | return -1; |
488 | } | 490 | } |
491 | |||
489 | switch (cmd) { | 492 | switch (cmd) { |
490 | case UI_CTRL_PRINT_ERRORS: | 493 | case UI_CTRL_PRINT_ERRORS: |
491 | { | 494 | { |
@@ -530,18 +533,18 @@ UI_get_ex_data(UI *r, int idx) | |||
530 | LCRYPTO_ALIAS(UI_get_ex_data) | 533 | LCRYPTO_ALIAS(UI_get_ex_data) |
531 | 534 | ||
532 | void | 535 | void |
533 | UI_set_default_method(const UI_METHOD *meth) | 536 | UI_set_default_method(const UI_METHOD *method) |
534 | { | 537 | { |
535 | default_UI_meth = meth; | 538 | default_UI_meth = method; |
536 | } | 539 | } |
537 | LCRYPTO_ALIAS(UI_set_default_method) | 540 | LCRYPTO_ALIAS(UI_set_default_method) |
538 | 541 | ||
539 | const UI_METHOD * | 542 | const UI_METHOD * |
540 | UI_get_default_method(void) | 543 | UI_get_default_method(void) |
541 | { | 544 | { |
542 | if (default_UI_meth == NULL) { | 545 | if (default_UI_meth == NULL) |
543 | default_UI_meth = UI_OpenSSL(); | 546 | default_UI_meth = UI_OpenSSL(); |
544 | } | 547 | |
545 | return default_UI_meth; | 548 | return default_UI_meth; |
546 | } | 549 | } |
547 | LCRYPTO_ALIAS(UI_get_default_method) | 550 | LCRYPTO_ALIAS(UI_get_default_method) |
@@ -554,9 +557,10 @@ UI_get_method(UI *ui) | |||
554 | LCRYPTO_ALIAS(UI_get_method) | 557 | LCRYPTO_ALIAS(UI_get_method) |
555 | 558 | ||
556 | const UI_METHOD * | 559 | const UI_METHOD * |
557 | UI_set_method(UI *ui, const UI_METHOD *meth) | 560 | UI_set_method(UI *ui, const UI_METHOD *method) |
558 | { | 561 | { |
559 | ui->meth = meth; | 562 | ui->meth = method; |
563 | |||
560 | return ui->meth; | 564 | return ui->meth; |
561 | } | 565 | } |
562 | LCRYPTO_ALIAS(UI_set_method) | 566 | LCRYPTO_ALIAS(UI_set_method) |
@@ -597,55 +601,60 @@ LCRYPTO_ALIAS(UI_destroy_method) | |||
597 | int | 601 | int |
598 | UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) | 602 | UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) |
599 | { | 603 | { |
600 | if (method) { | 604 | if (method == NULL) |
601 | method->ui_open_session = opener; | 605 | return -1; |
602 | return 0; | 606 | |
603 | } | 607 | method->ui_open_session = opener; |
604 | return -1; | 608 | |
609 | return 0; | ||
605 | } | 610 | } |
606 | LCRYPTO_ALIAS(UI_method_set_opener) | 611 | LCRYPTO_ALIAS(UI_method_set_opener) |
607 | 612 | ||
608 | int | 613 | int |
609 | UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)) | 614 | UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)) |
610 | { | 615 | { |
611 | if (method) { | 616 | if (method == NULL) |
612 | method->ui_write_string = writer; | 617 | return -1; |
613 | return 0; | 618 | |
614 | } | 619 | method->ui_write_string = writer; |
615 | return -1; | 620 | |
621 | return 0; | ||
616 | } | 622 | } |
617 | LCRYPTO_ALIAS(UI_method_set_writer) | 623 | LCRYPTO_ALIAS(UI_method_set_writer) |
618 | 624 | ||
619 | int | 625 | int |
620 | UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)) | 626 | UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)) |
621 | { | 627 | { |
622 | if (method) { | 628 | if (method == NULL) |
623 | method->ui_flush = flusher; | 629 | return -1; |
624 | return 0; | 630 | |
625 | } | 631 | method->ui_flush = flusher; |
626 | return -1; | 632 | |
633 | return 0; | ||
627 | } | 634 | } |
628 | LCRYPTO_ALIAS(UI_method_set_flusher) | 635 | LCRYPTO_ALIAS(UI_method_set_flusher) |
629 | 636 | ||
630 | int | 637 | int |
631 | UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)) | 638 | UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)) |
632 | { | 639 | { |
633 | if (method) { | 640 | if (method == NULL) |
634 | method->ui_read_string = reader; | 641 | return -1; |
635 | return 0; | 642 | |
636 | } | 643 | method->ui_read_string = reader; |
637 | return -1; | 644 | |
645 | return 0; | ||
638 | } | 646 | } |
639 | LCRYPTO_ALIAS(UI_method_set_reader) | 647 | LCRYPTO_ALIAS(UI_method_set_reader) |
640 | 648 | ||
641 | int | 649 | int |
642 | UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)) | 650 | UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)) |
643 | { | 651 | { |
644 | if (method) { | 652 | if (method == NULL) |
645 | method->ui_close_session = closer; | 653 | return -1; |
646 | return 0; | 654 | |
647 | } | 655 | method->ui_close_session = closer; |
648 | return -1; | 656 | |
657 | return 0; | ||
649 | } | 658 | } |
650 | LCRYPTO_ALIAS(UI_method_set_closer) | 659 | LCRYPTO_ALIAS(UI_method_set_closer) |
651 | 660 | ||
@@ -654,56 +663,62 @@ UI_method_set_prompt_constructor(UI_METHOD *method, | |||
654 | char *(*prompt_constructor)(UI *ui, const char *object_desc, | 663 | char *(*prompt_constructor)(UI *ui, const char *object_desc, |
655 | const char *object_name)) | 664 | const char *object_name)) |
656 | { | 665 | { |
657 | if (method) { | 666 | if (method == NULL) |
658 | method->ui_construct_prompt = prompt_constructor; | 667 | return -1; |
659 | return 0; | 668 | |
660 | } | 669 | method->ui_construct_prompt = prompt_constructor; |
661 | return -1; | 670 | |
671 | return 0; | ||
662 | } | 672 | } |
663 | LCRYPTO_ALIAS(UI_method_set_prompt_constructor) | 673 | LCRYPTO_ALIAS(UI_method_set_prompt_constructor) |
664 | 674 | ||
665 | int | 675 | int |
666 | (*UI_method_get_opener(const UI_METHOD * method))(UI *) | 676 | (*UI_method_get_opener(const UI_METHOD * method))(UI *) |
667 | { | 677 | { |
668 | if (method) | 678 | if (method == NULL) |
669 | return method->ui_open_session; | 679 | return NULL; |
670 | return NULL; | 680 | |
681 | return method->ui_open_session; | ||
671 | } | 682 | } |
672 | LCRYPTO_ALIAS(UI_method_get_opener) | 683 | LCRYPTO_ALIAS(UI_method_get_opener) |
673 | 684 | ||
674 | int | 685 | int |
675 | (*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *) | 686 | (*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *) |
676 | { | 687 | { |
677 | if (method) | 688 | if (method == NULL) |
678 | return method->ui_write_string; | 689 | return NULL; |
679 | return NULL; | 690 | |
691 | return method->ui_write_string; | ||
680 | } | 692 | } |
681 | LCRYPTO_ALIAS(UI_method_get_writer) | 693 | LCRYPTO_ALIAS(UI_method_get_writer) |
682 | 694 | ||
683 | int | 695 | int |
684 | (*UI_method_get_flusher(const UI_METHOD *method)) (UI *) | 696 | (*UI_method_get_flusher(const UI_METHOD *method)) (UI *) |
685 | { | 697 | { |
686 | if (method) | 698 | if (method == NULL) |
687 | return method->ui_flush; | 699 | return NULL; |
688 | return NULL; | 700 | |
701 | return method->ui_flush; | ||
689 | } | 702 | } |
690 | LCRYPTO_ALIAS(UI_method_get_flusher) | 703 | LCRYPTO_ALIAS(UI_method_get_flusher) |
691 | 704 | ||
692 | int | 705 | int |
693 | (*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *) | 706 | (*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *) |
694 | { | 707 | { |
695 | if (method) | 708 | if (method == NULL) |
696 | return method->ui_read_string; | 709 | return NULL; |
697 | return NULL; | 710 | |
711 | return method->ui_read_string; | ||
698 | } | 712 | } |
699 | LCRYPTO_ALIAS(UI_method_get_reader) | 713 | LCRYPTO_ALIAS(UI_method_get_reader) |
700 | 714 | ||
701 | int | 715 | int |
702 | (*UI_method_get_closer(const UI_METHOD *method))(UI *) | 716 | (*UI_method_get_closer(const UI_METHOD *method))(UI *) |
703 | { | 717 | { |
704 | if (method) | 718 | if (method == NULL) |
705 | return method->ui_close_session; | 719 | return NULL; |
706 | return NULL; | 720 | |
721 | return method->ui_close_session; | ||
707 | } | 722 | } |
708 | LCRYPTO_ALIAS(UI_method_get_closer) | 723 | LCRYPTO_ALIAS(UI_method_get_closer) |
709 | 724 | ||
@@ -711,17 +726,19 @@ char * | |||
711 | (*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *, const char *, | 726 | (*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *, const char *, |
712 | const char *) | 727 | const char *) |
713 | { | 728 | { |
714 | if (method) | 729 | if (method == NULL) |
715 | return method->ui_construct_prompt; | 730 | return NULL; |
716 | return NULL; | 731 | |
732 | return method->ui_construct_prompt; | ||
717 | } | 733 | } |
718 | LCRYPTO_ALIAS(UI_method_get_prompt_constructor) | 734 | LCRYPTO_ALIAS(UI_method_get_prompt_constructor) |
719 | 735 | ||
720 | enum UI_string_types | 736 | enum UI_string_types |
721 | UI_get_string_type(UI_STRING *uis) | 737 | UI_get_string_type(UI_STRING *uis) |
722 | { | 738 | { |
723 | if (!uis) | 739 | if (uis == NULL) |
724 | return UIT_NONE; | 740 | return UIT_NONE; |
741 | |||
725 | return uis->type; | 742 | return uis->type; |
726 | } | 743 | } |
727 | LCRYPTO_ALIAS(UI_get_string_type) | 744 | LCRYPTO_ALIAS(UI_get_string_type) |
@@ -729,8 +746,9 @@ LCRYPTO_ALIAS(UI_get_string_type) | |||
729 | int | 746 | int |
730 | UI_get_input_flags(UI_STRING *uis) | 747 | UI_get_input_flags(UI_STRING *uis) |
731 | { | 748 | { |
732 | if (!uis) | 749 | if (uis == NULL) |
733 | return 0; | 750 | return 0; |
751 | |||
734 | return uis->input_flags; | 752 | return uis->input_flags; |
735 | } | 753 | } |
736 | LCRYPTO_ALIAS(UI_get_input_flags) | 754 | LCRYPTO_ALIAS(UI_get_input_flags) |
@@ -738,8 +756,9 @@ LCRYPTO_ALIAS(UI_get_input_flags) | |||
738 | const char * | 756 | const char * |
739 | UI_get0_output_string(UI_STRING *uis) | 757 | UI_get0_output_string(UI_STRING *uis) |
740 | { | 758 | { |
741 | if (!uis) | 759 | if (uis == NULL) |
742 | return NULL; | 760 | return NULL; |
761 | |||
743 | return uis->out_string; | 762 | return uis->out_string; |
744 | } | 763 | } |
745 | LCRYPTO_ALIAS(UI_get0_output_string) | 764 | LCRYPTO_ALIAS(UI_get0_output_string) |
@@ -747,8 +766,9 @@ LCRYPTO_ALIAS(UI_get0_output_string) | |||
747 | const char * | 766 | const char * |
748 | UI_get0_action_string(UI_STRING *uis) | 767 | UI_get0_action_string(UI_STRING *uis) |
749 | { | 768 | { |
750 | if (!uis) | 769 | if (uis == NULL) |
751 | return NULL; | 770 | return NULL; |
771 | |||
752 | switch (uis->type) { | 772 | switch (uis->type) { |
753 | case UIT_PROMPT: | 773 | case UIT_PROMPT: |
754 | case UIT_BOOLEAN: | 774 | case UIT_BOOLEAN: |
@@ -762,8 +782,9 @@ LCRYPTO_ALIAS(UI_get0_action_string) | |||
762 | const char * | 782 | const char * |
763 | UI_get0_result_string(UI_STRING *uis) | 783 | UI_get0_result_string(UI_STRING *uis) |
764 | { | 784 | { |
765 | if (!uis) | 785 | if (uis == NULL) |
766 | return NULL; | 786 | return NULL; |
787 | |||
767 | switch (uis->type) { | 788 | switch (uis->type) { |
768 | case UIT_PROMPT: | 789 | case UIT_PROMPT: |
769 | case UIT_VERIFY: | 790 | case UIT_VERIFY: |
@@ -777,8 +798,9 @@ LCRYPTO_ALIAS(UI_get0_result_string) | |||
777 | const char * | 798 | const char * |
778 | UI_get0_test_string(UI_STRING *uis) | 799 | UI_get0_test_string(UI_STRING *uis) |
779 | { | 800 | { |
780 | if (!uis) | 801 | if (uis == NULL) |
781 | return NULL; | 802 | return NULL; |
803 | |||
782 | switch (uis->type) { | 804 | switch (uis->type) { |
783 | case UIT_VERIFY: | 805 | case UIT_VERIFY: |
784 | return uis->_.string_data.test_buf; | 806 | return uis->_.string_data.test_buf; |
@@ -791,8 +813,9 @@ LCRYPTO_ALIAS(UI_get0_test_string) | |||
791 | int | 813 | int |
792 | UI_get_result_minsize(UI_STRING *uis) | 814 | UI_get_result_minsize(UI_STRING *uis) |
793 | { | 815 | { |
794 | if (!uis) | 816 | if (uis == NULL) |
795 | return -1; | 817 | return -1; |
818 | |||
796 | switch (uis->type) { | 819 | switch (uis->type) { |
797 | case UIT_PROMPT: | 820 | case UIT_PROMPT: |
798 | case UIT_VERIFY: | 821 | case UIT_VERIFY: |
@@ -806,8 +829,9 @@ LCRYPTO_ALIAS(UI_get_result_minsize) | |||
806 | int | 829 | int |
807 | UI_get_result_maxsize(UI_STRING *uis) | 830 | UI_get_result_maxsize(UI_STRING *uis) |
808 | { | 831 | { |
809 | if (!uis) | 832 | if (uis == NULL) |
810 | return -1; | 833 | return -1; |
834 | |||
811 | switch (uis->type) { | 835 | switch (uis->type) { |
812 | case UIT_PROMPT: | 836 | case UIT_PROMPT: |
813 | case UIT_VERIFY: | 837 | case UIT_VERIFY: |
@@ -826,8 +850,9 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result) | |||
826 | 850 | ||
827 | ui->flags &= ~UI_FLAG_REDOABLE; | 851 | ui->flags &= ~UI_FLAG_REDOABLE; |
828 | 852 | ||
829 | if (!uis) | 853 | if (uis == NULL) |
830 | return -1; | 854 | return -1; |
855 | |||
831 | switch (uis->type) { | 856 | switch (uis->type) { |
832 | case UIT_PROMPT: | 857 | case UIT_PROMPT: |
833 | case UIT_VERIFY: | 858 | case UIT_VERIFY: |