From: jsing Date: Fri, 18 Apr 2014 05:37:44 +0000 (+0000) Subject: More KNF. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c3bf35506bd105697d3974c688ac341f5c2d6771;p=openbsd More KNF. --- diff --git a/lib/libcrypto/ui/ui.h b/lib/libcrypto/ui/ui.h index ed35e50eb45..7970f893d64 100644 --- a/lib/libcrypto/ui/ui.h +++ b/lib/libcrypto/ui/ui.h @@ -10,7 +10,7 @@ * 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 @@ -128,19 +128,19 @@ void UI_free(UI *ui); 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); @@ -185,8 +185,8 @@ int UI_dup_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. @@ -228,8 +228,8 @@ int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)); #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 */ @@ -292,15 +292,14 @@ DECLARE_STACK_OF(UI_STRING) /* 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); @@ -312,9 +311,9 @@ int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis 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*); @@ -342,8 +341,8 @@ int UI_set_result(UI *ui, UI_STRING *uis, const char *result); /* 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 */ diff --git a/lib/libcrypto/ui/ui_compat.c b/lib/libcrypto/ui/ui_compat.c index 2c5ee4dcee0..416e035bdfd 100644 --- a/lib/libcrypto/ui/ui_compat.c +++ b/lib/libcrypto/ui/ui_compat.c @@ -56,13 +56,13 @@ #include #include -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); diff --git a/lib/libcrypto/ui/ui_compat.h b/lib/libcrypto/ui/ui_compat.h index b35c9bb7fd3..75c2ae1ef92 100644 --- a/lib/libcrypto/ui/ui_compat.h +++ b/lib/libcrypto/ui/ui_compat.h @@ -10,7 +10,7 @@ * 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 @@ -74,8 +74,8 @@ extern "C" { #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 } diff --git a/lib/libcrypto/ui/ui_err.c b/lib/libcrypto/ui/ui_err.c index a9b22e2e573..e8b841eb0d9 100644 --- a/lib/libcrypto/ui/ui_err.c +++ b/lib/libcrypto/ui/ui_err.c @@ -68,8 +68,7 @@ #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"}, @@ -85,8 +84,7 @@ static ERR_STRING_DATA UI_str_functs[] = {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"}, @@ -99,11 +97,10 @@ static ERR_STRING_DATA UI_str_reasons[] = #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); diff --git a/lib/libcrypto/ui/ui_lib.c b/lib/libcrypto/ui/ui_lib.c index 32fb9d7dbb9..fc03d9b7d4c 100644 --- a/lib/libcrypto/ui/ui_lib.c +++ b/lib/libcrypto/ui/ui_lib.c @@ -64,16 +64,16 @@ #include #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; @@ -94,16 +94,16 @@ UI_new_method(const UI_METHOD * method) 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; @@ -112,8 +112,8 @@ free_string(UI_STRING * uis) free(uis); } -void -UI_free(UI * ui) +void +UI_free(UI *ui) { if (ui == NULL) return; @@ -122,8 +122,8 @@ UI_free(UI * ui) 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(); @@ -135,7 +135,7 @@ allocate_string_stack(UI * ui) } 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) { @@ -143,8 +143,8 @@ general_allocate_prompt(UI * ui, const char *prompt, 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; @@ -156,8 +156,8 @@ general_allocate_prompt(UI * ui, const char *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) { @@ -180,8 +180,8 @@ general_allocate_string(UI * ui, const char *prompt, 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, @@ -227,8 +227,8 @@ general_allocate_boolean(UI * ui, /* 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, @@ -236,8 +236,8 @@ UI_add_input_string(UI * ui, const char *prompt, int flags, } /* 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; @@ -253,16 +253,16 @@ UI_dup_input_string(UI * ui, const char *prompt, int flags, 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; @@ -278,8 +278,8 @@ UI_dup_verify_string(UI * ui, const char *prompt, int flags, 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) { @@ -287,8 +287,8 @@ UI_add_input_boolean(UI * ui, const char *prompt, const char *action_desc, 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) { @@ -328,6 +328,7 @@ UI_dup_input_boolean(UI * ui, const char *prompt, const char *action_desc, 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); @@ -340,15 +341,15 @@ err: 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; @@ -363,15 +364,15 @@ UI_dup_info_string(UI * ui, const char *text) 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; @@ -387,8 +388,7 @@ UI_dup_error_string(UI * ui, const char *text) } 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; @@ -408,7 +408,7 @@ UI_construct_prompt(UI * ui, const char *object_desc, 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) { @@ -421,7 +421,7 @@ UI_construct_prompt(UI * ui, const char *object_desc, } 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; @@ -429,13 +429,13 @@ UI_add_user_data(UI * ui, void *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); @@ -448,8 +448,8 @@ UI_get0_result(UI * ui, int i) 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; @@ -457,14 +457,14 @@ print_error(const char *str, size_t len, UI * ui) 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; @@ -473,12 +473,12 @@ UI_process(UI * ui) 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; @@ -490,7 +490,7 @@ UI_process(UI * ui) case -1: /* Interrupt/Cancel/something... */ ok = -2; goto err; - case 0: /* Errors */ + case 0: /* Errors */ ok = -1; goto err; default: /* Success */ @@ -501,11 +501,11 @@ UI_process(UI * ui) 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 */ @@ -520,8 +520,8 @@ err: 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); @@ -546,28 +546,28 @@ UI_ctrl(UI * ui, int cmd, long i, void *p, void (*f) (void)) 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; } @@ -582,13 +582,13 @@ UI_get_default_method(void) } 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; @@ -610,16 +610,16 @@ UI_create_method(char *name) /* 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; @@ -628,8 +628,8 @@ UI_method_set_opener(UI_METHOD * method, int (*opener) (UI * ui)) 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; @@ -638,8 +638,8 @@ UI_method_set_writer(UI_METHOD * method, int (*writer) (UI * ui, UI_STRING * uis 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; @@ -648,8 +648,8 @@ UI_method_set_flusher(UI_METHOD * method, int (*flusher) (UI * ui)) 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; @@ -658,8 +658,8 @@ UI_method_set_reader(UI_METHOD * method, int (*reader) (UI * ui, UI_STRING * uis 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; @@ -668,8 +668,10 @@ UI_method_set_closer(UI_METHOD * method, int (*closer) (UI * ui)) 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; @@ -678,8 +680,8 @@ UI_method_set_prompt_constructor(UI_METHOD * method, char *(*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; @@ -687,8 +689,8 @@ int (* 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; @@ -696,8 +698,8 @@ int (* 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; @@ -705,8 +707,8 @@ int (* 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; @@ -714,8 +716,8 @@ int (* 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; @@ -723,8 +725,9 @@ int (* 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; @@ -732,16 +735,16 @@ char *(* 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; @@ -749,7 +752,7 @@ UI_get_input_flags(UI_STRING * uis) } const char * -UI_get0_output_string(UI_STRING * uis) +UI_get0_output_string(UI_STRING *uis) { if (!uis) return NULL; @@ -757,7 +760,7 @@ UI_get0_output_string(UI_STRING * uis) } const char * -UI_get0_action_string(UI_STRING * uis) +UI_get0_action_string(UI_STRING *uis) { if (!uis) return NULL; @@ -771,7 +774,7 @@ UI_get0_action_string(UI_STRING * uis) } const char * -UI_get0_result_string(UI_STRING * uis) +UI_get0_result_string(UI_STRING *uis) { if (!uis) return NULL; @@ -785,7 +788,7 @@ UI_get0_result_string(UI_STRING * uis) } const char * -UI_get0_test_string(UI_STRING * uis) +UI_get0_test_string(UI_STRING *uis) { if (!uis) return NULL; @@ -797,8 +800,8 @@ UI_get0_test_string(UI_STRING * uis) } } -int -UI_get_result_minsize(UI_STRING * uis) +int +UI_get_result_minsize(UI_STRING *uis) { if (!uis) return -1; @@ -811,8 +814,8 @@ UI_get_result_minsize(UI_STRING * uis) } } -int -UI_get_result_maxsize(UI_STRING * uis) +int +UI_get_result_maxsize(UI_STRING *uis) { if (!uis) return -1; @@ -825,8 +828,8 @@ UI_get_result_maxsize(UI_STRING * uis) } } -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); @@ -890,7 +893,7 @@ UI_set_result(UI * ui, UI_STRING * uis, const char *result) break; } } - default: + default: break; } } diff --git a/lib/libcrypto/ui/ui_locl.h b/lib/libcrypto/ui/ui_locl.h index 39789e26380..d6c4e261927 100644 --- a/lib/libcrypto/ui/ui_locl.h +++ b/lib/libcrypto/ui/ui_locl.h @@ -10,7 +10,7 @@ * 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 @@ -66,8 +66,7 @@ #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 @@ -96,11 +95,10 @@ struct ui_method_st 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 */ @@ -111,10 +109,8 @@ struct ui_string_st 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. */ @@ -123,21 +119,19 @@ struct ui_string_st 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 @@ -148,6 +142,6 @@ struct ui_st #define UI_FLAG_REDOABLE 0x0001 #define UI_FLAG_PRINT_ERRORS 0x0100 int flags; - }; +}; #endif diff --git a/lib/libcrypto/ui/ui_openssl.c b/lib/libcrypto/ui/ui_openssl.c index 94a999baa8d..ef483352ea3 100644 --- a/lib/libcrypto/ui/ui_openssl.c +++ b/lib/libcrypto/ui/ui_openssl.c @@ -114,7 +114,6 @@ * [including the GNU Public Licence.] */ - #include #include @@ -187,18 +186,17 @@ static int read_till_nl(FILE *); 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, @@ -217,12 +215,12 @@ UI_OpenSSL(void) /* 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; @@ -232,8 +230,8 @@ write_string(UI * ui, UI_STRING * uis) return 1; } -static int -read_string(UI * ui, UI_STRING * uis) +static int +read_string(UI *ui, UI_STRING *uis) { int ok = 0; @@ -257,7 +255,7 @@ read_string(UI * ui, UI_STRING * uis) 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; @@ -271,8 +269,8 @@ read_string(UI * ui, UI_STRING * uis) /* 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]; @@ -286,8 +284,8 @@ read_till_nl(FILE * in) 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; @@ -339,8 +337,8 @@ error: /* 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; @@ -361,8 +359,8 @@ open_console(UI * ui) * 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; } @@ -370,8 +368,8 @@ open_console(UI * ui) 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)); @@ -385,8 +383,8 @@ noecho_console(UI * ui) 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)); @@ -400,8 +398,8 @@ echo_console(UI * ui) return 1; } -static int -close_console(UI * ui) +static int +close_console(UI *ui) { if (tty_in != stdin) fclose(tty_in); @@ -414,7 +412,7 @@ close_console(UI * ui) /* Internal functions to handle signals and act on them */ -static void +static void pushsig(void) { int i; @@ -450,7 +448,7 @@ pushsig(void) #endif } -static void +static void popsig(void) { int i; @@ -467,7 +465,7 @@ popsig(void) } } -static void +static void recsig(int i) { intr_signal = i; diff --git a/lib/libcrypto/ui/ui_util.c b/lib/libcrypto/ui/ui_util.c index af504514034..81c5a079a65 100644 --- a/lib/libcrypto/ui/ui_util.c +++ b/lib/libcrypto/ui/ui_util.c @@ -56,18 +56,19 @@ #include #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; @@ -80,8 +81,8 @@ UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify) 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); diff --git a/lib/libssl/src/crypto/ui/ui.h b/lib/libssl/src/crypto/ui/ui.h index ed35e50eb45..7970f893d64 100644 --- a/lib/libssl/src/crypto/ui/ui.h +++ b/lib/libssl/src/crypto/ui/ui.h @@ -10,7 +10,7 @@ * 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 @@ -128,19 +128,19 @@ void UI_free(UI *ui); 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); @@ -185,8 +185,8 @@ int UI_dup_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. @@ -228,8 +228,8 @@ int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)); #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 */ @@ -292,15 +292,14 @@ DECLARE_STACK_OF(UI_STRING) /* 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); @@ -312,9 +311,9 @@ int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis 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*); @@ -342,8 +341,8 @@ int UI_set_result(UI *ui, UI_STRING *uis, const char *result); /* 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 */ diff --git a/lib/libssl/src/crypto/ui/ui_compat.c b/lib/libssl/src/crypto/ui/ui_compat.c index 2c5ee4dcee0..416e035bdfd 100644 --- a/lib/libssl/src/crypto/ui/ui_compat.c +++ b/lib/libssl/src/crypto/ui/ui_compat.c @@ -56,13 +56,13 @@ #include #include -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); diff --git a/lib/libssl/src/crypto/ui/ui_compat.h b/lib/libssl/src/crypto/ui/ui_compat.h index b35c9bb7fd3..75c2ae1ef92 100644 --- a/lib/libssl/src/crypto/ui/ui_compat.h +++ b/lib/libssl/src/crypto/ui/ui_compat.h @@ -10,7 +10,7 @@ * 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 @@ -74,8 +74,8 @@ extern "C" { #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 } diff --git a/lib/libssl/src/crypto/ui/ui_err.c b/lib/libssl/src/crypto/ui/ui_err.c index a9b22e2e573..e8b841eb0d9 100644 --- a/lib/libssl/src/crypto/ui/ui_err.c +++ b/lib/libssl/src/crypto/ui/ui_err.c @@ -68,8 +68,7 @@ #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"}, @@ -85,8 +84,7 @@ static ERR_STRING_DATA UI_str_functs[] = {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"}, @@ -99,11 +97,10 @@ static ERR_STRING_DATA UI_str_reasons[] = #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); diff --git a/lib/libssl/src/crypto/ui/ui_lib.c b/lib/libssl/src/crypto/ui/ui_lib.c index 32fb9d7dbb9..fc03d9b7d4c 100644 --- a/lib/libssl/src/crypto/ui/ui_lib.c +++ b/lib/libssl/src/crypto/ui/ui_lib.c @@ -64,16 +64,16 @@ #include #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; @@ -94,16 +94,16 @@ UI_new_method(const UI_METHOD * method) 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; @@ -112,8 +112,8 @@ free_string(UI_STRING * uis) free(uis); } -void -UI_free(UI * ui) +void +UI_free(UI *ui) { if (ui == NULL) return; @@ -122,8 +122,8 @@ UI_free(UI * ui) 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(); @@ -135,7 +135,7 @@ allocate_string_stack(UI * ui) } 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) { @@ -143,8 +143,8 @@ general_allocate_prompt(UI * ui, const char *prompt, 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; @@ -156,8 +156,8 @@ general_allocate_prompt(UI * ui, const char *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) { @@ -180,8 +180,8 @@ general_allocate_string(UI * ui, const char *prompt, 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, @@ -227,8 +227,8 @@ general_allocate_boolean(UI * ui, /* 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, @@ -236,8 +236,8 @@ UI_add_input_string(UI * ui, const char *prompt, int flags, } /* 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; @@ -253,16 +253,16 @@ UI_dup_input_string(UI * ui, const char *prompt, int flags, 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; @@ -278,8 +278,8 @@ UI_dup_verify_string(UI * ui, const char *prompt, int flags, 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) { @@ -287,8 +287,8 @@ UI_add_input_boolean(UI * ui, const char *prompt, const char *action_desc, 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) { @@ -328,6 +328,7 @@ UI_dup_input_boolean(UI * ui, const char *prompt, const char *action_desc, 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); @@ -340,15 +341,15 @@ err: 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; @@ -363,15 +364,15 @@ UI_dup_info_string(UI * ui, const char *text) 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; @@ -387,8 +388,7 @@ UI_dup_error_string(UI * ui, const char *text) } 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; @@ -408,7 +408,7 @@ UI_construct_prompt(UI * ui, const char *object_desc, 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) { @@ -421,7 +421,7 @@ UI_construct_prompt(UI * ui, const char *object_desc, } 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; @@ -429,13 +429,13 @@ UI_add_user_data(UI * ui, void *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); @@ -448,8 +448,8 @@ UI_get0_result(UI * ui, int i) 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; @@ -457,14 +457,14 @@ print_error(const char *str, size_t len, UI * ui) 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; @@ -473,12 +473,12 @@ UI_process(UI * ui) 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; @@ -490,7 +490,7 @@ UI_process(UI * ui) case -1: /* Interrupt/Cancel/something... */ ok = -2; goto err; - case 0: /* Errors */ + case 0: /* Errors */ ok = -1; goto err; default: /* Success */ @@ -501,11 +501,11 @@ UI_process(UI * ui) 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 */ @@ -520,8 +520,8 @@ err: 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); @@ -546,28 +546,28 @@ UI_ctrl(UI * ui, int cmd, long i, void *p, void (*f) (void)) 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; } @@ -582,13 +582,13 @@ UI_get_default_method(void) } 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; @@ -610,16 +610,16 @@ UI_create_method(char *name) /* 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; @@ -628,8 +628,8 @@ UI_method_set_opener(UI_METHOD * method, int (*opener) (UI * ui)) 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; @@ -638,8 +638,8 @@ UI_method_set_writer(UI_METHOD * method, int (*writer) (UI * ui, UI_STRING * uis 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; @@ -648,8 +648,8 @@ UI_method_set_flusher(UI_METHOD * method, int (*flusher) (UI * ui)) 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; @@ -658,8 +658,8 @@ UI_method_set_reader(UI_METHOD * method, int (*reader) (UI * ui, UI_STRING * uis 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; @@ -668,8 +668,10 @@ UI_method_set_closer(UI_METHOD * method, int (*closer) (UI * ui)) 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; @@ -678,8 +680,8 @@ UI_method_set_prompt_constructor(UI_METHOD * method, char *(*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; @@ -687,8 +689,8 @@ int (* 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; @@ -696,8 +698,8 @@ int (* 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; @@ -705,8 +707,8 @@ int (* 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; @@ -714,8 +716,8 @@ int (* 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; @@ -723,8 +725,9 @@ int (* 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; @@ -732,16 +735,16 @@ char *(* 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; @@ -749,7 +752,7 @@ UI_get_input_flags(UI_STRING * uis) } const char * -UI_get0_output_string(UI_STRING * uis) +UI_get0_output_string(UI_STRING *uis) { if (!uis) return NULL; @@ -757,7 +760,7 @@ UI_get0_output_string(UI_STRING * uis) } const char * -UI_get0_action_string(UI_STRING * uis) +UI_get0_action_string(UI_STRING *uis) { if (!uis) return NULL; @@ -771,7 +774,7 @@ UI_get0_action_string(UI_STRING * uis) } const char * -UI_get0_result_string(UI_STRING * uis) +UI_get0_result_string(UI_STRING *uis) { if (!uis) return NULL; @@ -785,7 +788,7 @@ UI_get0_result_string(UI_STRING * uis) } const char * -UI_get0_test_string(UI_STRING * uis) +UI_get0_test_string(UI_STRING *uis) { if (!uis) return NULL; @@ -797,8 +800,8 @@ UI_get0_test_string(UI_STRING * uis) } } -int -UI_get_result_minsize(UI_STRING * uis) +int +UI_get_result_minsize(UI_STRING *uis) { if (!uis) return -1; @@ -811,8 +814,8 @@ UI_get_result_minsize(UI_STRING * uis) } } -int -UI_get_result_maxsize(UI_STRING * uis) +int +UI_get_result_maxsize(UI_STRING *uis) { if (!uis) return -1; @@ -825,8 +828,8 @@ UI_get_result_maxsize(UI_STRING * uis) } } -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); @@ -890,7 +893,7 @@ UI_set_result(UI * ui, UI_STRING * uis, const char *result) break; } } - default: + default: break; } } diff --git a/lib/libssl/src/crypto/ui/ui_locl.h b/lib/libssl/src/crypto/ui/ui_locl.h index 39789e26380..d6c4e261927 100644 --- a/lib/libssl/src/crypto/ui/ui_locl.h +++ b/lib/libssl/src/crypto/ui/ui_locl.h @@ -10,7 +10,7 @@ * 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 @@ -66,8 +66,7 @@ #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 @@ -96,11 +95,10 @@ struct ui_method_st 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 */ @@ -111,10 +109,8 @@ struct ui_string_st 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. */ @@ -123,21 +119,19 @@ struct ui_string_st 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 @@ -148,6 +142,6 @@ struct ui_st #define UI_FLAG_REDOABLE 0x0001 #define UI_FLAG_PRINT_ERRORS 0x0100 int flags; - }; +}; #endif diff --git a/lib/libssl/src/crypto/ui/ui_openssl.c b/lib/libssl/src/crypto/ui/ui_openssl.c index 94a999baa8d..ef483352ea3 100644 --- a/lib/libssl/src/crypto/ui/ui_openssl.c +++ b/lib/libssl/src/crypto/ui/ui_openssl.c @@ -114,7 +114,6 @@ * [including the GNU Public Licence.] */ - #include #include @@ -187,18 +186,17 @@ static int read_till_nl(FILE *); 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, @@ -217,12 +215,12 @@ UI_OpenSSL(void) /* 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; @@ -232,8 +230,8 @@ write_string(UI * ui, UI_STRING * uis) return 1; } -static int -read_string(UI * ui, UI_STRING * uis) +static int +read_string(UI *ui, UI_STRING *uis) { int ok = 0; @@ -257,7 +255,7 @@ read_string(UI * ui, UI_STRING * uis) 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; @@ -271,8 +269,8 @@ read_string(UI * ui, UI_STRING * uis) /* 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]; @@ -286,8 +284,8 @@ read_till_nl(FILE * in) 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; @@ -339,8 +337,8 @@ error: /* 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; @@ -361,8 +359,8 @@ open_console(UI * ui) * 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; } @@ -370,8 +368,8 @@ open_console(UI * ui) 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)); @@ -385,8 +383,8 @@ noecho_console(UI * ui) 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)); @@ -400,8 +398,8 @@ echo_console(UI * ui) return 1; } -static int -close_console(UI * ui) +static int +close_console(UI *ui) { if (tty_in != stdin) fclose(tty_in); @@ -414,7 +412,7 @@ close_console(UI * ui) /* Internal functions to handle signals and act on them */ -static void +static void pushsig(void) { int i; @@ -450,7 +448,7 @@ pushsig(void) #endif } -static void +static void popsig(void) { int i; @@ -467,7 +465,7 @@ popsig(void) } } -static void +static void recsig(int i) { intr_signal = i; diff --git a/lib/libssl/src/crypto/ui/ui_util.c b/lib/libssl/src/crypto/ui/ui_util.c index af504514034..81c5a079a65 100644 --- a/lib/libssl/src/crypto/ui/ui_util.c +++ b/lib/libssl/src/crypto/ui/ui_util.c @@ -56,18 +56,19 @@ #include #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; @@ -80,8 +81,8 @@ UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify) 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);