summaryrefslogtreecommitdiff
path: root/usr.bin/openssl/apps.c
diff options
context:
space:
mode:
authorBrent Cook <bcook@cvs.openbsd.org>2015-09-13 12:41:02 +0000
committerBrent Cook <bcook@cvs.openbsd.org>2015-09-13 12:41:02 +0000
commit17d32d258afd78c03b69787afbfb5171ef578b3c (patch)
treecfc6e0133fd9792d1b5afc491a301f2fb346da11 /usr.bin/openssl/apps.c
parent43e4c407686b229ebfa16e584e6b4879f7bcdb62 (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/openssl/apps.c')
-rw-r--r--usr.bin/openssl/apps.c77
1 files changed, 25 insertions, 52 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;