diff options
author | Brent Cook <bcook@cvs.openbsd.org> | 2015-09-13 12:41:02 +0000 |
---|---|---|
committer | Brent Cook <bcook@cvs.openbsd.org> | 2015-09-13 12:41:02 +0000 |
commit | 17d32d258afd78c03b69787afbfb5171ef578b3c (patch) | |
tree | cfc6e0133fd9792d1b5afc491a301f2fb346da11 /usr.bin | |
parent | 43e4c407686b229ebfa16e584e6b4879f7bcdb62 (diff) |
Factor out setup_up / destroy_ui functions.
This pulls out and renames setup_ui/destroy_ui so we have something that
can be replaced as-needed, moving the the console setup code for Windows
to app_win.c in -portable, instead of needing a local patch to enable binary
console mode
ui_read/write are also simplified.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/openssl/apps.c | 77 | ||||
-rw-r--r-- | usr.bin/openssl/apps.h | 13 | ||||
-rw-r--r-- | usr.bin/openssl/apps_posix.c | 20 | ||||
-rw-r--r-- | usr.bin/openssl/openssl.c | 6 |
4 files changed, 58 insertions, 58 deletions
diff --git a/usr.bin/openssl/apps.c b/usr.bin/openssl/apps.c index f8cad1a703d..c2b786d3f9d 100644 --- a/usr.bin/openssl/apps.c +++ b/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.35 2015/09/11 14:30:23 bcook Exp $ */ +/* $OpenBSD: apps.c,v 1.36 2015/09/13 12:41:01 bcook Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> * @@ -142,7 +142,6 @@ #include <openssl/pem.h> #include <openssl/pkcs12.h> #include <openssl/safestack.h> -#include <openssl/ui.h> #include <openssl/x509.h> #include <openssl/x509v3.h> @@ -154,7 +153,7 @@ typedef struct { unsigned long mask; } NAME_EX_TBL; -static UI_METHOD *ui_method = NULL; +UI_METHOD *ui_method = NULL; static int set_table_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL *in_tbl); @@ -297,85 +296,59 @@ dump_cert_text(BIO *out, X509 *x) return 0; } -static int +int ui_open(UI *ui) { return UI_method_get_opener(UI_OpenSSL()) (ui); } -static int +int ui_read(UI *ui, UI_STRING *uis) { + const char *password; + int string_type; + if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD && UI_get0_user_data(ui)) { - switch (UI_get_string_type(uis)) { - case UIT_PROMPT: - case UIT_VERIFY: - { - const char *password = - ((PW_CB_DATA *)UI_get0_user_data(ui))->password; - if (password && password[0] != '\0') { - UI_set_result(ui, uis, password); - return 1; - } + string_type = UI_get_string_type(uis); + if (string_type == UIT_PROMPT || string_type == UIT_VERIFY) { + password = + ((PW_CB_DATA *)UI_get0_user_data(ui))->password; + if (password && password[0] != '\0') { + UI_set_result(ui, uis, password); + return 1; } - break; - default: - break; } } return UI_method_get_reader(UI_OpenSSL()) (ui, uis); } -static int +int ui_write(UI *ui, UI_STRING *uis) { + const char *password; + int string_type; + if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD && UI_get0_user_data(ui)) { - switch (UI_get_string_type(uis)) { - case UIT_PROMPT: - case UIT_VERIFY: - { - const char *password = - ((PW_CB_DATA *)UI_get0_user_data(ui))->password; - if (password && password[0] != '\0') - return 1; - } - break; - default: - break; + string_type = UI_get_string_type(uis); + if (string_type == UIT_PROMPT || string_type == UIT_VERIFY) { + password = + ((PW_CB_DATA *)UI_get0_user_data(ui))->password; + if (password && password[0] != '\0') + return 1; } } return UI_method_get_writer(UI_OpenSSL()) (ui, uis); } -static int +int ui_close(UI *ui) { return UI_method_get_closer(UI_OpenSSL()) (ui); } int -setup_ui_method(void) -{ - ui_method = UI_create_method("OpenSSL application user interface"); - UI_method_set_opener(ui_method, ui_open); - UI_method_set_reader(ui_method, ui_read); - UI_method_set_writer(ui_method, ui_write); - UI_method_set_closer(ui_method, ui_close); - return 0; -} - -void -destroy_ui_method(void) -{ - if (ui_method) { - UI_destroy_method(ui_method); - ui_method = NULL; - } -} - -int password_callback(char *buf, int bufsiz, int verify, void *arg) { PW_CB_DATA *cb_tmp = arg; diff --git a/usr.bin/openssl/apps.h b/usr.bin/openssl/apps.h index f63079179d8..bb9fd0dd7ae 100644 --- a/usr.bin/openssl/apps.h +++ b/usr.bin/openssl/apps.h @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.h,v 1.15 2015/09/11 14:30:23 bcook Exp $ */ +/* $OpenBSD: apps.h,v 1.16 2015/09/13 12:41:01 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -120,6 +120,7 @@ #include <openssl/ossl_typ.h> #include <openssl/txt_db.h> #include <openssl/x509.h> +#include <openssl/ui.h> #ifndef OPENSSL_NO_OCSP #include <openssl/ocsp.h> @@ -142,8 +143,14 @@ typedef struct pw_cb_data { int password_callback(char *buf, int bufsiz, int verify, void *cb_data); -int setup_ui_method(void); -void destroy_ui_method(void); +int setup_ui(void); +void destroy_ui(void); + +extern UI_METHOD *ui_method; +int ui_open(UI *ui); +int ui_read(UI *ui, UI_STRING *uis); +int ui_write(UI *ui, UI_STRING *uis); +int ui_close(UI *ui); int should_retry(int i); int args_from_file(char *file, int *argc, char **argv[]); diff --git a/usr.bin/openssl/apps_posix.c b/usr.bin/openssl/apps_posix.c index c49a23a653c..67cd465088e 100644 --- a/usr.bin/openssl/apps_posix.c +++ b/usr.bin/openssl/apps_posix.c @@ -142,3 +142,23 @@ app_tminterval(int stop, int usertime) return (ret); } + +int +setup_ui(void) +{ + ui_method = UI_create_method("OpenSSL application user interface"); + UI_method_set_opener(ui_method, ui_open); + UI_method_set_reader(ui_method, ui_read); + UI_method_set_writer(ui_method, ui_write); + UI_method_set_closer(ui_method, ui_close); + return 0; +} + +void +destroy_ui(void) +{ + if (ui_method) { + UI_destroy_method(ui_method); + ui_method = NULL; + } +} diff --git a/usr.bin/openssl/openssl.c b/usr.bin/openssl/openssl.c index 653329f7c6c..d0c0ec05518 100644 --- a/usr.bin/openssl/openssl.c +++ b/usr.bin/openssl/openssl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: openssl.c,v 1.9 2015/09/12 19:34:07 lteo Exp $ */ +/* $OpenBSD: openssl.c,v 1.10 2015/09/13 12:41:01 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -405,14 +405,14 @@ openssl_startup(void) SSL_library_init(); SSL_load_error_strings(); - setup_ui_method(); + setup_ui(); } static void openssl_shutdown(void) { CONF_modules_unload(1); - destroy_ui_method(); + destroy_ui(); OBJ_cleanup(); EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); |