* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
On success, the all return an index of the added information. That index
is usefull when retrieving results with UI_get0_result(). */
int UI_add_input_string(UI *ui, const char *prompt, int flags,
- char *result_buf, int minsize, int maxsize);
+ char *result_buf, int minsize, int maxsize);
int UI_dup_input_string(UI *ui, const char *prompt, int flags,
- char *result_buf, int minsize, int maxsize);
+ char *result_buf, int minsize, int maxsize);
int UI_add_verify_string(UI *ui, const char *prompt, int flags,
- char *result_buf, int minsize, int maxsize, const char *test_buf);
+ char *result_buf, int minsize, int maxsize, const char *test_buf);
int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
- char *result_buf, int minsize, int maxsize, const char *test_buf);
+ char *result_buf, int minsize, int maxsize, const char *test_buf);
int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
- const char *ok_chars, const char *cancel_chars,
- int flags, char *result_buf);
+ const char *ok_chars, const char *cancel_chars,
+ int flags, char *result_buf);
int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
- const char *ok_chars, const char *cancel_chars,
- int flags, char *result_buf);
+ const char *ok_chars, const char *cancel_chars,
+ int flags, char *result_buf);
int UI_add_info_string(UI *ui, const char *text);
int UI_dup_info_string(UI *ui, const char *text);
int UI_add_error_string(UI *ui, const char *text);
"Enter pass phrase for foo.key:"
*/
-char *UI_construct_prompt(UI *ui_method,
- const char *object_desc, const char *object_name);
+char *UI_construct_prompt(UI *ui_method, const char *object_desc,
+ const char *object_name);
/* The following function is used to store a pointer to user-specific data.
#define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg)
#define UI_get_app_data(s) UI_get_ex_data(s,0)
int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
-int UI_set_ex_data(UI *r,int idx,void *arg);
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
+int UI_set_ex_data(UI *r, int idx, void *arg);
void *UI_get_ex_data(UI *r, int idx);
/* Use specific methods instead of the built-in one */
/* The different types of strings that are currently supported.
This is only needed by method authors. */
-enum UI_string_types
- {
- UIT_NONE=0,
+enum UI_string_types {
+ UIT_NONE = 0,
UIT_PROMPT, /* Prompt for a string */
UIT_VERIFY, /* Prompt for a string and verify */
UIT_BOOLEAN, /* Prompt for a yes/no response */
UIT_INFO, /* Send info to the user */
UIT_ERROR /* Send an error message to the user */
- };
+};
/* Create and manipulate methods */
UI_METHOD *UI_create_method(char *name);
int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name));
int (*UI_method_get_opener(UI_METHOD *method))(UI*);
-int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
+int (*UI_method_get_writer(UI_METHOD *method))(UI*, UI_STRING*);
int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
-int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
+int (*UI_method_get_reader(UI_METHOD *method))(UI*, UI_STRING*);
int (*UI_method_get_closer(UI_METHOD *method))(UI*);
char * (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, const char*);
/* A couple of popular utility functions */
-int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify);
-int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
+int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify);
+int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify);
/* BEGIN ERROR CODES */
#include <string.h>
#include <openssl/ui_compat.h>
-int
+int
_ossl_old_des_read_pw_string(char *buf, int length, const char *prompt, int verify)
{
return UI_UTIL_read_pw_string(buf, length, prompt, verify);
}
-int
+int
_ossl_old_des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
{
return UI_UTIL_read_pw(buf, buff, size, prompt, verify);
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
#define des_read_pw(b,bf,s,p,v) \
_ossl_old_des_read_pw((b),(bf),(s),(p),(v))
-int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify);
-int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
+int _ossl_old_des_read_pw_string(char *buf, int length, const char *prompt, int verify);
+int _ossl_old_des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify);
#ifdef __cplusplus
}
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_UI,func,0)
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason)
-static ERR_STRING_DATA UI_str_functs[] =
-{
+static ERR_STRING_DATA UI_str_functs[] = {
{ERR_FUNC(UI_F_GENERAL_ALLOCATE_BOOLEAN), "GENERAL_ALLOCATE_BOOLEAN"},
{ERR_FUNC(UI_F_GENERAL_ALLOCATE_PROMPT), "GENERAL_ALLOCATE_PROMPT"},
{ERR_FUNC(UI_F_GENERAL_ALLOCATE_STRING), "GENERAL_ALLOCATE_STRING"},
{0, NULL}
};
-static ERR_STRING_DATA UI_str_reasons[] =
-{
+static ERR_STRING_DATA UI_str_reasons[] = {
{ERR_REASON(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS), "common ok and cancel characters"},
{ERR_REASON(UI_R_INDEX_TOO_LARGE), "index too large"},
{ERR_REASON(UI_R_INDEX_TOO_SMALL), "index too small"},
#endif
-void
+void
ERR_load_UI_strings(void)
{
#ifndef OPENSSL_NO_ERR
-
if (ERR_func_error_string(UI_str_functs[0].error) == NULL) {
ERR_load_strings(0, UI_str_functs);
ERR_load_strings(0, UI_str_reasons);
#include <openssl/err.h>
#include "ui_locl.h"
-IMPLEMENT_STACK_OF(UI_STRING_ST)
- static const UI_METHOD *default_UI_meth = NULL;
+IMPLEMENT_STACK_OF(UI_STRING_ST) static const UI_METHOD *default_UI_meth = NULL;
- UI *UI_new(void)
+UI *
+UI_new(void)
{
return (UI_new_method(NULL));
}
UI *
-UI_new_method(const UI_METHOD * method)
+UI_new_method(const UI_METHOD *method)
{
UI *ret;
return ret;
}
-static void
-free_string(UI_STRING * uis)
+static void
+free_string(UI_STRING *uis)
{
if (uis->flags & OUT_STRING_FREEABLE) {
free((char *) uis->out_string);
switch (uis->type) {
case UIT_BOOLEAN:
- free((char *) uis->_.boolean_data.action_desc);
- free((char *) uis->_.boolean_data.ok_chars);
- free((char *) uis->_.boolean_data.cancel_chars);
+ free((char *)uis->_.boolean_data.action_desc);
+ free((char *)uis->_.boolean_data.ok_chars);
+ free((char *)uis->_.boolean_data.cancel_chars);
break;
default:
break;
free(uis);
}
-void
-UI_free(UI * ui)
+void
+UI_free(UI *ui)
{
if (ui == NULL)
return;
free(ui);
}
-static int
-allocate_string_stack(UI * ui)
+static int
+allocate_string_stack(UI *ui)
{
if (ui->strings == NULL) {
ui->strings = sk_UI_STRING_new_null();
}
static UI_STRING *
-general_allocate_prompt(UI * ui, const char *prompt,
+general_allocate_prompt(UI *ui, const char *prompt,
int prompt_freeable, enum UI_string_types type, int input_flags,
char *result_buf)
{
if (prompt == NULL) {
UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, ERR_R_PASSED_NULL_PARAMETER);
- } else if ((type == UIT_PROMPT || type == UIT_VERIFY
- || type == UIT_BOOLEAN) && result_buf == NULL) {
+ } else if ((type == UIT_PROMPT || type == UIT_VERIFY ||
+ type == UIT_BOOLEAN) && result_buf == NULL) {
UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, UI_R_NO_RESULT_BUFFER);
} else if ((ret = (UI_STRING *) malloc(sizeof(UI_STRING)))) {
ret->out_string = prompt;
return ret;
}
-static int
-general_allocate_string(UI * ui, const char *prompt,
+static int
+general_allocate_string(UI *ui, const char *prompt,
int prompt_freeable, enum UI_string_types type, int input_flags,
char *result_buf, int minsize, int maxsize, const char *test_buf)
{
return ret;
}
-static int
-general_allocate_boolean(UI * ui,
+static int
+general_allocate_boolean(UI *ui,
const char *prompt, const char *action_desc,
const char *ok_chars, const char *cancel_chars,
int prompt_freeable, enum UI_string_types type, int input_flags,
/* Returns the index to the place in the stack or -1 for error. Uses a
direct reference to the prompt. */
-int
-UI_add_input_string(UI * ui, const char *prompt, int flags,
+int
+UI_add_input_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize)
{
return general_allocate_string(ui, prompt, 0,
}
/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
-int
-UI_dup_input_string(UI * ui, const char *prompt, int flags,
+int
+UI_dup_input_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize)
{
char *prompt_copy = NULL;
UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
}
-int
-UI_add_verify_string(UI * ui, const char *prompt, int flags,
+int
+UI_add_verify_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize, const char *test_buf)
{
return general_allocate_string(ui, prompt, 0,
UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
}
-int
-UI_dup_verify_string(UI * ui, const char *prompt, int flags,
+int
+UI_dup_verify_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize, const char *test_buf)
{
char *prompt_copy = NULL;
UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
}
-int
-UI_add_input_boolean(UI * ui, const char *prompt, const char *action_desc,
+int
+UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
const char *ok_chars, const char *cancel_chars,
int flags, char *result_buf)
{
ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
}
-int
-UI_dup_input_boolean(UI * ui, const char *prompt, const char *action_desc,
+int
+UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
const char *ok_chars, const char *cancel_chars,
int flags, char *result_buf)
{
return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
result_buf);
+
err:
if (prompt_copy)
free(prompt_copy);
return -1;
}
-int
-UI_add_info_string(UI * ui, const char *text)
+int
+UI_add_info_string(UI *ui, const char *text)
{
return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
NULL);
}
-int
-UI_dup_info_string(UI * ui, const char *text)
+int
+UI_dup_info_string(UI *ui, const char *text)
{
char *text_copy = NULL;
0, 0, NULL);
}
-int
-UI_add_error_string(UI * ui, const char *text)
+int
+UI_add_error_string(UI *ui, const char *text)
{
return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
NULL);
}
-int
-UI_dup_error_string(UI * ui, const char *text)
+int
+UI_dup_error_string(UI *ui, const char *text)
{
char *text_copy = NULL;
}
char *
-UI_construct_prompt(UI * ui, const char *object_desc,
- const char *object_name)
+UI_construct_prompt(UI *ui, const char *object_desc, const char *object_name)
{
char *prompt = NULL;
len += sizeof(prompt2) - 1 + strlen(object_name);
len += sizeof(prompt3) - 1;
- prompt = (char *) malloc(len + 1);
+ prompt = (char *)malloc(len + 1);
BUF_strlcpy(prompt, prompt1, len + 1);
BUF_strlcat(prompt, object_desc, len + 1);
if (object_name) {
}
void *
-UI_add_user_data(UI * ui, void *user_data)
+UI_add_user_data(UI *ui, void *user_data)
{
void *old_data = ui->user_data;
ui->user_data = user_data;
}
void *
-UI_get0_user_data(UI * ui)
+UI_get0_user_data(UI *ui)
{
return ui->user_data;
}
const char *
-UI_get0_result(UI * ui, int i)
+UI_get0_result(UI *ui, int i)
{
if (i < 0) {
UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_SMALL);
return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
}
-static int
-print_error(const char *str, size_t len, UI * ui)
+static int
+print_error(const char *str, size_t len, UI *ui)
{
UI_STRING uis;
uis.type = UIT_ERROR;
uis.out_string = str;
- if (ui->meth->ui_write_string
- && !ui->meth->ui_write_string(ui, &uis))
+ if (ui->meth->ui_write_string &&
+ !ui->meth->ui_write_string(ui, &uis))
return -1;
return 0;
}
-int
-UI_process(UI * ui)
+int
+UI_process(UI *ui)
{
int i, ok = 0;
if (ui->flags & UI_FLAG_PRINT_ERRORS)
ERR_print_errors_cb(
- (int (*) (const char *, size_t, void *)) print_error,
- (void *) ui);
+ (int (*)(const char *, size_t, void *)) print_error,
+ (void *)ui);
for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
- if (ui->meth->ui_write_string
- && !ui->meth->ui_write_string(ui,
+ if (ui->meth->ui_write_string &&
+ !ui->meth->ui_write_string(ui,
sk_UI_STRING_value(ui->strings, i))) {
ok = -1;
goto err;
case -1: /* Interrupt/Cancel/something... */
ok = -2;
goto err;
- case 0: /* Errors */
+ case 0: /* Errors */
ok = -1;
goto err;
default: /* Success */
for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
if (ui->meth->ui_read_string) {
switch (ui->meth->ui_read_string(ui,
- sk_UI_STRING_value(ui->strings, i))) {
+ sk_UI_STRING_value(ui->strings, i))) {
case -1: /* Interrupt/Cancel/something... */
ok = -2;
goto err;
- case 0:/* Errors */
+ case 0: /* Errors */
ok = -1;
goto err;
default: /* Success */
return ok;
}
-int
-UI_ctrl(UI * ui, int cmd, long i, void *p, void (*f) (void))
+int
+UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void))
{
if (ui == NULL) {
UIerr(UI_F_UI_CTRL, ERR_R_PASSED_NULL_PARAMETER);
return -1;
}
-int
-UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new * new_func,
- CRYPTO_EX_dup * dup_func, CRYPTO_EX_free * free_func)
+int
+UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
{
return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
new_func, dup_func, free_func);
}
-int
-UI_set_ex_data(UI * r, int idx, void *arg)
+int
+UI_set_ex_data(UI *r, int idx, void *arg)
{
return (CRYPTO_set_ex_data(&r->ex_data, idx, arg));
}
void *
-UI_get_ex_data(UI * r, int idx)
+UI_get_ex_data(UI *r, int idx)
{
return (CRYPTO_get_ex_data(&r->ex_data, idx));
}
-void
-UI_set_default_method(const UI_METHOD * meth)
+void
+UI_set_default_method(const UI_METHOD *meth)
{
default_UI_meth = meth;
}
}
const UI_METHOD *
-UI_get_method(UI * ui)
+UI_get_method(UI *ui)
{
return ui->meth;
}
const UI_METHOD *
-UI_set_method(UI * ui, const UI_METHOD * meth)
+UI_set_method(UI *ui, const UI_METHOD *meth)
{
ui->meth = meth;
return ui->meth;
/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
(that is, it hasn't been allocated using UI_create_method(), you deserve
anything Murphy can throw at you and more! You have been warned. */
-void
-UI_destroy_method(UI_METHOD * ui_method)
+void
+UI_destroy_method(UI_METHOD *ui_method)
{
free(ui_method->name);
ui_method->name = NULL;
free(ui_method);
}
-int
-UI_method_set_opener(UI_METHOD * method, int (*opener) (UI * ui))
+int
+UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
{
if (method) {
method->ui_open_session = opener;
return -1;
}
-int
-UI_method_set_writer(UI_METHOD * method, int (*writer) (UI * ui, UI_STRING * uis))
+int
+UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
{
if (method) {
method->ui_write_string = writer;
return -1;
}
-int
-UI_method_set_flusher(UI_METHOD * method, int (*flusher) (UI * ui))
+int
+UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui))
{
if (method) {
method->ui_flush = flusher;
return -1;
}
-int
-UI_method_set_reader(UI_METHOD * method, int (*reader) (UI * ui, UI_STRING * uis))
+int
+UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
{
if (method) {
method->ui_read_string = reader;
return -1;
}
-int
-UI_method_set_closer(UI_METHOD * method, int (*closer) (UI * ui))
+int
+UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
{
if (method) {
method->ui_close_session = closer;
return -1;
}
-int
-UI_method_set_prompt_constructor(UI_METHOD * method, char *(*prompt_constructor) (UI * ui, const char *object_desc, const char *object_name))
+int
+UI_method_set_prompt_constructor(UI_METHOD *method,
+ char *(*prompt_constructor)(UI *ui, const char *object_desc,
+ const char *object_name))
{
if (method) {
method->ui_construct_prompt = prompt_constructor;
return -1;
}
-int (*
- UI_method_get_opener(UI_METHOD * method)) (UI *)
+int
+(*UI_method_get_opener(UI_METHOD * method))(UI *)
{
if (method)
return method->ui_open_session;
return NULL;
}
-int (*
- UI_method_get_writer(UI_METHOD * method)) (UI *, UI_STRING *)
+int
+(*UI_method_get_writer(UI_METHOD *method))(UI *, UI_STRING *)
{
if (method)
return method->ui_write_string;
return NULL;
}
-int (*
- UI_method_get_flusher(UI_METHOD * method)) (UI *)
+int
+(*UI_method_get_flusher(UI_METHOD *method)) (UI *)
{
if (method)
return method->ui_flush;
return NULL;
}
-int (*
- UI_method_get_reader(UI_METHOD * method)) (UI *, UI_STRING *)
+int
+(*UI_method_get_reader(UI_METHOD *method))(UI *, UI_STRING *)
{
if (method)
return method->ui_read_string;
return NULL;
}
-int (*
- UI_method_get_closer(UI_METHOD * method)) (UI *)
+int
+(*UI_method_get_closer(UI_METHOD *method))(UI *)
{
if (method)
return method->ui_close_session;
return NULL;
}
-char *(*
- UI_method_get_prompt_constructor(UI_METHOD * method)) (UI *, const char *, const char *)
+char *
+(*UI_method_get_prompt_constructor(UI_METHOD *method))(UI *, const char *,
+ const char *)
{
if (method)
return method->ui_construct_prompt;
return NULL;
}
-enum UI_string_types
-UI_get_string_type(UI_STRING * uis)
+enum UI_string_types
+UI_get_string_type(UI_STRING *uis)
{
if (!uis)
return UIT_NONE;
return uis->type;
}
-int
-UI_get_input_flags(UI_STRING * uis)
+int
+UI_get_input_flags(UI_STRING *uis)
{
if (!uis)
return 0;
}
const char *
-UI_get0_output_string(UI_STRING * uis)
+UI_get0_output_string(UI_STRING *uis)
{
if (!uis)
return NULL;
}
const char *
-UI_get0_action_string(UI_STRING * uis)
+UI_get0_action_string(UI_STRING *uis)
{
if (!uis)
return NULL;
}
const char *
-UI_get0_result_string(UI_STRING * uis)
+UI_get0_result_string(UI_STRING *uis)
{
if (!uis)
return NULL;
}
const char *
-UI_get0_test_string(UI_STRING * uis)
+UI_get0_test_string(UI_STRING *uis)
{
if (!uis)
return NULL;
}
}
-int
-UI_get_result_minsize(UI_STRING * uis)
+int
+UI_get_result_minsize(UI_STRING *uis)
{
if (!uis)
return -1;
}
}
-int
-UI_get_result_maxsize(UI_STRING * uis)
+int
+UI_get_result_maxsize(UI_STRING *uis)
{
if (!uis)
return -1;
}
}
-int
-UI_set_result(UI * ui, UI_STRING * uis, const char *result)
+int
+UI_set_result(UI *ui, UI_STRING *uis, const char *result)
{
int l = strlen(result);
break;
}
}
- default:
+ default:
break;
}
}
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
#undef _
#endif
-struct ui_method_st
- {
+struct ui_method_st {
char *name;
/* All the functions return 1 or non-NULL for success and 0 or NULL
The returned string shall always be allocated on the heap with
malloc(), and need to be free'd with free(). */
char *(*ui_construct_prompt)(UI *ui, const char *object_desc,
- const char *object_name);
- };
+ const char *object_name);
+};
-struct ui_string_st
- {
+struct ui_string_st {
enum UI_string_types type; /* Input */
const char *out_string; /* Input */
int input_flags; /* Flags from the user */
with size in result_maxsize. Otherwise, it
may be allocated by the UI routine, meaning
result_minsize is going to be overwritten.*/
- union
- {
- struct
- {
+ union {
+ struct {
int result_minsize; /* Input: minimum required
size of the result.
*/
const char *test_buf; /* Input: test string to verify
against */
- } string_data;
- struct
- {
+ } string_data;
+ struct {
const char *action_desc; /* Input */
const char *ok_chars; /* Input */
const char *cancel_chars; /* Input */
- } boolean_data;
- } _;
+ } boolean_data;
+ } _;
#define OUT_STRING_FREEABLE 0x01
int flags; /* flags for internal use */
- };
+};
-struct ui_st
- {
+struct ui_st {
const UI_METHOD *meth;
STACK_OF(UI_STRING) *strings; /* We might want to prompt for more
than one thing at a time, and
#define UI_FLAG_REDOABLE 0x0001
#define UI_FLAG_PRINT_ERRORS 0x0100
int flags;
- };
+};
#endif
* [including the GNU Public Licence.]
*/
-
#include <openssl/e_os2.h>
#include <signal.h>
static void recsig(int);
static void pushsig(void);
static void popsig(void);
-static int read_string_inner(UI * ui, UI_STRING * uis, int echo, int strip_nl);
+static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
-static int read_string(UI * ui, UI_STRING * uis);
-static int write_string(UI * ui, UI_STRING * uis);
+static int read_string(UI *ui, UI_STRING *uis);
+static int write_string(UI *ui, UI_STRING *uis);
-static int open_console(UI * ui);
-static int echo_console(UI * ui);
-static int noecho_console(UI * ui);
-static int close_console(UI * ui);
+static int open_console(UI *ui);
+static int echo_console(UI *ui);
+static int noecho_console(UI *ui);
+static int close_console(UI *ui);
-static UI_METHOD ui_openssl =
-{
+static UI_METHOD ui_openssl = {
"OpenSSL default user interface",
open_console,
write_string,
/* The following function makes sure that info and error strings are printed
before any prompt. */
-static int
-write_string(UI * ui, UI_STRING * uis)
+static int
+write_string(UI *ui, UI_STRING *uis)
{
switch (UI_get_string_type(uis)) {
- case UIT_ERROR:
- case UIT_INFO:
+ case UIT_ERROR:
+ case UIT_INFO:
fputs(UI_get0_output_string(uis), tty_out);
fflush(tty_out);
break;
return 1;
}
-static int
-read_string(UI * ui, UI_STRING * uis)
+static int
+read_string(UI *ui, UI_STRING *uis)
{
int ok = 0;
UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
return ok;
if (strcmp(UI_get0_result_string(uis),
- UI_get0_test_string(uis)) != 0) {
+ UI_get0_test_string(uis)) != 0) {
fprintf(tty_out, "Verify failure\n");
fflush(tty_out);
return 0;
/* Internal functions to read a string without echoing */
-static int
-read_till_nl(FILE * in)
+static int
+read_till_nl(FILE *in)
{
#define SIZE 4
char buf[SIZE + 1];
static volatile sig_atomic_t intr_signal;
-static int
-read_string_inner(UI * ui, UI_STRING * uis, int echo, int strip_nl)
+static int
+read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
{
static int ps;
int ok;
/* Internal functions to open, handle and close a channel to the console. */
-static int
-open_console(UI * ui)
+static int
+open_console(UI *ui)
{
CRYPTO_w_lock(CRYPTO_LOCK_UI);
is_a_tty = 1;
* solaris can return EINVAL instead. This should be
* ok
*/
- if (errno == EINVAL)
- is_a_tty = 0;
+ if (errno == EINVAL)
+ is_a_tty = 0;
else
return 0;
}
return 1;
}
-static int
-noecho_console(UI * ui)
+static int
+noecho_console(UI *ui)
{
#ifdef TTY_FLAGS
memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
return 1;
}
-static int
-echo_console(UI * ui)
+static int
+echo_console(UI *ui)
{
#if defined(TTY_set)
memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
return 1;
}
-static int
-close_console(UI * ui)
+static int
+close_console(UI *ui)
{
if (tty_in != stdin)
fclose(tty_in);
/* Internal functions to handle signals and act on them */
-static void
+static void
pushsig(void)
{
int i;
#endif
}
-static void
+static void
popsig(void)
{
int i;
}
}
-static void
+static void
recsig(int i)
{
intr_signal = i;
#include <string.h>
#include "ui_locl.h"
-int
+int
UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
{
char buff[BUFSIZ];
int ret;
- ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length, prompt, verify);
+ ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,
+ prompt, verify);
OPENSSL_cleanse(buff, BUFSIZ);
return (ret);
}
-int
+int
UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
{
int ok = 0;
if (ui) {
ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1);
if (ok >= 0 && verify)
- ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1,
- buf);
+ ok = UI_add_verify_string(ui, prompt, 0, buff, 0,
+ size - 1, buf);
if (ok >= 0)
ok = UI_process(ui);
UI_free(ui);
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
On success, the all return an index of the added information. That index
is usefull when retrieving results with UI_get0_result(). */
int UI_add_input_string(UI *ui, const char *prompt, int flags,
- char *result_buf, int minsize, int maxsize);
+ char *result_buf, int minsize, int maxsize);
int UI_dup_input_string(UI *ui, const char *prompt, int flags,
- char *result_buf, int minsize, int maxsize);
+ char *result_buf, int minsize, int maxsize);
int UI_add_verify_string(UI *ui, const char *prompt, int flags,
- char *result_buf, int minsize, int maxsize, const char *test_buf);
+ char *result_buf, int minsize, int maxsize, const char *test_buf);
int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
- char *result_buf, int minsize, int maxsize, const char *test_buf);
+ char *result_buf, int minsize, int maxsize, const char *test_buf);
int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
- const char *ok_chars, const char *cancel_chars,
- int flags, char *result_buf);
+ const char *ok_chars, const char *cancel_chars,
+ int flags, char *result_buf);
int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
- const char *ok_chars, const char *cancel_chars,
- int flags, char *result_buf);
+ const char *ok_chars, const char *cancel_chars,
+ int flags, char *result_buf);
int UI_add_info_string(UI *ui, const char *text);
int UI_dup_info_string(UI *ui, const char *text);
int UI_add_error_string(UI *ui, const char *text);
"Enter pass phrase for foo.key:"
*/
-char *UI_construct_prompt(UI *ui_method,
- const char *object_desc, const char *object_name);
+char *UI_construct_prompt(UI *ui_method, const char *object_desc,
+ const char *object_name);
/* The following function is used to store a pointer to user-specific data.
#define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg)
#define UI_get_app_data(s) UI_get_ex_data(s,0)
int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
-int UI_set_ex_data(UI *r,int idx,void *arg);
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
+int UI_set_ex_data(UI *r, int idx, void *arg);
void *UI_get_ex_data(UI *r, int idx);
/* Use specific methods instead of the built-in one */
/* The different types of strings that are currently supported.
This is only needed by method authors. */
-enum UI_string_types
- {
- UIT_NONE=0,
+enum UI_string_types {
+ UIT_NONE = 0,
UIT_PROMPT, /* Prompt for a string */
UIT_VERIFY, /* Prompt for a string and verify */
UIT_BOOLEAN, /* Prompt for a yes/no response */
UIT_INFO, /* Send info to the user */
UIT_ERROR /* Send an error message to the user */
- };
+};
/* Create and manipulate methods */
UI_METHOD *UI_create_method(char *name);
int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name));
int (*UI_method_get_opener(UI_METHOD *method))(UI*);
-int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
+int (*UI_method_get_writer(UI_METHOD *method))(UI*, UI_STRING*);
int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
-int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
+int (*UI_method_get_reader(UI_METHOD *method))(UI*, UI_STRING*);
int (*UI_method_get_closer(UI_METHOD *method))(UI*);
char * (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, const char*);
/* A couple of popular utility functions */
-int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify);
-int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
+int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify);
+int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify);
/* BEGIN ERROR CODES */
#include <string.h>
#include <openssl/ui_compat.h>
-int
+int
_ossl_old_des_read_pw_string(char *buf, int length, const char *prompt, int verify)
{
return UI_UTIL_read_pw_string(buf, length, prompt, verify);
}
-int
+int
_ossl_old_des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
{
return UI_UTIL_read_pw(buf, buff, size, prompt, verify);
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
#define des_read_pw(b,bf,s,p,v) \
_ossl_old_des_read_pw((b),(bf),(s),(p),(v))
-int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify);
-int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
+int _ossl_old_des_read_pw_string(char *buf, int length, const char *prompt, int verify);
+int _ossl_old_des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify);
#ifdef __cplusplus
}
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_UI,func,0)
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason)
-static ERR_STRING_DATA UI_str_functs[] =
-{
+static ERR_STRING_DATA UI_str_functs[] = {
{ERR_FUNC(UI_F_GENERAL_ALLOCATE_BOOLEAN), "GENERAL_ALLOCATE_BOOLEAN"},
{ERR_FUNC(UI_F_GENERAL_ALLOCATE_PROMPT), "GENERAL_ALLOCATE_PROMPT"},
{ERR_FUNC(UI_F_GENERAL_ALLOCATE_STRING), "GENERAL_ALLOCATE_STRING"},
{0, NULL}
};
-static ERR_STRING_DATA UI_str_reasons[] =
-{
+static ERR_STRING_DATA UI_str_reasons[] = {
{ERR_REASON(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS), "common ok and cancel characters"},
{ERR_REASON(UI_R_INDEX_TOO_LARGE), "index too large"},
{ERR_REASON(UI_R_INDEX_TOO_SMALL), "index too small"},
#endif
-void
+void
ERR_load_UI_strings(void)
{
#ifndef OPENSSL_NO_ERR
-
if (ERR_func_error_string(UI_str_functs[0].error) == NULL) {
ERR_load_strings(0, UI_str_functs);
ERR_load_strings(0, UI_str_reasons);
#include <openssl/err.h>
#include "ui_locl.h"
-IMPLEMENT_STACK_OF(UI_STRING_ST)
- static const UI_METHOD *default_UI_meth = NULL;
+IMPLEMENT_STACK_OF(UI_STRING_ST) static const UI_METHOD *default_UI_meth = NULL;
- UI *UI_new(void)
+UI *
+UI_new(void)
{
return (UI_new_method(NULL));
}
UI *
-UI_new_method(const UI_METHOD * method)
+UI_new_method(const UI_METHOD *method)
{
UI *ret;
return ret;
}
-static void
-free_string(UI_STRING * uis)
+static void
+free_string(UI_STRING *uis)
{
if (uis->flags & OUT_STRING_FREEABLE) {
free((char *) uis->out_string);
switch (uis->type) {
case UIT_BOOLEAN:
- free((char *) uis->_.boolean_data.action_desc);
- free((char *) uis->_.boolean_data.ok_chars);
- free((char *) uis->_.boolean_data.cancel_chars);
+ free((char *)uis->_.boolean_data.action_desc);
+ free((char *)uis->_.boolean_data.ok_chars);
+ free((char *)uis->_.boolean_data.cancel_chars);
break;
default:
break;
free(uis);
}
-void
-UI_free(UI * ui)
+void
+UI_free(UI *ui)
{
if (ui == NULL)
return;
free(ui);
}
-static int
-allocate_string_stack(UI * ui)
+static int
+allocate_string_stack(UI *ui)
{
if (ui->strings == NULL) {
ui->strings = sk_UI_STRING_new_null();
}
static UI_STRING *
-general_allocate_prompt(UI * ui, const char *prompt,
+general_allocate_prompt(UI *ui, const char *prompt,
int prompt_freeable, enum UI_string_types type, int input_flags,
char *result_buf)
{
if (prompt == NULL) {
UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, ERR_R_PASSED_NULL_PARAMETER);
- } else if ((type == UIT_PROMPT || type == UIT_VERIFY
- || type == UIT_BOOLEAN) && result_buf == NULL) {
+ } else if ((type == UIT_PROMPT || type == UIT_VERIFY ||
+ type == UIT_BOOLEAN) && result_buf == NULL) {
UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, UI_R_NO_RESULT_BUFFER);
} else if ((ret = (UI_STRING *) malloc(sizeof(UI_STRING)))) {
ret->out_string = prompt;
return ret;
}
-static int
-general_allocate_string(UI * ui, const char *prompt,
+static int
+general_allocate_string(UI *ui, const char *prompt,
int prompt_freeable, enum UI_string_types type, int input_flags,
char *result_buf, int minsize, int maxsize, const char *test_buf)
{
return ret;
}
-static int
-general_allocate_boolean(UI * ui,
+static int
+general_allocate_boolean(UI *ui,
const char *prompt, const char *action_desc,
const char *ok_chars, const char *cancel_chars,
int prompt_freeable, enum UI_string_types type, int input_flags,
/* Returns the index to the place in the stack or -1 for error. Uses a
direct reference to the prompt. */
-int
-UI_add_input_string(UI * ui, const char *prompt, int flags,
+int
+UI_add_input_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize)
{
return general_allocate_string(ui, prompt, 0,
}
/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
-int
-UI_dup_input_string(UI * ui, const char *prompt, int flags,
+int
+UI_dup_input_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize)
{
char *prompt_copy = NULL;
UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
}
-int
-UI_add_verify_string(UI * ui, const char *prompt, int flags,
+int
+UI_add_verify_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize, const char *test_buf)
{
return general_allocate_string(ui, prompt, 0,
UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
}
-int
-UI_dup_verify_string(UI * ui, const char *prompt, int flags,
+int
+UI_dup_verify_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize, const char *test_buf)
{
char *prompt_copy = NULL;
UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
}
-int
-UI_add_input_boolean(UI * ui, const char *prompt, const char *action_desc,
+int
+UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
const char *ok_chars, const char *cancel_chars,
int flags, char *result_buf)
{
ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
}
-int
-UI_dup_input_boolean(UI * ui, const char *prompt, const char *action_desc,
+int
+UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
const char *ok_chars, const char *cancel_chars,
int flags, char *result_buf)
{
return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
result_buf);
+
err:
if (prompt_copy)
free(prompt_copy);
return -1;
}
-int
-UI_add_info_string(UI * ui, const char *text)
+int
+UI_add_info_string(UI *ui, const char *text)
{
return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
NULL);
}
-int
-UI_dup_info_string(UI * ui, const char *text)
+int
+UI_dup_info_string(UI *ui, const char *text)
{
char *text_copy = NULL;
0, 0, NULL);
}
-int
-UI_add_error_string(UI * ui, const char *text)
+int
+UI_add_error_string(UI *ui, const char *text)
{
return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
NULL);
}
-int
-UI_dup_error_string(UI * ui, const char *text)
+int
+UI_dup_error_string(UI *ui, const char *text)
{
char *text_copy = NULL;
}
char *
-UI_construct_prompt(UI * ui, const char *object_desc,
- const char *object_name)
+UI_construct_prompt(UI *ui, const char *object_desc, const char *object_name)
{
char *prompt = NULL;
len += sizeof(prompt2) - 1 + strlen(object_name);
len += sizeof(prompt3) - 1;
- prompt = (char *) malloc(len + 1);
+ prompt = (char *)malloc(len + 1);
BUF_strlcpy(prompt, prompt1, len + 1);
BUF_strlcat(prompt, object_desc, len + 1);
if (object_name) {
}
void *
-UI_add_user_data(UI * ui, void *user_data)
+UI_add_user_data(UI *ui, void *user_data)
{
void *old_data = ui->user_data;
ui->user_data = user_data;
}
void *
-UI_get0_user_data(UI * ui)
+UI_get0_user_data(UI *ui)
{
return ui->user_data;
}
const char *
-UI_get0_result(UI * ui, int i)
+UI_get0_result(UI *ui, int i)
{
if (i < 0) {
UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_SMALL);
return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
}
-static int
-print_error(const char *str, size_t len, UI * ui)
+static int
+print_error(const char *str, size_t len, UI *ui)
{
UI_STRING uis;
uis.type = UIT_ERROR;
uis.out_string = str;
- if (ui->meth->ui_write_string
- && !ui->meth->ui_write_string(ui, &uis))
+ if (ui->meth->ui_write_string &&
+ !ui->meth->ui_write_string(ui, &uis))
return -1;
return 0;
}
-int
-UI_process(UI * ui)
+int
+UI_process(UI *ui)
{
int i, ok = 0;
if (ui->flags & UI_FLAG_PRINT_ERRORS)
ERR_print_errors_cb(
- (int (*) (const char *, size_t, void *)) print_error,
- (void *) ui);
+ (int (*)(const char *, size_t, void *)) print_error,
+ (void *)ui);
for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
- if (ui->meth->ui_write_string
- && !ui->meth->ui_write_string(ui,
+ if (ui->meth->ui_write_string &&
+ !ui->meth->ui_write_string(ui,
sk_UI_STRING_value(ui->strings, i))) {
ok = -1;
goto err;
case -1: /* Interrupt/Cancel/something... */
ok = -2;
goto err;
- case 0: /* Errors */
+ case 0: /* Errors */
ok = -1;
goto err;
default: /* Success */
for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
if (ui->meth->ui_read_string) {
switch (ui->meth->ui_read_string(ui,
- sk_UI_STRING_value(ui->strings, i))) {
+ sk_UI_STRING_value(ui->strings, i))) {
case -1: /* Interrupt/Cancel/something... */
ok = -2;
goto err;
- case 0:/* Errors */
+ case 0: /* Errors */
ok = -1;
goto err;
default: /* Success */
return ok;
}
-int
-UI_ctrl(UI * ui, int cmd, long i, void *p, void (*f) (void))
+int
+UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void))
{
if (ui == NULL) {
UIerr(UI_F_UI_CTRL, ERR_R_PASSED_NULL_PARAMETER);
return -1;
}
-int
-UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new * new_func,
- CRYPTO_EX_dup * dup_func, CRYPTO_EX_free * free_func)
+int
+UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
{
return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
new_func, dup_func, free_func);
}
-int
-UI_set_ex_data(UI * r, int idx, void *arg)
+int
+UI_set_ex_data(UI *r, int idx, void *arg)
{
return (CRYPTO_set_ex_data(&r->ex_data, idx, arg));
}
void *
-UI_get_ex_data(UI * r, int idx)
+UI_get_ex_data(UI *r, int idx)
{
return (CRYPTO_get_ex_data(&r->ex_data, idx));
}
-void
-UI_set_default_method(const UI_METHOD * meth)
+void
+UI_set_default_method(const UI_METHOD *meth)
{
default_UI_meth = meth;
}
}
const UI_METHOD *
-UI_get_method(UI * ui)
+UI_get_method(UI *ui)
{
return ui->meth;
}
const UI_METHOD *
-UI_set_method(UI * ui, const UI_METHOD * meth)
+UI_set_method(UI *ui, const UI_METHOD *meth)
{
ui->meth = meth;
return ui->meth;
/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
(that is, it hasn't been allocated using UI_create_method(), you deserve
anything Murphy can throw at you and more! You have been warned. */
-void
-UI_destroy_method(UI_METHOD * ui_method)
+void
+UI_destroy_method(UI_METHOD *ui_method)
{
free(ui_method->name);
ui_method->name = NULL;
free(ui_method);
}
-int
-UI_method_set_opener(UI_METHOD * method, int (*opener) (UI * ui))
+int
+UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
{
if (method) {
method->ui_open_session = opener;
return -1;
}
-int
-UI_method_set_writer(UI_METHOD * method, int (*writer) (UI * ui, UI_STRING * uis))
+int
+UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
{
if (method) {
method->ui_write_string = writer;
return -1;
}
-int
-UI_method_set_flusher(UI_METHOD * method, int (*flusher) (UI * ui))
+int
+UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui))
{
if (method) {
method->ui_flush = flusher;
return -1;
}
-int
-UI_method_set_reader(UI_METHOD * method, int (*reader) (UI * ui, UI_STRING * uis))
+int
+UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
{
if (method) {
method->ui_read_string = reader;
return -1;
}
-int
-UI_method_set_closer(UI_METHOD * method, int (*closer) (UI * ui))
+int
+UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
{
if (method) {
method->ui_close_session = closer;
return -1;
}
-int
-UI_method_set_prompt_constructor(UI_METHOD * method, char *(*prompt_constructor) (UI * ui, const char *object_desc, const char *object_name))
+int
+UI_method_set_prompt_constructor(UI_METHOD *method,
+ char *(*prompt_constructor)(UI *ui, const char *object_desc,
+ const char *object_name))
{
if (method) {
method->ui_construct_prompt = prompt_constructor;
return -1;
}
-int (*
- UI_method_get_opener(UI_METHOD * method)) (UI *)
+int
+(*UI_method_get_opener(UI_METHOD * method))(UI *)
{
if (method)
return method->ui_open_session;
return NULL;
}
-int (*
- UI_method_get_writer(UI_METHOD * method)) (UI *, UI_STRING *)
+int
+(*UI_method_get_writer(UI_METHOD *method))(UI *, UI_STRING *)
{
if (method)
return method->ui_write_string;
return NULL;
}
-int (*
- UI_method_get_flusher(UI_METHOD * method)) (UI *)
+int
+(*UI_method_get_flusher(UI_METHOD *method)) (UI *)
{
if (method)
return method->ui_flush;
return NULL;
}
-int (*
- UI_method_get_reader(UI_METHOD * method)) (UI *, UI_STRING *)
+int
+(*UI_method_get_reader(UI_METHOD *method))(UI *, UI_STRING *)
{
if (method)
return method->ui_read_string;
return NULL;
}
-int (*
- UI_method_get_closer(UI_METHOD * method)) (UI *)
+int
+(*UI_method_get_closer(UI_METHOD *method))(UI *)
{
if (method)
return method->ui_close_session;
return NULL;
}
-char *(*
- UI_method_get_prompt_constructor(UI_METHOD * method)) (UI *, const char *, const char *)
+char *
+(*UI_method_get_prompt_constructor(UI_METHOD *method))(UI *, const char *,
+ const char *)
{
if (method)
return method->ui_construct_prompt;
return NULL;
}
-enum UI_string_types
-UI_get_string_type(UI_STRING * uis)
+enum UI_string_types
+UI_get_string_type(UI_STRING *uis)
{
if (!uis)
return UIT_NONE;
return uis->type;
}
-int
-UI_get_input_flags(UI_STRING * uis)
+int
+UI_get_input_flags(UI_STRING *uis)
{
if (!uis)
return 0;
}
const char *
-UI_get0_output_string(UI_STRING * uis)
+UI_get0_output_string(UI_STRING *uis)
{
if (!uis)
return NULL;
}
const char *
-UI_get0_action_string(UI_STRING * uis)
+UI_get0_action_string(UI_STRING *uis)
{
if (!uis)
return NULL;
}
const char *
-UI_get0_result_string(UI_STRING * uis)
+UI_get0_result_string(UI_STRING *uis)
{
if (!uis)
return NULL;
}
const char *
-UI_get0_test_string(UI_STRING * uis)
+UI_get0_test_string(UI_STRING *uis)
{
if (!uis)
return NULL;
}
}
-int
-UI_get_result_minsize(UI_STRING * uis)
+int
+UI_get_result_minsize(UI_STRING *uis)
{
if (!uis)
return -1;
}
}
-int
-UI_get_result_maxsize(UI_STRING * uis)
+int
+UI_get_result_maxsize(UI_STRING *uis)
{
if (!uis)
return -1;
}
}
-int
-UI_set_result(UI * ui, UI_STRING * uis, const char *result)
+int
+UI_set_result(UI *ui, UI_STRING *uis, const char *result)
{
int l = strlen(result);
break;
}
}
- default:
+ default:
break;
}
}
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
#undef _
#endif
-struct ui_method_st
- {
+struct ui_method_st {
char *name;
/* All the functions return 1 or non-NULL for success and 0 or NULL
The returned string shall always be allocated on the heap with
malloc(), and need to be free'd with free(). */
char *(*ui_construct_prompt)(UI *ui, const char *object_desc,
- const char *object_name);
- };
+ const char *object_name);
+};
-struct ui_string_st
- {
+struct ui_string_st {
enum UI_string_types type; /* Input */
const char *out_string; /* Input */
int input_flags; /* Flags from the user */
with size in result_maxsize. Otherwise, it
may be allocated by the UI routine, meaning
result_minsize is going to be overwritten.*/
- union
- {
- struct
- {
+ union {
+ struct {
int result_minsize; /* Input: minimum required
size of the result.
*/
const char *test_buf; /* Input: test string to verify
against */
- } string_data;
- struct
- {
+ } string_data;
+ struct {
const char *action_desc; /* Input */
const char *ok_chars; /* Input */
const char *cancel_chars; /* Input */
- } boolean_data;
- } _;
+ } boolean_data;
+ } _;
#define OUT_STRING_FREEABLE 0x01
int flags; /* flags for internal use */
- };
+};
-struct ui_st
- {
+struct ui_st {
const UI_METHOD *meth;
STACK_OF(UI_STRING) *strings; /* We might want to prompt for more
than one thing at a time, and
#define UI_FLAG_REDOABLE 0x0001
#define UI_FLAG_PRINT_ERRORS 0x0100
int flags;
- };
+};
#endif
* [including the GNU Public Licence.]
*/
-
#include <openssl/e_os2.h>
#include <signal.h>
static void recsig(int);
static void pushsig(void);
static void popsig(void);
-static int read_string_inner(UI * ui, UI_STRING * uis, int echo, int strip_nl);
+static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
-static int read_string(UI * ui, UI_STRING * uis);
-static int write_string(UI * ui, UI_STRING * uis);
+static int read_string(UI *ui, UI_STRING *uis);
+static int write_string(UI *ui, UI_STRING *uis);
-static int open_console(UI * ui);
-static int echo_console(UI * ui);
-static int noecho_console(UI * ui);
-static int close_console(UI * ui);
+static int open_console(UI *ui);
+static int echo_console(UI *ui);
+static int noecho_console(UI *ui);
+static int close_console(UI *ui);
-static UI_METHOD ui_openssl =
-{
+static UI_METHOD ui_openssl = {
"OpenSSL default user interface",
open_console,
write_string,
/* The following function makes sure that info and error strings are printed
before any prompt. */
-static int
-write_string(UI * ui, UI_STRING * uis)
+static int
+write_string(UI *ui, UI_STRING *uis)
{
switch (UI_get_string_type(uis)) {
- case UIT_ERROR:
- case UIT_INFO:
+ case UIT_ERROR:
+ case UIT_INFO:
fputs(UI_get0_output_string(uis), tty_out);
fflush(tty_out);
break;
return 1;
}
-static int
-read_string(UI * ui, UI_STRING * uis)
+static int
+read_string(UI *ui, UI_STRING *uis)
{
int ok = 0;
UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
return ok;
if (strcmp(UI_get0_result_string(uis),
- UI_get0_test_string(uis)) != 0) {
+ UI_get0_test_string(uis)) != 0) {
fprintf(tty_out, "Verify failure\n");
fflush(tty_out);
return 0;
/* Internal functions to read a string without echoing */
-static int
-read_till_nl(FILE * in)
+static int
+read_till_nl(FILE *in)
{
#define SIZE 4
char buf[SIZE + 1];
static volatile sig_atomic_t intr_signal;
-static int
-read_string_inner(UI * ui, UI_STRING * uis, int echo, int strip_nl)
+static int
+read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
{
static int ps;
int ok;
/* Internal functions to open, handle and close a channel to the console. */
-static int
-open_console(UI * ui)
+static int
+open_console(UI *ui)
{
CRYPTO_w_lock(CRYPTO_LOCK_UI);
is_a_tty = 1;
* solaris can return EINVAL instead. This should be
* ok
*/
- if (errno == EINVAL)
- is_a_tty = 0;
+ if (errno == EINVAL)
+ is_a_tty = 0;
else
return 0;
}
return 1;
}
-static int
-noecho_console(UI * ui)
+static int
+noecho_console(UI *ui)
{
#ifdef TTY_FLAGS
memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
return 1;
}
-static int
-echo_console(UI * ui)
+static int
+echo_console(UI *ui)
{
#if defined(TTY_set)
memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
return 1;
}
-static int
-close_console(UI * ui)
+static int
+close_console(UI *ui)
{
if (tty_in != stdin)
fclose(tty_in);
/* Internal functions to handle signals and act on them */
-static void
+static void
pushsig(void)
{
int i;
#endif
}
-static void
+static void
popsig(void)
{
int i;
}
}
-static void
+static void
recsig(int i)
{
intr_signal = i;
#include <string.h>
#include "ui_locl.h"
-int
+int
UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
{
char buff[BUFSIZ];
int ret;
- ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length, prompt, verify);
+ ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,
+ prompt, verify);
OPENSSL_cleanse(buff, BUFSIZ);
return (ret);
}
-int
+int
UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
{
int ok = 0;
if (ui) {
ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1);
if (ok >= 0 && verify)
- ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1,
- buf);
+ ok = UI_add_verify_string(ui, prompt, 0, buff, 0,
+ size - 1, buf);
if (ok >= 0)
ok = UI_process(ui);
UI_free(ui);