summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortedu <>2014-04-17 22:37:59 +0000
committertedu <>2014-04-17 22:37:59 +0000
commit4eaf48dd2cdab352d97fac22655d61c3da773d72 (patch)
tree821354c596b97115962e666d119a8ee8fedff14b
parent750723d995eaa75bcee4b0391acd1847a464e058 (diff)
downloadopenbsd-4eaf48dd2cdab352d97fac22655d61c3da773d72.tar.gz
openbsd-4eaf48dd2cdab352d97fac22655d61c3da773d72.tar.bz2
openbsd-4eaf48dd2cdab352d97fac22655d61c3da773d72.zip
stab at indentation
-rw-r--r--src/lib/libcrypto/ui/ui_compat.c16
-rw-r--r--src/lib/libcrypto/ui/ui_err.c72
-rw-r--r--src/lib/libcrypto/ui/ui_lib.c1022
-rw-r--r--src/lib/libcrypto/ui/ui_openssl.c315
-rw-r--r--src/lib/libcrypto/ui/ui_util.c37
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_compat.c16
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_err.c72
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_lib.c1022
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_openssl.c315
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_util.c37
10 files changed, 1450 insertions, 1474 deletions
diff --git a/src/lib/libcrypto/ui/ui_compat.c b/src/lib/libcrypto/ui/ui_compat.c
index 13e0f70d90..2c5ee4dcee 100644
--- a/src/lib/libcrypto/ui/ui_compat.c
+++ b/src/lib/libcrypto/ui/ui_compat.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -56,12 +56,14 @@
56#include <string.h> 56#include <string.h>
57#include <openssl/ui_compat.h> 57#include <openssl/ui_compat.h>
58 58
59int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify) 59int
60 { 60_ossl_old_des_read_pw_string(char *buf, int length, const char *prompt, int verify)
61{
61 return UI_UTIL_read_pw_string(buf, length, prompt, verify); 62 return UI_UTIL_read_pw_string(buf, length, prompt, verify);
62 } 63}
63 64
64int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify) 65int
65 { 66_ossl_old_des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
67{
66 return UI_UTIL_read_pw(buf, buff, size, prompt, verify); 68 return UI_UTIL_read_pw(buf, buff, size, prompt, verify);
67 } 69}
diff --git a/src/lib/libcrypto/ui/ui_err.c b/src/lib/libcrypto/ui/ui_err.c
index a6b96299a0..a9b22e2e57 100644
--- a/src/lib/libcrypto/ui/ui_err.c
+++ b/src/lib/libcrypto/ui/ui_err.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -68,45 +68,45 @@
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_UI,func,0) 68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_UI,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason) 69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason)
70 70
71static ERR_STRING_DATA UI_str_functs[]= 71static ERR_STRING_DATA UI_str_functs[] =
72 { 72{
73{ERR_FUNC(UI_F_GENERAL_ALLOCATE_BOOLEAN), "GENERAL_ALLOCATE_BOOLEAN"}, 73 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_BOOLEAN), "GENERAL_ALLOCATE_BOOLEAN"},
74{ERR_FUNC(UI_F_GENERAL_ALLOCATE_PROMPT), "GENERAL_ALLOCATE_PROMPT"}, 74 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_PROMPT), "GENERAL_ALLOCATE_PROMPT"},
75{ERR_FUNC(UI_F_GENERAL_ALLOCATE_STRING), "GENERAL_ALLOCATE_STRING"}, 75 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_STRING), "GENERAL_ALLOCATE_STRING"},
76{ERR_FUNC(UI_F_UI_CTRL), "UI_ctrl"}, 76 {ERR_FUNC(UI_F_UI_CTRL), "UI_ctrl"},
77{ERR_FUNC(UI_F_UI_DUP_ERROR_STRING), "UI_dup_error_string"}, 77 {ERR_FUNC(UI_F_UI_DUP_ERROR_STRING), "UI_dup_error_string"},
78{ERR_FUNC(UI_F_UI_DUP_INFO_STRING), "UI_dup_info_string"}, 78 {ERR_FUNC(UI_F_UI_DUP_INFO_STRING), "UI_dup_info_string"},
79{ERR_FUNC(UI_F_UI_DUP_INPUT_BOOLEAN), "UI_dup_input_boolean"}, 79 {ERR_FUNC(UI_F_UI_DUP_INPUT_BOOLEAN), "UI_dup_input_boolean"},
80{ERR_FUNC(UI_F_UI_DUP_INPUT_STRING), "UI_dup_input_string"}, 80 {ERR_FUNC(UI_F_UI_DUP_INPUT_STRING), "UI_dup_input_string"},
81{ERR_FUNC(UI_F_UI_DUP_VERIFY_STRING), "UI_dup_verify_string"}, 81 {ERR_FUNC(UI_F_UI_DUP_VERIFY_STRING), "UI_dup_verify_string"},
82{ERR_FUNC(UI_F_UI_GET0_RESULT), "UI_get0_result"}, 82 {ERR_FUNC(UI_F_UI_GET0_RESULT), "UI_get0_result"},
83{ERR_FUNC(UI_F_UI_NEW_METHOD), "UI_new_method"}, 83 {ERR_FUNC(UI_F_UI_NEW_METHOD), "UI_new_method"},
84{ERR_FUNC(UI_F_UI_SET_RESULT), "UI_set_result"}, 84 {ERR_FUNC(UI_F_UI_SET_RESULT), "UI_set_result"},
85{0,NULL} 85 {0, NULL}
86 }; 86};
87 87
88static ERR_STRING_DATA UI_str_reasons[]= 88static ERR_STRING_DATA UI_str_reasons[] =
89 { 89{
90{ERR_REASON(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS),"common ok and cancel characters"}, 90 {ERR_REASON(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS), "common ok and cancel characters"},
91{ERR_REASON(UI_R_INDEX_TOO_LARGE) ,"index too large"}, 91 {ERR_REASON(UI_R_INDEX_TOO_LARGE), "index too large"},
92{ERR_REASON(UI_R_INDEX_TOO_SMALL) ,"index too small"}, 92 {ERR_REASON(UI_R_INDEX_TOO_SMALL), "index too small"},
93{ERR_REASON(UI_R_NO_RESULT_BUFFER) ,"no result buffer"}, 93 {ERR_REASON(UI_R_NO_RESULT_BUFFER), "no result buffer"},
94{ERR_REASON(UI_R_RESULT_TOO_LARGE) ,"result too large"}, 94 {ERR_REASON(UI_R_RESULT_TOO_LARGE), "result too large"},
95{ERR_REASON(UI_R_RESULT_TOO_SMALL) ,"result too small"}, 95 {ERR_REASON(UI_R_RESULT_TOO_SMALL), "result too small"},
96{ERR_REASON(UI_R_UNKNOWN_CONTROL_COMMAND),"unknown control command"}, 96 {ERR_REASON(UI_R_UNKNOWN_CONTROL_COMMAND), "unknown control command"},
97{0,NULL} 97 {0, NULL}
98 }; 98};
99 99
100#endif 100#endif
101 101
102void ERR_load_UI_strings(void) 102void
103 { 103ERR_load_UI_strings(void)
104{
104#ifndef OPENSSL_NO_ERR 105#ifndef OPENSSL_NO_ERR
105 106
106 if (ERR_func_error_string(UI_str_functs[0].error) == NULL) 107 if (ERR_func_error_string(UI_str_functs[0].error) == NULL) {
107 { 108 ERR_load_strings(0, UI_str_functs);
108 ERR_load_strings(0,UI_str_functs); 109 ERR_load_strings(0, UI_str_reasons);
109 ERR_load_strings(0,UI_str_reasons);
110 }
111#endif
112 } 110 }
111#endif
112}
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c
index d3cadd51f6..32fb9d7dbb 100644
--- a/src/lib/libcrypto/ui/ui_lib.c
+++ b/src/lib/libcrypto/ui/ui_lib.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -65,359 +65,337 @@
65#include "ui_locl.h" 65#include "ui_locl.h"
66 66
67IMPLEMENT_STACK_OF(UI_STRING_ST) 67IMPLEMENT_STACK_OF(UI_STRING_ST)
68 static const UI_METHOD *default_UI_meth = NULL;
68 69
69static const UI_METHOD *default_UI_meth=NULL; 70 UI *UI_new(void)
71{
72 return (UI_new_method(NULL));
73}
70 74
71UI *UI_new(void) 75UI *
72 { 76UI_new_method(const UI_METHOD * method)
73 return(UI_new_method(NULL)); 77{
74 }
75
76UI *UI_new_method(const UI_METHOD *method)
77 {
78 UI *ret; 78 UI *ret;
79 79
80 ret=(UI *)malloc(sizeof(UI)); 80 ret = (UI *) malloc(sizeof(UI));
81 if (ret == NULL) 81 if (ret == NULL) {
82 { 82 UIerr(UI_F_UI_NEW_METHOD, ERR_R_MALLOC_FAILURE);
83 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE);
84 return NULL; 83 return NULL;
85 } 84 }
86 if (method == NULL) 85 if (method == NULL)
87 ret->meth=UI_get_default_method(); 86 ret->meth = UI_get_default_method();
88 else 87 else
89 ret->meth=method; 88 ret->meth = method;
90 89
91 ret->strings=NULL; 90 ret->strings = NULL;
92 ret->user_data=NULL; 91 ret->user_data = NULL;
93 ret->flags=0; 92 ret->flags = 0;
94 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data); 93 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data);
95 return ret; 94 return ret;
96 } 95}
97 96
98static void free_string(UI_STRING *uis) 97static void
99 { 98free_string(UI_STRING * uis)
100 if (uis->flags & OUT_STRING_FREEABLE) 99{
101 { 100 if (uis->flags & OUT_STRING_FREEABLE) {
102 free((char *)uis->out_string); 101 free((char *) uis->out_string);
103 switch(uis->type) 102 switch (uis->type) {
104 {
105 case UIT_BOOLEAN: 103 case UIT_BOOLEAN:
106 free((char *)uis->_.boolean_data.action_desc); 104 free((char *) uis->_.boolean_data.action_desc);
107 free((char *)uis->_.boolean_data.ok_chars); 105 free((char *) uis->_.boolean_data.ok_chars);
108 free((char *)uis->_.boolean_data.cancel_chars); 106 free((char *) uis->_.boolean_data.cancel_chars);
109 break; 107 break;
110 default: 108 default:
111 break; 109 break;
112 }
113 } 110 }
114 free(uis);
115 } 111 }
112 free(uis);
113}
116 114
117void UI_free(UI *ui) 115void
118 { 116UI_free(UI * ui)
117{
119 if (ui == NULL) 118 if (ui == NULL)
120 return; 119 return;
121 sk_UI_STRING_pop_free(ui->strings,free_string); 120 sk_UI_STRING_pop_free(ui->strings, free_string);
122 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data); 121 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
123 free(ui); 122 free(ui);
124 } 123}
125 124
126static int allocate_string_stack(UI *ui) 125static int
127 { 126allocate_string_stack(UI * ui)
128 if (ui->strings == NULL) 127{
129 { 128 if (ui->strings == NULL) {
130 ui->strings=sk_UI_STRING_new_null(); 129 ui->strings = sk_UI_STRING_new_null();
131 if (ui->strings == NULL) 130 if (ui->strings == NULL) {
132 {
133 return -1; 131 return -1;
134 }
135 } 132 }
136 return 0;
137 } 133 }
134 return 0;
135}
138 136
139static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt, 137static UI_STRING *
140 int prompt_freeable, enum UI_string_types type, int input_flags, 138general_allocate_prompt(UI * ui, const char *prompt,
141 char *result_buf) 139 int prompt_freeable, enum UI_string_types type, int input_flags,
142 { 140 char *result_buf)
141{
143 UI_STRING *ret = NULL; 142 UI_STRING *ret = NULL;
144 143
145 if (prompt == NULL) 144 if (prompt == NULL) {
146 { 145 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, ERR_R_PASSED_NULL_PARAMETER);
147 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER); 146 } else if ((type == UIT_PROMPT || type == UIT_VERIFY
148 } 147 || type == UIT_BOOLEAN) && result_buf == NULL) {
149 else if ((type == UIT_PROMPT || type == UIT_VERIFY 148 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, UI_R_NO_RESULT_BUFFER);
150 || type == UIT_BOOLEAN) && result_buf == NULL) 149 } else if ((ret = (UI_STRING *) malloc(sizeof(UI_STRING)))) {
151 { 150 ret->out_string = prompt;
152 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER); 151 ret->flags = prompt_freeable ? OUT_STRING_FREEABLE : 0;
153 } 152 ret->input_flags = input_flags;
154 else if ((ret = (UI_STRING *)malloc(sizeof(UI_STRING)))) 153 ret->type = type;
155 { 154 ret->result_buf = result_buf;
156 ret->out_string=prompt;
157 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0;
158 ret->input_flags=input_flags;
159 ret->type=type;
160 ret->result_buf=result_buf;
161 }
162 return ret;
163 } 155 }
156 return ret;
157}
164 158
165static int general_allocate_string(UI *ui, const char *prompt, 159static int
166 int prompt_freeable, enum UI_string_types type, int input_flags, 160general_allocate_string(UI * ui, const char *prompt,
167 char *result_buf, int minsize, int maxsize, const char *test_buf) 161 int prompt_freeable, enum UI_string_types type, int input_flags,
168 { 162 char *result_buf, int minsize, int maxsize, const char *test_buf)
163{
169 int ret = -1; 164 int ret = -1;
170 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable, 165 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
171 type, input_flags, result_buf); 166 type, input_flags, result_buf);
172 167
173 if (s) 168 if (s) {
174 { 169 if (allocate_string_stack(ui) >= 0) {
175 if (allocate_string_stack(ui) >= 0) 170 s->_.string_data.result_minsize = minsize;
176 { 171 s->_.string_data.result_maxsize = maxsize;
177 s->_.string_data.result_minsize=minsize; 172 s->_.string_data.test_buf = test_buf;
178 s->_.string_data.result_maxsize=maxsize; 173 ret = sk_UI_STRING_push(ui->strings, s);
179 s->_.string_data.test_buf=test_buf;
180 ret=sk_UI_STRING_push(ui->strings, s);
181 /* sk_push() returns 0 on error. Let's addapt that */ 174 /* sk_push() returns 0 on error. Let's addapt that */
182 if (ret <= 0) ret--; 175 if (ret <= 0)
183 } 176 ret--;
184 else 177 } else
185 free_string(s); 178 free_string(s);
186 }
187 return ret;
188 } 179 }
189 180 return ret;
190static int general_allocate_boolean(UI *ui, 181}
191 const char *prompt, const char *action_desc, 182
192 const char *ok_chars, const char *cancel_chars, 183static int
193 int prompt_freeable, enum UI_string_types type, int input_flags, 184general_allocate_boolean(UI * ui,
194 char *result_buf) 185 const char *prompt, const char *action_desc,
195 { 186 const char *ok_chars, const char *cancel_chars,
187 int prompt_freeable, enum UI_string_types type, int input_flags,
188 char *result_buf)
189{
196 int ret = -1; 190 int ret = -1;
197 UI_STRING *s; 191 UI_STRING *s;
198 const char *p; 192 const char *p;
199 193
200 if (ok_chars == NULL) 194 if (ok_chars == NULL) {
201 { 195 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, ERR_R_PASSED_NULL_PARAMETER);
202 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER); 196 } else if (cancel_chars == NULL) {
203 } 197 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, ERR_R_PASSED_NULL_PARAMETER);
204 else if (cancel_chars == NULL) 198 } else {
205 { 199 for (p = ok_chars; *p; p++) {
206 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER); 200 if (strchr(cancel_chars, *p)) {
207 }
208 else
209 {
210 for(p = ok_chars; *p; p++)
211 {
212 if (strchr(cancel_chars, *p))
213 {
214 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, 201 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,
215 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS); 202 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
216 }
217 } 203 }
204 }
218 205
219 s = general_allocate_prompt(ui, prompt, prompt_freeable, 206 s = general_allocate_prompt(ui, prompt, prompt_freeable,
220 type, input_flags, result_buf); 207 type, input_flags, result_buf);
221 208
222 if (s) 209 if (s) {
223 { 210 if (allocate_string_stack(ui) >= 0) {
224 if (allocate_string_stack(ui) >= 0)
225 {
226 s->_.boolean_data.action_desc = action_desc; 211 s->_.boolean_data.action_desc = action_desc;
227 s->_.boolean_data.ok_chars = ok_chars; 212 s->_.boolean_data.ok_chars = ok_chars;
228 s->_.boolean_data.cancel_chars = cancel_chars; 213 s->_.boolean_data.cancel_chars = cancel_chars;
229 ret=sk_UI_STRING_push(ui->strings, s); 214 ret = sk_UI_STRING_push(ui->strings, s);
230 /* sk_push() returns 0 on error. 215 /*
231 Let's addapt that */ 216 * sk_push() returns 0 on error. Let's addapt
232 if (ret <= 0) ret--; 217 * that
233 } 218 */
234 else 219 if (ret <= 0)
220 ret--;
221 } else
235 free_string(s); 222 free_string(s);
236 }
237 } 223 }
238 return ret;
239 } 224 }
225 return ret;
226}
240 227
241/* Returns the index to the place in the stack or -1 for error. Uses a 228/* Returns the index to the place in the stack or -1 for error. Uses a
242 direct reference to the prompt. */ 229 direct reference to the prompt. */
243int UI_add_input_string(UI *ui, const char *prompt, int flags, 230int
244 char *result_buf, int minsize, int maxsize) 231UI_add_input_string(UI * ui, const char *prompt, int flags,
245 { 232 char *result_buf, int minsize, int maxsize)
233{
246 return general_allocate_string(ui, prompt, 0, 234 return general_allocate_string(ui, prompt, 0,
247 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL); 235 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
248 } 236}
249 237
250/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */ 238/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
251int UI_dup_input_string(UI *ui, const char *prompt, int flags, 239int
252 char *result_buf, int minsize, int maxsize) 240UI_dup_input_string(UI * ui, const char *prompt, int flags,
253 { 241 char *result_buf, int minsize, int maxsize)
254 char *prompt_copy=NULL; 242{
243 char *prompt_copy = NULL;
255 244
256 if (prompt) 245 if (prompt) {
257 { 246 prompt_copy = BUF_strdup(prompt);
258 prompt_copy=BUF_strdup(prompt); 247 if (prompt_copy == NULL) {
259 if (prompt_copy == NULL) 248 UIerr(UI_F_UI_DUP_INPUT_STRING, ERR_R_MALLOC_FAILURE);
260 {
261 UIerr(UI_F_UI_DUP_INPUT_STRING,ERR_R_MALLOC_FAILURE);
262 return 0; 249 return 0;
263 }
264 } 250 }
265
266 return general_allocate_string(ui, prompt_copy, 1,
267 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
268 } 251 }
252 return general_allocate_string(ui, prompt_copy, 1,
253 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
254}
269 255
270int UI_add_verify_string(UI *ui, const char *prompt, int flags, 256int
271 char *result_buf, int minsize, int maxsize, const char *test_buf) 257UI_add_verify_string(UI * ui, const char *prompt, int flags,
272 { 258 char *result_buf, int minsize, int maxsize, const char *test_buf)
259{
273 return general_allocate_string(ui, prompt, 0, 260 return general_allocate_string(ui, prompt, 0,
274 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); 261 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
275 } 262}
276 263
277int UI_dup_verify_string(UI *ui, const char *prompt, int flags, 264int
278 char *result_buf, int minsize, int maxsize, const char *test_buf) 265UI_dup_verify_string(UI * ui, const char *prompt, int flags,
279 { 266 char *result_buf, int minsize, int maxsize, const char *test_buf)
280 char *prompt_copy=NULL; 267{
268 char *prompt_copy = NULL;
281 269
282 if (prompt) 270 if (prompt) {
283 { 271 prompt_copy = BUF_strdup(prompt);
284 prompt_copy=BUF_strdup(prompt); 272 if (prompt_copy == NULL) {
285 if (prompt_copy == NULL) 273 UIerr(UI_F_UI_DUP_VERIFY_STRING, ERR_R_MALLOC_FAILURE);
286 {
287 UIerr(UI_F_UI_DUP_VERIFY_STRING,ERR_R_MALLOC_FAILURE);
288 return -1; 274 return -1;
289 }
290 } 275 }
291
292 return general_allocate_string(ui, prompt_copy, 1,
293 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
294 } 276 }
295 277 return general_allocate_string(ui, prompt_copy, 1,
296int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, 278 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
297 const char *ok_chars, const char *cancel_chars, 279}
298 int flags, char *result_buf) 280
299 { 281int
282UI_add_input_boolean(UI * ui, const char *prompt, const char *action_desc,
283 const char *ok_chars, const char *cancel_chars,
284 int flags, char *result_buf)
285{
300 return general_allocate_boolean(ui, prompt, action_desc, 286 return general_allocate_boolean(ui, prompt, action_desc,
301 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf); 287 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
302 } 288}
303 289
304int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, 290int
305 const char *ok_chars, const char *cancel_chars, 291UI_dup_input_boolean(UI * ui, const char *prompt, const char *action_desc,
306 int flags, char *result_buf) 292 const char *ok_chars, const char *cancel_chars,
307 { 293 int flags, char *result_buf)
294{
308 char *prompt_copy = NULL; 295 char *prompt_copy = NULL;
309 char *action_desc_copy = NULL; 296 char *action_desc_copy = NULL;
310 char *ok_chars_copy = NULL; 297 char *ok_chars_copy = NULL;
311 char *cancel_chars_copy = NULL; 298 char *cancel_chars_copy = NULL;
312 299
313 if (prompt) 300 if (prompt) {
314 { 301 prompt_copy = BUF_strdup(prompt);
315 prompt_copy=BUF_strdup(prompt); 302 if (prompt_copy == NULL) {
316 if (prompt_copy == NULL) 303 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE);
317 {
318 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
319 goto err; 304 goto err;
320 }
321 } 305 }
322 306 }
323 if (action_desc) 307 if (action_desc) {
324 { 308 action_desc_copy = BUF_strdup(action_desc);
325 action_desc_copy=BUF_strdup(action_desc); 309 if (action_desc_copy == NULL) {
326 if (action_desc_copy == NULL) 310 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE);
327 {
328 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
329 goto err; 311 goto err;
330 }
331 } 312 }
332 313 }
333 if (ok_chars) 314 if (ok_chars) {
334 { 315 ok_chars_copy = BUF_strdup(ok_chars);
335 ok_chars_copy=BUF_strdup(ok_chars); 316 if (ok_chars_copy == NULL) {
336 if (ok_chars_copy == NULL) 317 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE);
337 {
338 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
339 goto err; 318 goto err;
340 }
341 } 319 }
342 320 }
343 if (cancel_chars) 321 if (cancel_chars) {
344 { 322 cancel_chars_copy = BUF_strdup(cancel_chars);
345 cancel_chars_copy=BUF_strdup(cancel_chars); 323 if (cancel_chars_copy == NULL) {
346 if (cancel_chars_copy == NULL) 324 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE);
347 {
348 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
349 goto err; 325 goto err;
350 }
351 } 326 }
352 327 }
353 return general_allocate_boolean(ui, prompt_copy, action_desc_copy, 328 return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
354 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags, 329 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
355 result_buf); 330 result_buf);
356 err: 331err:
357 if (prompt_copy) free(prompt_copy); 332 if (prompt_copy)
358 if (action_desc_copy) free(action_desc_copy); 333 free(prompt_copy);
359 if (ok_chars_copy) free(ok_chars_copy); 334 if (action_desc_copy)
360 if (cancel_chars_copy) free(cancel_chars_copy); 335 free(action_desc_copy);
336 if (ok_chars_copy)
337 free(ok_chars_copy);
338 if (cancel_chars_copy)
339 free(cancel_chars_copy);
361 return -1; 340 return -1;
362 } 341}
363 342
364int UI_add_info_string(UI *ui, const char *text) 343int
365 { 344UI_add_info_string(UI * ui, const char *text)
345{
366 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0, 346 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
367 NULL); 347 NULL);
368 } 348}
369 349
370int UI_dup_info_string(UI *ui, const char *text) 350int
371 { 351UI_dup_info_string(UI * ui, const char *text)
372 char *text_copy=NULL; 352{
373 353 char *text_copy = NULL;
374 if (text) 354
375 { 355 if (text) {
376 text_copy=BUF_strdup(text); 356 text_copy = BUF_strdup(text);
377 if (text_copy == NULL) 357 if (text_copy == NULL) {
378 { 358 UIerr(UI_F_UI_DUP_INFO_STRING, ERR_R_MALLOC_FAILURE);
379 UIerr(UI_F_UI_DUP_INFO_STRING,ERR_R_MALLOC_FAILURE);
380 return -1; 359 return -1;
381 }
382 } 360 }
383
384 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
385 0, 0, NULL);
386 } 361 }
362 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
363 0, 0, NULL);
364}
387 365
388int UI_add_error_string(UI *ui, const char *text) 366int
389 { 367UI_add_error_string(UI * ui, const char *text)
368{
390 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0, 369 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
391 NULL); 370 NULL);
392 } 371}
393 372
394int UI_dup_error_string(UI *ui, const char *text) 373int
395 { 374UI_dup_error_string(UI * ui, const char *text)
396 char *text_copy=NULL; 375{
397 376 char *text_copy = NULL;
398 if (text) 377
399 { 378 if (text) {
400 text_copy=BUF_strdup(text); 379 text_copy = BUF_strdup(text);
401 if (text_copy == NULL) 380 if (text_copy == NULL) {
402 { 381 UIerr(UI_F_UI_DUP_ERROR_STRING, ERR_R_MALLOC_FAILURE);
403 UIerr(UI_F_UI_DUP_ERROR_STRING,ERR_R_MALLOC_FAILURE);
404 return -1; 382 return -1;
405 }
406 } 383 }
407 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
408 0, 0, NULL);
409 } 384 }
385 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
386 0, 0, NULL);
387}
410 388
411char *UI_construct_prompt(UI *ui, const char *object_desc, 389char *
412 const char *object_name) 390UI_construct_prompt(UI * ui, const char *object_desc,
413 { 391 const char *object_name)
392{
414 char *prompt = NULL; 393 char *prompt = NULL;
415 394
416 if (ui->meth->ui_construct_prompt) 395 if (ui->meth->ui_construct_prompt)
417 prompt = ui->meth->ui_construct_prompt(ui, 396 prompt = ui->meth->ui_construct_prompt(ui,
418 object_desc, object_name); 397 object_desc, object_name);
419 else 398 else {
420 {
421 char prompt1[] = "Enter "; 399 char prompt1[] = "Enter ";
422 char prompt2[] = " for "; 400 char prompt2[] = " for ";
423 char prompt3[] = ":"; 401 char prompt3[] = ":";
@@ -430,48 +408,49 @@ char *UI_construct_prompt(UI *ui, const char *object_desc,
430 len += sizeof(prompt2) - 1 + strlen(object_name); 408 len += sizeof(prompt2) - 1 + strlen(object_name);
431 len += sizeof(prompt3) - 1; 409 len += sizeof(prompt3) - 1;
432 410
433 prompt = (char *)malloc(len + 1); 411 prompt = (char *) malloc(len + 1);
434 BUF_strlcpy(prompt, prompt1, len + 1); 412 BUF_strlcpy(prompt, prompt1, len + 1);
435 BUF_strlcat(prompt, object_desc, len + 1); 413 BUF_strlcat(prompt, object_desc, len + 1);
436 if (object_name) 414 if (object_name) {
437 {
438 BUF_strlcat(prompt, prompt2, len + 1); 415 BUF_strlcat(prompt, prompt2, len + 1);
439 BUF_strlcat(prompt, object_name, len + 1); 416 BUF_strlcat(prompt, object_name, len + 1);
440 }
441 BUF_strlcat(prompt, prompt3, len + 1);
442 } 417 }
443 return prompt; 418 BUF_strlcat(prompt, prompt3, len + 1);
444 } 419 }
420 return prompt;
421}
445 422
446void *UI_add_user_data(UI *ui, void *user_data) 423void *
447 { 424UI_add_user_data(UI * ui, void *user_data)
425{
448 void *old_data = ui->user_data; 426 void *old_data = ui->user_data;
449 ui->user_data = user_data; 427 ui->user_data = user_data;
450 return old_data; 428 return old_data;
451 } 429}
452 430
453void *UI_get0_user_data(UI *ui) 431void *
454 { 432UI_get0_user_data(UI * ui)
433{
455 return ui->user_data; 434 return ui->user_data;
456 } 435}
457 436
458const char *UI_get0_result(UI *ui, int i) 437const char *
459 { 438UI_get0_result(UI * ui, int i)
460 if (i < 0) 439{
461 { 440 if (i < 0) {
462 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL); 441 UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_SMALL);
463 return NULL; 442 return NULL;
464 } 443 }
465 if (i >= sk_UI_STRING_num(ui->strings)) 444 if (i >= sk_UI_STRING_num(ui->strings)) {
466 { 445 UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_LARGE);
467 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE);
468 return NULL; 446 return NULL;
469 }
470 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
471 } 447 }
448 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
449}
472 450
473static int print_error(const char *str, size_t len, UI *ui) 451static int
474 { 452print_error(const char *str, size_t len, UI * ui)
453{
475 UI_STRING uis; 454 UI_STRING uis;
476 455
477 memset(&uis, 0, sizeof(uis)); 456 memset(&uis, 0, sizeof(uis));
@@ -479,446 +458,441 @@ static int print_error(const char *str, size_t len, UI *ui)
479 uis.out_string = str; 458 uis.out_string = str;
480 459
481 if (ui->meth->ui_write_string 460 if (ui->meth->ui_write_string
482 && !ui->meth->ui_write_string(ui, &uis)) 461 && !ui->meth->ui_write_string(ui, &uis))
483 return -1; 462 return -1;
484 return 0; 463 return 0;
485 } 464}
486 465
487int UI_process(UI *ui) 466int
488 { 467UI_process(UI * ui)
489 int i, ok=0; 468{
469 int i, ok = 0;
490 470
491 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui)) 471 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui))
492 return -1; 472 return -1;
493 473
494 if (ui->flags & UI_FLAG_PRINT_ERRORS) 474 if (ui->flags & UI_FLAG_PRINT_ERRORS)
495 ERR_print_errors_cb( 475 ERR_print_errors_cb(
496 (int (*)(const char *, size_t, void *))print_error, 476 (int (*) (const char *, size_t, void *)) print_error,
497 (void *)ui); 477 (void *) ui);
498 478
499 for(i=0; i<sk_UI_STRING_num(ui->strings); i++) 479 for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
500 {
501 if (ui->meth->ui_write_string 480 if (ui->meth->ui_write_string
502 && !ui->meth->ui_write_string(ui, 481 && !ui->meth->ui_write_string(ui,
503 sk_UI_STRING_value(ui->strings, i))) 482 sk_UI_STRING_value(ui->strings, i))) {
504 { 483 ok = -1;
505 ok=-1;
506 goto err; 484 goto err;
507 }
508 } 485 }
486 }
509 487
510 if (ui->meth->ui_flush) 488 if (ui->meth->ui_flush)
511 switch(ui->meth->ui_flush(ui)) 489 switch (ui->meth->ui_flush(ui)) {
512 { 490 case -1: /* Interrupt/Cancel/something... */
513 case -1: /* Interrupt/Cancel/something... */
514 ok = -2; 491 ok = -2;
515 goto err; 492 goto err;
516 case 0: /* Errors */ 493 case 0: /* Errors */
517 ok = -1; 494 ok = -1;
518 goto err; 495 goto err;
519 default: /* Success */ 496 default: /* Success */
520 ok = 0; 497 ok = 0;
521 break; 498 break;
522 } 499 }
523 500
524 for(i=0; i<sk_UI_STRING_num(ui->strings); i++) 501 for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
525 { 502 if (ui->meth->ui_read_string) {
526 if (ui->meth->ui_read_string) 503 switch (ui->meth->ui_read_string(ui,
527 { 504 sk_UI_STRING_value(ui->strings, i))) {
528 switch(ui->meth->ui_read_string(ui, 505 case -1: /* Interrupt/Cancel/something... */
529 sk_UI_STRING_value(ui->strings, i)))
530 {
531 case -1: /* Interrupt/Cancel/something... */
532 ok = -2; 506 ok = -2;
533 goto err; 507 goto err;
534 case 0: /* Errors */ 508 case 0:/* Errors */
535 ok = -1; 509 ok = -1;
536 goto err; 510 goto err;
537 default: /* Success */ 511 default: /* Success */
538 ok = 0; 512 ok = 0;
539 break; 513 break;
540 }
541 } 514 }
542 } 515 }
543 err: 516 }
517err:
544 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui)) 518 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui))
545 return -1; 519 return -1;
546 return ok; 520 return ok;
547 } 521}
548 522
549int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)) 523int
550 { 524UI_ctrl(UI * ui, int cmd, long i, void *p, void (*f) (void))
551 if (ui == NULL) 525{
552 { 526 if (ui == NULL) {
553 UIerr(UI_F_UI_CTRL,ERR_R_PASSED_NULL_PARAMETER); 527 UIerr(UI_F_UI_CTRL, ERR_R_PASSED_NULL_PARAMETER);
554 return -1; 528 return -1;
555 } 529 }
556 switch(cmd) 530 switch (cmd) {
557 {
558 case UI_CTRL_PRINT_ERRORS: 531 case UI_CTRL_PRINT_ERRORS:
559 { 532 {
560 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS); 533 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS);
561 if (i) 534 if (i)
562 ui->flags |= UI_FLAG_PRINT_ERRORS; 535 ui->flags |= UI_FLAG_PRINT_ERRORS;
563 else 536 else
564 ui->flags &= ~UI_FLAG_PRINT_ERRORS; 537 ui->flags &= ~UI_FLAG_PRINT_ERRORS;
565 return save_flag; 538 return save_flag;
566 } 539 }
567 case UI_CTRL_IS_REDOABLE: 540 case UI_CTRL_IS_REDOABLE:
568 return !!(ui->flags & UI_FLAG_REDOABLE); 541 return !!(ui->flags & UI_FLAG_REDOABLE);
569 default: 542 default:
570 break; 543 break;
571 }
572 UIerr(UI_F_UI_CTRL,UI_R_UNKNOWN_CONTROL_COMMAND);
573 return -1;
574 } 544 }
545 UIerr(UI_F_UI_CTRL, UI_R_UNKNOWN_CONTROL_COMMAND);
546 return -1;
547}
575 548
576int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 549int
577 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) 550UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new * new_func,
578 { 551 CRYPTO_EX_dup * dup_func, CRYPTO_EX_free * free_func)
552{
579 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp, 553 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
580 new_func, dup_func, free_func); 554 new_func, dup_func, free_func);
581 } 555}
582 556
583int UI_set_ex_data(UI *r, int idx, void *arg) 557int
584 { 558UI_set_ex_data(UI * r, int idx, void *arg)
585 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); 559{
586 } 560 return (CRYPTO_set_ex_data(&r->ex_data, idx, arg));
587 561}
588void *UI_get_ex_data(UI *r, int idx) 562
589 { 563void *
590 return(CRYPTO_get_ex_data(&r->ex_data,idx)); 564UI_get_ex_data(UI * r, int idx)
591 } 565{
592 566 return (CRYPTO_get_ex_data(&r->ex_data, idx));
593void UI_set_default_method(const UI_METHOD *meth) 567}
594 { 568
595 default_UI_meth=meth; 569void
570UI_set_default_method(const UI_METHOD * meth)
571{
572 default_UI_meth = meth;
573}
574
575const UI_METHOD *
576UI_get_default_method(void)
577{
578 if (default_UI_meth == NULL) {
579 default_UI_meth = UI_OpenSSL();
596 } 580 }
597
598const UI_METHOD *UI_get_default_method(void)
599 {
600 if (default_UI_meth == NULL)
601 {
602 default_UI_meth=UI_OpenSSL();
603 }
604 return default_UI_meth; 581 return default_UI_meth;
605 } 582}
606 583
607const UI_METHOD *UI_get_method(UI *ui) 584const UI_METHOD *
608 { 585UI_get_method(UI * ui)
586{
609 return ui->meth; 587 return ui->meth;
610 } 588}
611 589
612const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth) 590const UI_METHOD *
613 { 591UI_set_method(UI * ui, const UI_METHOD * meth)
614 ui->meth=meth; 592{
593 ui->meth = meth;
615 return ui->meth; 594 return ui->meth;
616 } 595}
617 596
618 597
619UI_METHOD *UI_create_method(char *name) 598UI_METHOD *
620 { 599UI_create_method(char *name)
621 UI_METHOD *ui_method = (UI_METHOD *)malloc(sizeof(UI_METHOD)); 600{
601 UI_METHOD *ui_method = (UI_METHOD *) malloc(sizeof(UI_METHOD));
622 602
623 if (ui_method) 603 if (ui_method) {
624 {
625 memset(ui_method, 0, sizeof(*ui_method)); 604 memset(ui_method, 0, sizeof(*ui_method));
626 ui_method->name = BUF_strdup(name); 605 ui_method->name = BUF_strdup(name);
627 }
628 return ui_method;
629 } 606 }
607 return ui_method;
608}
630 609
631/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method 610/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
632 (that is, it hasn't been allocated using UI_create_method(), you deserve 611 (that is, it hasn't been allocated using UI_create_method(), you deserve
633 anything Murphy can throw at you and more! You have been warned. */ 612 anything Murphy can throw at you and more! You have been warned. */
634void UI_destroy_method(UI_METHOD *ui_method) 613void
635 { 614UI_destroy_method(UI_METHOD * ui_method)
615{
636 free(ui_method->name); 616 free(ui_method->name);
637 ui_method->name = NULL; 617 ui_method->name = NULL;
638 free(ui_method); 618 free(ui_method);
639 } 619}
640 620
641int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) 621int
642 { 622UI_method_set_opener(UI_METHOD * method, int (*opener) (UI * ui))
643 if (method) 623{
644 { 624 if (method) {
645 method->ui_open_session = opener; 625 method->ui_open_session = opener;
646 return 0; 626 return 0;
647 } 627 } else
648 else
649 return -1; 628 return -1;
650 } 629}
651 630
652int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)) 631int
653 { 632UI_method_set_writer(UI_METHOD * method, int (*writer) (UI * ui, UI_STRING * uis))
654 if (method) 633{
655 { 634 if (method) {
656 method->ui_write_string = writer; 635 method->ui_write_string = writer;
657 return 0; 636 return 0;
658 } 637 } else
659 else
660 return -1; 638 return -1;
661 } 639}
662 640
663int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)) 641int
664 { 642UI_method_set_flusher(UI_METHOD * method, int (*flusher) (UI * ui))
665 if (method) 643{
666 { 644 if (method) {
667 method->ui_flush = flusher; 645 method->ui_flush = flusher;
668 return 0; 646 return 0;
669 } 647 } else
670 else
671 return -1; 648 return -1;
672 } 649}
673 650
674int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)) 651int
675 { 652UI_method_set_reader(UI_METHOD * method, int (*reader) (UI * ui, UI_STRING * uis))
676 if (method) 653{
677 { 654 if (method) {
678 method->ui_read_string = reader; 655 method->ui_read_string = reader;
679 return 0; 656 return 0;
680 } 657 } else
681 else
682 return -1; 658 return -1;
683 } 659}
684 660
685int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)) 661int
686 { 662UI_method_set_closer(UI_METHOD * method, int (*closer) (UI * ui))
687 if (method) 663{
688 { 664 if (method) {
689 method->ui_close_session = closer; 665 method->ui_close_session = closer;
690 return 0; 666 return 0;
691 } 667 } else
692 else
693 return -1; 668 return -1;
694 } 669}
695 670
696int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name)) 671int
697 { 672UI_method_set_prompt_constructor(UI_METHOD * method, char *(*prompt_constructor) (UI * ui, const char *object_desc, const char *object_name))
698 if (method) 673{
699 { 674 if (method) {
700 method->ui_construct_prompt = prompt_constructor; 675 method->ui_construct_prompt = prompt_constructor;
701 return 0; 676 return 0;
702 } 677 } else
703 else
704 return -1; 678 return -1;
705 } 679}
706 680
707int (*UI_method_get_opener(UI_METHOD *method))(UI*) 681int (*
708 { 682 UI_method_get_opener(UI_METHOD * method)) (UI *)
683{
709 if (method) 684 if (method)
710 return method->ui_open_session; 685 return method->ui_open_session;
711 else 686 else
712 return NULL; 687 return NULL;
713 } 688}
714 689
715int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*) 690int (*
716 { 691 UI_method_get_writer(UI_METHOD * method)) (UI *, UI_STRING *)
692{
717 if (method) 693 if (method)
718 return method->ui_write_string; 694 return method->ui_write_string;
719 else 695 else
720 return NULL; 696 return NULL;
721 } 697}
722 698
723int (*UI_method_get_flusher(UI_METHOD *method))(UI*) 699int (*
724 { 700 UI_method_get_flusher(UI_METHOD * method)) (UI *)
701{
725 if (method) 702 if (method)
726 return method->ui_flush; 703 return method->ui_flush;
727 else 704 else
728 return NULL; 705 return NULL;
729 } 706}
730 707
731int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*) 708int (*
732 { 709 UI_method_get_reader(UI_METHOD * method)) (UI *, UI_STRING *)
710{
733 if (method) 711 if (method)
734 return method->ui_read_string; 712 return method->ui_read_string;
735 else 713 else
736 return NULL; 714 return NULL;
737 } 715}
738 716
739int (*UI_method_get_closer(UI_METHOD *method))(UI*) 717int (*
740 { 718 UI_method_get_closer(UI_METHOD * method)) (UI *)
719{
741 if (method) 720 if (method)
742 return method->ui_close_session; 721 return method->ui_close_session;
743 else 722 else
744 return NULL; 723 return NULL;
745 } 724}
746 725
747char* (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, const char*) 726char *(*
748 { 727 UI_method_get_prompt_constructor(UI_METHOD * method)) (UI *, const char *, const char *)
728{
749 if (method) 729 if (method)
750 return method->ui_construct_prompt; 730 return method->ui_construct_prompt;
751 else 731 else
752 return NULL; 732 return NULL;
753 } 733}
754 734
755enum UI_string_types UI_get_string_type(UI_STRING *uis) 735enum UI_string_types
756 { 736UI_get_string_type(UI_STRING * uis)
737{
757 if (!uis) 738 if (!uis)
758 return UIT_NONE; 739 return UIT_NONE;
759 return uis->type; 740 return uis->type;
760 } 741}
761 742
762int UI_get_input_flags(UI_STRING *uis) 743int
763 { 744UI_get_input_flags(UI_STRING * uis)
745{
764 if (!uis) 746 if (!uis)
765 return 0; 747 return 0;
766 return uis->input_flags; 748 return uis->input_flags;
767 } 749}
768 750
769const char *UI_get0_output_string(UI_STRING *uis) 751const char *
770 { 752UI_get0_output_string(UI_STRING * uis)
753{
771 if (!uis) 754 if (!uis)
772 return NULL; 755 return NULL;
773 return uis->out_string; 756 return uis->out_string;
774 } 757}
775 758
776const char *UI_get0_action_string(UI_STRING *uis) 759const char *
777 { 760UI_get0_action_string(UI_STRING * uis)
761{
778 if (!uis) 762 if (!uis)
779 return NULL; 763 return NULL;
780 switch(uis->type) 764 switch (uis->type) {
781 {
782 case UIT_PROMPT: 765 case UIT_PROMPT:
783 case UIT_BOOLEAN: 766 case UIT_BOOLEAN:
784 return uis->_.boolean_data.action_desc; 767 return uis->_.boolean_data.action_desc;
785 default: 768 default:
786 return NULL; 769 return NULL;
787 }
788 } 770 }
771}
789 772
790const char *UI_get0_result_string(UI_STRING *uis) 773const char *
791 { 774UI_get0_result_string(UI_STRING * uis)
775{
792 if (!uis) 776 if (!uis)
793 return NULL; 777 return NULL;
794 switch(uis->type) 778 switch (uis->type) {
795 {
796 case UIT_PROMPT: 779 case UIT_PROMPT:
797 case UIT_VERIFY: 780 case UIT_VERIFY:
798 return uis->result_buf; 781 return uis->result_buf;
799 default: 782 default:
800 return NULL; 783 return NULL;
801 }
802 } 784 }
785}
803 786
804const char *UI_get0_test_string(UI_STRING *uis) 787const char *
805 { 788UI_get0_test_string(UI_STRING * uis)
789{
806 if (!uis) 790 if (!uis)
807 return NULL; 791 return NULL;
808 switch(uis->type) 792 switch (uis->type) {
809 {
810 case UIT_VERIFY: 793 case UIT_VERIFY:
811 return uis->_.string_data.test_buf; 794 return uis->_.string_data.test_buf;
812 default: 795 default:
813 return NULL; 796 return NULL;
814 }
815 } 797 }
798}
816 799
817int UI_get_result_minsize(UI_STRING *uis) 800int
818 { 801UI_get_result_minsize(UI_STRING * uis)
802{
819 if (!uis) 803 if (!uis)
820 return -1; 804 return -1;
821 switch(uis->type) 805 switch (uis->type) {
822 {
823 case UIT_PROMPT: 806 case UIT_PROMPT:
824 case UIT_VERIFY: 807 case UIT_VERIFY:
825 return uis->_.string_data.result_minsize; 808 return uis->_.string_data.result_minsize;
826 default: 809 default:
827 return -1; 810 return -1;
828 }
829 } 811 }
812}
830 813
831int UI_get_result_maxsize(UI_STRING *uis) 814int
832 { 815UI_get_result_maxsize(UI_STRING * uis)
816{
833 if (!uis) 817 if (!uis)
834 return -1; 818 return -1;
835 switch(uis->type) 819 switch (uis->type) {
836 {
837 case UIT_PROMPT: 820 case UIT_PROMPT:
838 case UIT_VERIFY: 821 case UIT_VERIFY:
839 return uis->_.string_data.result_maxsize; 822 return uis->_.string_data.result_maxsize;
840 default: 823 default:
841 return -1; 824 return -1;
842 }
843 } 825 }
826}
844 827
845int UI_set_result(UI *ui, UI_STRING *uis, const char *result) 828int
846 { 829UI_set_result(UI * ui, UI_STRING * uis, const char *result)
830{
847 int l = strlen(result); 831 int l = strlen(result);
848 832
849 ui->flags &= ~UI_FLAG_REDOABLE; 833 ui->flags &= ~UI_FLAG_REDOABLE;
850 834
851 if (!uis) 835 if (!uis)
852 return -1; 836 return -1;
853 switch (uis->type) 837 switch (uis->type) {
854 {
855 case UIT_PROMPT: 838 case UIT_PROMPT:
856 case UIT_VERIFY: 839 case UIT_VERIFY:
857 { 840 {
858 char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize)+1]; 841 char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize) + 1];
859 char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize)+1]; 842 char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize) + 1];
860 843
861 (void) snprintf(number1, sizeof(number1), "%d", 844 (void) snprintf(number1, sizeof(number1), "%d",
862 uis->_.string_data.result_minsize); 845 uis->_.string_data.result_minsize);
863 (void) snprintf(number2, sizeof(number2), "%d", 846 (void) snprintf(number2, sizeof(number2), "%d",
864 uis->_.string_data.result_maxsize); 847 uis->_.string_data.result_maxsize);
865 848
866 if (l < uis->_.string_data.result_minsize) 849 if (l < uis->_.string_data.result_minsize) {
867 { 850 ui->flags |= UI_FLAG_REDOABLE;
868 ui->flags |= UI_FLAG_REDOABLE; 851 UIerr(UI_F_UI_SET_RESULT, UI_R_RESULT_TOO_SMALL);
869 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_SMALL); 852 ERR_add_error_data(5, "You must type in ",
870 ERR_add_error_data(5,"You must type in ", 853 number1, " to ", number2, " characters");
871 number1," to ",number2," characters"); 854 return -1;
872 return -1;
873 } 855 }
874 if (l > uis->_.string_data.result_maxsize) 856 if (l > uis->_.string_data.result_maxsize) {
875 { 857 ui->flags |= UI_FLAG_REDOABLE;
876 ui->flags |= UI_FLAG_REDOABLE; 858 UIerr(UI_F_UI_SET_RESULT, UI_R_RESULT_TOO_LARGE);
877 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_LARGE); 859 ERR_add_error_data(5, "You must type in ",
878 ERR_add_error_data(5,"You must type in ", 860 number1, " to ", number2, " characters");
879 number1," to ",number2," characters"); 861 return -1;
880 return -1;
881 } 862 }
882 } 863 }
883 864
884 if (!uis->result_buf) 865 if (!uis->result_buf) {
885 { 866 UIerr(UI_F_UI_SET_RESULT, UI_R_NO_RESULT_BUFFER);
886 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
887 return -1; 867 return -1;
888 } 868 }
889
890 BUF_strlcpy(uis->result_buf, result, 869 BUF_strlcpy(uis->result_buf, result,
891 uis->_.string_data.result_maxsize + 1); 870 uis->_.string_data.result_maxsize + 1);
892 break; 871 break;
893 case UIT_BOOLEAN: 872 case UIT_BOOLEAN:
894 { 873 {
895 const char *p; 874 const char *p;
896 875
897 if (!uis->result_buf) 876 if (!uis->result_buf) {
898 { 877 UIerr(UI_F_UI_SET_RESULT, UI_R_NO_RESULT_BUFFER);
899 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER); 878 return -1;
900 return -1;
901 } 879 }
902 880 uis->result_buf[0] = '\0';
903 uis->result_buf[0] = '\0'; 881 for (p = result; *p; p++) {
904 for(p = result; *p; p++) 882 if (strchr(uis->_.boolean_data.ok_chars, *p)) {
905 { 883 uis->result_buf[0] =
906 if (strchr(uis->_.boolean_data.ok_chars, *p)) 884 uis->_.boolean_data.ok_chars[0];
907 { 885 break;
908 uis->result_buf[0] =
909 uis->_.boolean_data.ok_chars[0];
910 break;
911 } 886 }
912 if (strchr(uis->_.boolean_data.cancel_chars, *p)) 887 if (strchr(uis->_.boolean_data.cancel_chars, *p)) {
913 { 888 uis->result_buf[0] =
914 uis->result_buf[0] = 889 uis->_.boolean_data.cancel_chars[0];
915 uis->_.boolean_data.cancel_chars[0]; 890 break;
916 break;
917 } 891 }
918 } 892 }
919 default: 893 default:
920 break; 894 break;
921 }
922 } 895 }
923 return 0;
924 } 896 }
897 return 0;
898}
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c
index 6000c24b1c..94a999baa8 100644
--- a/src/lib/libcrypto/ui/ui_openssl.c
+++ b/src/lib/libcrypto/ui/ui_openssl.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -63,21 +63,21 @@
63 * This package is an SSL implementation written 63 * This package is an SSL implementation written
64 * by Eric Young (eay@cryptsoft.com). 64 * by Eric Young (eay@cryptsoft.com).
65 * The implementation was written so as to conform with Netscapes SSL. 65 * The implementation was written so as to conform with Netscapes SSL.
66 * 66 *
67 * This library is free for commercial and non-commercial use as long as 67 * This library is free for commercial and non-commercial use as long as
68 * the following conditions are aheared to. The following conditions 68 * the following conditions are aheared to. The following conditions
69 * apply to all code found in this distribution, be it the RC4, RSA, 69 * apply to all code found in this distribution, be it the RC4, RSA,
70 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 70 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
71 * included with this distribution is covered by the same copyright terms 71 * included with this distribution is covered by the same copyright terms
72 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 72 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
73 * 73 *
74 * Copyright remains Eric Young's, and as such any Copyright notices in 74 * Copyright remains Eric Young's, and as such any Copyright notices in
75 * the code are not to be removed. 75 * the code are not to be removed.
76 * If this package is used in a product, Eric Young should be given attribution 76 * If this package is used in a product, Eric Young should be given attribution
77 * as the author of the parts of the library used. 77 * as the author of the parts of the library used.
78 * This can be in the form of a textual message at program startup or 78 * This can be in the form of a textual message at program startup or
79 * in documentation (online or textual) provided with the package. 79 * in documentation (online or textual) provided with the package.
80 * 80 *
81 * Redistribution and use in source and binary forms, with or without 81 * Redistribution and use in source and binary forms, with or without
82 * modification, are permitted provided that the following conditions 82 * modification, are permitted provided that the following conditions
83 * are met: 83 * are met:
@@ -92,10 +92,10 @@
92 * Eric Young (eay@cryptsoft.com)" 92 * Eric Young (eay@cryptsoft.com)"
93 * The word 'cryptographic' can be left out if the rouines from the library 93 * The word 'cryptographic' can be left out if the rouines from the library
94 * being used are not cryptographic related :-). 94 * being used are not cryptographic related :-).
95 * 4. If you include any Windows specific code (or a derivative thereof) from 95 * 4. If you include any Windows specific code (or a derivative thereof) from
96 * the apps directory (application code) you must include an acknowledgement: 96 * the apps directory (application code) you must include an acknowledgement:
97 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 97 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
98 * 98 *
99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -107,7 +107,7 @@
107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
109 * SUCH DAMAGE. 109 * SUCH DAMAGE.
110 * 110 *
111 * The licence and distribution terms for any publically available version or 111 * The licence and distribution terms for any publically available version or
112 * derivative of this code cannot be changed. i.e. this code cannot simply be 112 * derivative of this code cannot be changed. i.e. this code cannot simply be
113 * copied and put under another distribution licence 113 * copied and put under another distribution licence
@@ -125,14 +125,14 @@
125#include <unistd.h> 125#include <unistd.h>
126/* If unistd.h defines _POSIX_VERSION, we conclude that we 126/* If unistd.h defines _POSIX_VERSION, we conclude that we
127 * are on a POSIX system and have sigaction and termios. */ 127 * are on a POSIX system and have sigaction and termios. */
128# if defined(_POSIX_VERSION) 128#if defined(_POSIX_VERSION)
129 129
130# define SIGACTION 130#define SIGACTION
131# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY) 131#if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
132# define TERMIOS 132#define TERMIOS
133# endif 133#endif
134 134
135# endif 135#endif
136 136
137#include "ui_locl.h" 137#include "ui_locl.h"
138#include "cryptlib.h" 138#include "cryptlib.h"
@@ -143,31 +143,31 @@
143 */ 143 */
144 144
145#ifdef _LIBC 145#ifdef _LIBC
146# undef TERMIOS 146#undef TERMIOS
147# define TERMIO 147#define TERMIO
148# undef SGTTY 148#undef SGTTY
149#endif 149#endif
150 150
151#ifdef TERMIOS 151#ifdef TERMIOS
152# include <termios.h> 152#include <termios.h>
153# define TTY_STRUCT struct termios 153#define TTY_STRUCT struct termios
154# define TTY_FLAGS c_lflag 154#define TTY_FLAGS c_lflag
155# define TTY_get(tty,data) tcgetattr(tty,data) 155#define TTY_get(tty,data) tcgetattr(tty,data)
156# define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data) 156#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
157#endif 157#endif
158 158
159#ifdef TERMIO 159#ifdef TERMIO
160# include <termio.h> 160#include <termio.h>
161# define TTY_STRUCT struct termio 161#define TTY_STRUCT struct termio
162# define TTY_FLAGS c_lflag 162#define TTY_FLAGS c_lflag
163# define TTY_get(tty,data) ioctl(tty,TCGETA,data) 163#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
164# define TTY_set(tty,data) ioctl(tty,TCSETA,data) 164#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
165#endif 165#endif
166 166
167# include <sys/ioctl.h> 167#include <sys/ioctl.h>
168 168
169#ifndef NX509_SIG 169#ifndef NX509_SIG
170# define NX509_SIG 32 170#define NX509_SIG 32
171#endif 171#endif
172 172
173 173
@@ -175,10 +175,10 @@
175#ifdef SIGACTION 175#ifdef SIGACTION
176static struct sigaction savsig[NX509_SIG]; 176static struct sigaction savsig[NX509_SIG];
177#else 177#else
178static void (*savsig[NX509_SIG])(int ); 178static void (*savsig[NX509_SIG]) (int);
179#endif 179#endif
180 180
181static TTY_STRUCT tty_orig,tty_new; 181static TTY_STRUCT tty_orig, tty_new;
182static FILE *tty_in, *tty_out; 182static FILE *tty_in, *tty_out;
183static int is_a_tty; 183static int is_a_tty;
184 184
@@ -187,18 +187,18 @@ static int read_till_nl(FILE *);
187static void recsig(int); 187static void recsig(int);
188static void pushsig(void); 188static void pushsig(void);
189static void popsig(void); 189static void popsig(void);
190static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl); 190static int read_string_inner(UI * ui, UI_STRING * uis, int echo, int strip_nl);
191 191
192static int read_string(UI *ui, UI_STRING *uis); 192static int read_string(UI * ui, UI_STRING * uis);
193static int write_string(UI *ui, UI_STRING *uis); 193static int write_string(UI * ui, UI_STRING * uis);
194 194
195static int open_console(UI *ui); 195static int open_console(UI * ui);
196static int echo_console(UI *ui); 196static int echo_console(UI * ui);
197static int noecho_console(UI *ui); 197static int noecho_console(UI * ui);
198static int close_console(UI *ui); 198static int close_console(UI * ui);
199 199
200static UI_METHOD ui_openssl = 200static UI_METHOD ui_openssl =
201 { 201{
202 "OpenSSL default user interface", 202 "OpenSSL default user interface",
203 open_console, 203 open_console,
204 write_string, 204 write_string,
@@ -206,216 +206,226 @@ static UI_METHOD ui_openssl =
206 read_string, 206 read_string,
207 close_console, 207 close_console,
208 NULL 208 NULL
209 }; 209};
210 210
211/* The method with all the built-in thingies */ 211/* The method with all the built-in thingies */
212UI_METHOD *UI_OpenSSL(void) 212UI_METHOD *
213 { 213UI_OpenSSL(void)
214{
214 return &ui_openssl; 215 return &ui_openssl;
215 } 216}
216 217
217/* The following function makes sure that info and error strings are printed 218/* The following function makes sure that info and error strings are printed
218 before any prompt. */ 219 before any prompt. */
219static int write_string(UI *ui, UI_STRING *uis) 220static int
220 { 221write_string(UI * ui, UI_STRING * uis)
221 switch (UI_get_string_type(uis)) 222{
222 { 223 switch (UI_get_string_type(uis)) {
223 case UIT_ERROR: 224 case UIT_ERROR:
224 case UIT_INFO: 225 case UIT_INFO:
225 fputs(UI_get0_output_string(uis), tty_out); 226 fputs(UI_get0_output_string(uis), tty_out);
226 fflush(tty_out); 227 fflush(tty_out);
227 break; 228 break;
228 default: 229 default:
229 break; 230 break;
230 }
231 return 1;
232 } 231 }
232 return 1;
233}
233 234
234static int read_string(UI *ui, UI_STRING *uis) 235static int
235 { 236read_string(UI * ui, UI_STRING * uis)
237{
236 int ok = 0; 238 int ok = 0;
237 239
238 switch (UI_get_string_type(uis)) 240 switch (UI_get_string_type(uis)) {
239 {
240 case UIT_BOOLEAN: 241 case UIT_BOOLEAN:
241 fputs(UI_get0_output_string(uis), tty_out); 242 fputs(UI_get0_output_string(uis), tty_out);
242 fputs(UI_get0_action_string(uis), tty_out); 243 fputs(UI_get0_action_string(uis), tty_out);
243 fflush(tty_out); 244 fflush(tty_out);
244 return read_string_inner(ui, uis, 245 return read_string_inner(ui, uis,
245 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0); 246 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
246 case UIT_PROMPT: 247 case UIT_PROMPT:
247 fputs(UI_get0_output_string(uis), tty_out); 248 fputs(UI_get0_output_string(uis), tty_out);
248 fflush(tty_out); 249 fflush(tty_out);
249 return read_string_inner(ui, uis, 250 return read_string_inner(ui, uis,
250 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1); 251 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
251 case UIT_VERIFY: 252 case UIT_VERIFY:
252 fprintf(tty_out,"Verifying - %s", 253 fprintf(tty_out, "Verifying - %s",
253 UI_get0_output_string(uis)); 254 UI_get0_output_string(uis));
254 fflush(tty_out); 255 fflush(tty_out);
255 if ((ok = read_string_inner(ui, uis, 256 if ((ok = read_string_inner(ui, uis,
256 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0) 257 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
257 return ok; 258 return ok;
258 if (strcmp(UI_get0_result_string(uis), 259 if (strcmp(UI_get0_result_string(uis),
259 UI_get0_test_string(uis)) != 0) 260 UI_get0_test_string(uis)) != 0) {
260 { 261 fprintf(tty_out, "Verify failure\n");
261 fprintf(tty_out,"Verify failure\n");
262 fflush(tty_out); 262 fflush(tty_out);
263 return 0; 263 return 0;
264 } 264 }
265 break; 265 break;
266 default: 266 default:
267 break; 267 break;
268 }
269 return 1;
270 } 268 }
269 return 1;
270}
271 271
272 272
273/* Internal functions to read a string without echoing */ 273/* Internal functions to read a string without echoing */
274static int read_till_nl(FILE *in) 274static int
275 { 275read_till_nl(FILE * in)
276{
276#define SIZE 4 277#define SIZE 4
277 char buf[SIZE+1]; 278 char buf[SIZE + 1];
278 279
279 do { 280 do {
280 if (!fgets(buf,SIZE,in)) 281 if (!fgets(buf, SIZE, in))
281 return 0; 282 return 0;
282 } while (strchr(buf,'\n') == NULL); 283 } while (strchr(buf, '\n') == NULL);
283 return 1; 284 return 1;
284 } 285}
285 286
286static volatile sig_atomic_t intr_signal; 287static volatile sig_atomic_t intr_signal;
287 288
288static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) 289static int
289 { 290read_string_inner(UI * ui, UI_STRING * uis, int echo, int strip_nl)
291{
290 static int ps; 292 static int ps;
291 int ok; 293 int ok;
292 char result[BUFSIZ]; 294 char result[BUFSIZ];
293 int maxsize = BUFSIZ-1; 295 int maxsize = BUFSIZ - 1;
294 char *p; 296 char *p;
295 297
296 intr_signal=0; 298 intr_signal = 0;
297 ok=0; 299 ok = 0;
298 ps=0; 300 ps = 0;
299 301
300 pushsig(); 302 pushsig();
301 ps=1; 303 ps = 1;
302 304
303 if (!echo && !noecho_console(ui)) 305 if (!echo && !noecho_console(ui))
304 goto error; 306 goto error;
305 ps=2; 307 ps = 2;
306 308
307 result[0]='\0'; 309 result[0] = '\0';
308 p=fgets(result,maxsize,tty_in); 310 p = fgets(result, maxsize, tty_in);
309 if(!p) 311 if (!p)
310 goto error; 312 goto error;
311 if (feof(tty_in)) goto error; 313 if (feof(tty_in))
312 if (ferror(tty_in)) goto error; 314 goto error;
313 if ((p=(char *)strchr(result,'\n')) != NULL) 315 if (ferror(tty_in))
314 { 316 goto error;
317 if ((p = (char *) strchr(result, '\n')) != NULL) {
315 if (strip_nl) 318 if (strip_nl)
316 *p='\0'; 319 *p = '\0';
317 } 320 } else if (!read_till_nl(tty_in))
318 else 321 goto error;
319 if (!read_till_nl(tty_in))
320 goto error;
321 if (UI_set_result(ui, uis, result) >= 0) 322 if (UI_set_result(ui, uis, result) >= 0)
322 ok=1; 323 ok = 1;
323 324
324error: 325error:
325 if (intr_signal == SIGINT) 326 if (intr_signal == SIGINT)
326 ok=-1; 327 ok = -1;
327 if (!echo) fprintf(tty_out,"\n"); 328 if (!echo)
329 fprintf(tty_out, "\n");
328 if (ps >= 2 && !echo && !echo_console(ui)) 330 if (ps >= 2 && !echo && !echo_console(ui))
329 ok=0; 331 ok = 0;
330 332
331 if (ps >= 1) 333 if (ps >= 1)
332 popsig(); 334 popsig();
333 335
334 OPENSSL_cleanse(result,BUFSIZ); 336 OPENSSL_cleanse(result, BUFSIZ);
335 return ok; 337 return ok;
336 } 338}
337 339
338 340
339/* Internal functions to open, handle and close a channel to the console. */ 341/* Internal functions to open, handle and close a channel to the console. */
340static int open_console(UI *ui) 342static int
341 { 343open_console(UI * ui)
344{
342 CRYPTO_w_lock(CRYPTO_LOCK_UI); 345 CRYPTO_w_lock(CRYPTO_LOCK_UI);
343 is_a_tty = 1; 346 is_a_tty = 1;
344 347
345# define DEV_TTY "/dev/tty" 348#define DEV_TTY "/dev/tty"
346 if ((tty_in=fopen(DEV_TTY,"r")) == NULL) 349 if ((tty_in = fopen(DEV_TTY, "r")) == NULL)
347 tty_in=stdin; 350 tty_in = stdin;
348 if ((tty_out=fopen(DEV_TTY,"w")) == NULL) 351 if ((tty_out = fopen(DEV_TTY, "w")) == NULL)
349 tty_out=stderr; 352 tty_out = stderr;
350 353
351#if defined(TTY_get) 354#if defined(TTY_get)
352 if (TTY_get(fileno(tty_in),&tty_orig) == -1) 355 if (TTY_get(fileno(tty_in), &tty_orig) == -1) {
353 {
354 if (errno == ENOTTY) 356 if (errno == ENOTTY)
355 is_a_tty=0; 357 is_a_tty = 0;
356 else 358 else
357 /* Ariel Glenn ariel@columbia.edu reports that solaris 359 /*
358 * can return EINVAL instead. This should be ok */ 360 * Ariel Glenn ariel@columbia.edu reports that
361 * solaris can return EINVAL instead. This should be
362 * ok
363 */
359 if (errno == EINVAL) 364 if (errno == EINVAL)
360 is_a_tty=0; 365 is_a_tty = 0;
361 else 366 else
362 return 0; 367 return 0;
363 } 368 }
364#endif 369#endif
365 return 1; 370 return 1;
366 } 371}
367 372
368static int noecho_console(UI *ui) 373static int
369 { 374noecho_console(UI * ui)
375{
370#ifdef TTY_FLAGS 376#ifdef TTY_FLAGS
371 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); 377 memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
372 tty_new.TTY_FLAGS &= ~ECHO; 378 tty_new.TTY_FLAGS &= ~ECHO;
373#endif 379#endif
374 380
375#if defined(TTY_set) 381#if defined(TTY_set)
376 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) 382 if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
377 return 0; 383 return 0;
378#endif 384#endif
379 return 1; 385 return 1;
380 } 386}
381 387
382static int echo_console(UI *ui) 388static int
383 { 389echo_console(UI * ui)
390{
384#if defined(TTY_set) 391#if defined(TTY_set)
385 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); 392 memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
386 tty_new.TTY_FLAGS |= ECHO; 393 tty_new.TTY_FLAGS |= ECHO;
387#endif 394#endif
388 395
389#if defined(TTY_set) 396#if defined(TTY_set)
390 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) 397 if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
391 return 0; 398 return 0;
392#endif 399#endif
393 return 1; 400 return 1;
394 } 401}
395 402
396static int close_console(UI *ui) 403static int
397 { 404close_console(UI * ui)
398 if (tty_in != stdin) fclose(tty_in); 405{
399 if (tty_out != stderr) fclose(tty_out); 406 if (tty_in != stdin)
407 fclose(tty_in);
408 if (tty_out != stderr)
409 fclose(tty_out);
400 CRYPTO_w_unlock(CRYPTO_LOCK_UI); 410 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
401 411
402 return 1; 412 return 1;
403 } 413}
404 414
405 415
406/* Internal functions to handle signals and act on them */ 416/* Internal functions to handle signals and act on them */
407static void pushsig(void) 417static void
408 { 418pushsig(void)
419{
409 int i; 420 int i;
410#ifdef SIGACTION 421#ifdef SIGACTION
411 struct sigaction sa; 422 struct sigaction sa;
412 423
413 memset(&sa,0,sizeof sa); 424 memset(&sa, 0, sizeof sa);
414 sa.sa_handler=recsig; 425 sa.sa_handler = recsig;
415#endif 426#endif
416 427
417 for (i=1; i<NX509_SIG; i++) 428 for (i = 1; i < NX509_SIG; i++) {
418 {
419#ifdef SIGUSR1 429#ifdef SIGUSR1
420 if (i == SIGUSR1) 430 if (i == SIGUSR1)
421 continue; 431 continue;
@@ -425,39 +435,40 @@ static void pushsig(void)
425 continue; 435 continue;
426#endif 436#endif
427#ifdef SIGKILL 437#ifdef SIGKILL
428 if (i == SIGKILL) /* We can't make any action on that. */ 438 if (i == SIGKILL) /* We can't make any action on that. */
429 continue; 439 continue;
430#endif 440#endif
431#ifdef SIGACTION 441#ifdef SIGACTION
432 sigaction(i,&sa,&savsig[i]); 442 sigaction(i, &sa, &savsig[i]);
433#else 443#else
434 savsig[i]=signal(i,recsig); 444 savsig[i] = signal(i, recsig);
435#endif 445#endif
436 } 446 }
437 447
438#ifdef SIGWINCH 448#ifdef SIGWINCH
439 signal(SIGWINCH,SIG_DFL); 449 signal(SIGWINCH, SIG_DFL);
440#endif 450#endif
441 } 451}
442 452
443static void popsig(void) 453static void
444 { 454popsig(void)
455{
445 int i; 456 int i;
446 for (i=1; i<NX509_SIG; i++) 457 for (i = 1; i < NX509_SIG; i++) {
447 {
448 if (i == SIGUSR1) 458 if (i == SIGUSR1)
449 continue; 459 continue;
450 if (i == SIGUSR2) 460 if (i == SIGUSR2)
451 continue; 461 continue;
452#ifdef SIGACTION 462#ifdef SIGACTION
453 sigaction(i,&savsig[i],NULL); 463 sigaction(i, &savsig[i], NULL);
454#else 464#else
455 signal(i,savsig[i]); 465 signal(i, savsig[i]);
456#endif 466#endif
457 }
458 } 467 }
468}
459 469
460static void recsig(int i) 470static void
461 { 471recsig(int i)
462 intr_signal=i; 472{
463 } 473 intr_signal = i;
474}
diff --git a/src/lib/libcrypto/ui/ui_util.c b/src/lib/libcrypto/ui/ui_util.c
index 5d9760bb7b..af50451403 100644
--- a/src/lib/libcrypto/ui/ui_util.c
+++ b/src/lib/libcrypto/ui/ui_util.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -56,18 +56,20 @@
56#include <string.h> 56#include <string.h>
57#include "ui_locl.h" 57#include "ui_locl.h"
58 58
59int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify) 59int
60 { 60UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
61{
61 char buff[BUFSIZ]; 62 char buff[BUFSIZ];
62 int ret; 63 int ret;
63 64
64 ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); 65 ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length, prompt, verify);
65 OPENSSL_cleanse(buff,BUFSIZ); 66 OPENSSL_cleanse(buff, BUFSIZ);
66 return(ret); 67 return (ret);
67 } 68}
68 69
69int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify) 70int
70 { 71UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
72{
71 int ok = 0; 73 int ok = 0;
72 UI *ui; 74 UI *ui;
73 75
@@ -75,17 +77,16 @@ int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
75 return -1; 77 return -1;
76 78
77 ui = UI_new(); 79 ui = UI_new();
78 if (ui) 80 if (ui) {
79 { 81 ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1);
80 ok = UI_add_input_string(ui,prompt,0,buf,0,size-1);
81 if (ok >= 0 && verify) 82 if (ok >= 0 && verify)
82 ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1, 83 ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1,
83 buf); 84 buf);
84 if (ok >= 0) 85 if (ok >= 0)
85 ok=UI_process(ui); 86 ok = UI_process(ui);
86 UI_free(ui); 87 UI_free(ui);
87 } 88 }
88 if (ok > 0) 89 if (ok > 0)
89 ok = 0; 90 ok = 0;
90 return(ok); 91 return (ok);
91 } 92}
diff --git a/src/lib/libssl/src/crypto/ui/ui_compat.c b/src/lib/libssl/src/crypto/ui/ui_compat.c
index 13e0f70d90..2c5ee4dcee 100644
--- a/src/lib/libssl/src/crypto/ui/ui_compat.c
+++ b/src/lib/libssl/src/crypto/ui/ui_compat.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -56,12 +56,14 @@
56#include <string.h> 56#include <string.h>
57#include <openssl/ui_compat.h> 57#include <openssl/ui_compat.h>
58 58
59int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify) 59int
60 { 60_ossl_old_des_read_pw_string(char *buf, int length, const char *prompt, int verify)
61{
61 return UI_UTIL_read_pw_string(buf, length, prompt, verify); 62 return UI_UTIL_read_pw_string(buf, length, prompt, verify);
62 } 63}
63 64
64int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify) 65int
65 { 66_ossl_old_des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
67{
66 return UI_UTIL_read_pw(buf, buff, size, prompt, verify); 68 return UI_UTIL_read_pw(buf, buff, size, prompt, verify);
67 } 69}
diff --git a/src/lib/libssl/src/crypto/ui/ui_err.c b/src/lib/libssl/src/crypto/ui/ui_err.c
index a6b96299a0..a9b22e2e57 100644
--- a/src/lib/libssl/src/crypto/ui/ui_err.c
+++ b/src/lib/libssl/src/crypto/ui/ui_err.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -68,45 +68,45 @@
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_UI,func,0) 68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_UI,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason) 69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason)
70 70
71static ERR_STRING_DATA UI_str_functs[]= 71static ERR_STRING_DATA UI_str_functs[] =
72 { 72{
73{ERR_FUNC(UI_F_GENERAL_ALLOCATE_BOOLEAN), "GENERAL_ALLOCATE_BOOLEAN"}, 73 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_BOOLEAN), "GENERAL_ALLOCATE_BOOLEAN"},
74{ERR_FUNC(UI_F_GENERAL_ALLOCATE_PROMPT), "GENERAL_ALLOCATE_PROMPT"}, 74 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_PROMPT), "GENERAL_ALLOCATE_PROMPT"},
75{ERR_FUNC(UI_F_GENERAL_ALLOCATE_STRING), "GENERAL_ALLOCATE_STRING"}, 75 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_STRING), "GENERAL_ALLOCATE_STRING"},
76{ERR_FUNC(UI_F_UI_CTRL), "UI_ctrl"}, 76 {ERR_FUNC(UI_F_UI_CTRL), "UI_ctrl"},
77{ERR_FUNC(UI_F_UI_DUP_ERROR_STRING), "UI_dup_error_string"}, 77 {ERR_FUNC(UI_F_UI_DUP_ERROR_STRING), "UI_dup_error_string"},
78{ERR_FUNC(UI_F_UI_DUP_INFO_STRING), "UI_dup_info_string"}, 78 {ERR_FUNC(UI_F_UI_DUP_INFO_STRING), "UI_dup_info_string"},
79{ERR_FUNC(UI_F_UI_DUP_INPUT_BOOLEAN), "UI_dup_input_boolean"}, 79 {ERR_FUNC(UI_F_UI_DUP_INPUT_BOOLEAN), "UI_dup_input_boolean"},
80{ERR_FUNC(UI_F_UI_DUP_INPUT_STRING), "UI_dup_input_string"}, 80 {ERR_FUNC(UI_F_UI_DUP_INPUT_STRING), "UI_dup_input_string"},
81{ERR_FUNC(UI_F_UI_DUP_VERIFY_STRING), "UI_dup_verify_string"}, 81 {ERR_FUNC(UI_F_UI_DUP_VERIFY_STRING), "UI_dup_verify_string"},
82{ERR_FUNC(UI_F_UI_GET0_RESULT), "UI_get0_result"}, 82 {ERR_FUNC(UI_F_UI_GET0_RESULT), "UI_get0_result"},
83{ERR_FUNC(UI_F_UI_NEW_METHOD), "UI_new_method"}, 83 {ERR_FUNC(UI_F_UI_NEW_METHOD), "UI_new_method"},
84{ERR_FUNC(UI_F_UI_SET_RESULT), "UI_set_result"}, 84 {ERR_FUNC(UI_F_UI_SET_RESULT), "UI_set_result"},
85{0,NULL} 85 {0, NULL}
86 }; 86};
87 87
88static ERR_STRING_DATA UI_str_reasons[]= 88static ERR_STRING_DATA UI_str_reasons[] =
89 { 89{
90{ERR_REASON(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS),"common ok and cancel characters"}, 90 {ERR_REASON(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS), "common ok and cancel characters"},
91{ERR_REASON(UI_R_INDEX_TOO_LARGE) ,"index too large"}, 91 {ERR_REASON(UI_R_INDEX_TOO_LARGE), "index too large"},
92{ERR_REASON(UI_R_INDEX_TOO_SMALL) ,"index too small"}, 92 {ERR_REASON(UI_R_INDEX_TOO_SMALL), "index too small"},
93{ERR_REASON(UI_R_NO_RESULT_BUFFER) ,"no result buffer"}, 93 {ERR_REASON(UI_R_NO_RESULT_BUFFER), "no result buffer"},
94{ERR_REASON(UI_R_RESULT_TOO_LARGE) ,"result too large"}, 94 {ERR_REASON(UI_R_RESULT_TOO_LARGE), "result too large"},
95{ERR_REASON(UI_R_RESULT_TOO_SMALL) ,"result too small"}, 95 {ERR_REASON(UI_R_RESULT_TOO_SMALL), "result too small"},
96{ERR_REASON(UI_R_UNKNOWN_CONTROL_COMMAND),"unknown control command"}, 96 {ERR_REASON(UI_R_UNKNOWN_CONTROL_COMMAND), "unknown control command"},
97{0,NULL} 97 {0, NULL}
98 }; 98};
99 99
100#endif 100#endif
101 101
102void ERR_load_UI_strings(void) 102void
103 { 103ERR_load_UI_strings(void)
104{
104#ifndef OPENSSL_NO_ERR 105#ifndef OPENSSL_NO_ERR
105 106
106 if (ERR_func_error_string(UI_str_functs[0].error) == NULL) 107 if (ERR_func_error_string(UI_str_functs[0].error) == NULL) {
107 { 108 ERR_load_strings(0, UI_str_functs);
108 ERR_load_strings(0,UI_str_functs); 109 ERR_load_strings(0, UI_str_reasons);
109 ERR_load_strings(0,UI_str_reasons);
110 }
111#endif
112 } 110 }
111#endif
112}
diff --git a/src/lib/libssl/src/crypto/ui/ui_lib.c b/src/lib/libssl/src/crypto/ui/ui_lib.c
index d3cadd51f6..32fb9d7dbb 100644
--- a/src/lib/libssl/src/crypto/ui/ui_lib.c
+++ b/src/lib/libssl/src/crypto/ui/ui_lib.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -65,359 +65,337 @@
65#include "ui_locl.h" 65#include "ui_locl.h"
66 66
67IMPLEMENT_STACK_OF(UI_STRING_ST) 67IMPLEMENT_STACK_OF(UI_STRING_ST)
68 static const UI_METHOD *default_UI_meth = NULL;
68 69
69static const UI_METHOD *default_UI_meth=NULL; 70 UI *UI_new(void)
71{
72 return (UI_new_method(NULL));
73}
70 74
71UI *UI_new(void) 75UI *
72 { 76UI_new_method(const UI_METHOD * method)
73 return(UI_new_method(NULL)); 77{
74 }
75
76UI *UI_new_method(const UI_METHOD *method)
77 {
78 UI *ret; 78 UI *ret;
79 79
80 ret=(UI *)malloc(sizeof(UI)); 80 ret = (UI *) malloc(sizeof(UI));
81 if (ret == NULL) 81 if (ret == NULL) {
82 { 82 UIerr(UI_F_UI_NEW_METHOD, ERR_R_MALLOC_FAILURE);
83 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE);
84 return NULL; 83 return NULL;
85 } 84 }
86 if (method == NULL) 85 if (method == NULL)
87 ret->meth=UI_get_default_method(); 86 ret->meth = UI_get_default_method();
88 else 87 else
89 ret->meth=method; 88 ret->meth = method;
90 89
91 ret->strings=NULL; 90 ret->strings = NULL;
92 ret->user_data=NULL; 91 ret->user_data = NULL;
93 ret->flags=0; 92 ret->flags = 0;
94 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data); 93 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data);
95 return ret; 94 return ret;
96 } 95}
97 96
98static void free_string(UI_STRING *uis) 97static void
99 { 98free_string(UI_STRING * uis)
100 if (uis->flags & OUT_STRING_FREEABLE) 99{
101 { 100 if (uis->flags & OUT_STRING_FREEABLE) {
102 free((char *)uis->out_string); 101 free((char *) uis->out_string);
103 switch(uis->type) 102 switch (uis->type) {
104 {
105 case UIT_BOOLEAN: 103 case UIT_BOOLEAN:
106 free((char *)uis->_.boolean_data.action_desc); 104 free((char *) uis->_.boolean_data.action_desc);
107 free((char *)uis->_.boolean_data.ok_chars); 105 free((char *) uis->_.boolean_data.ok_chars);
108 free((char *)uis->_.boolean_data.cancel_chars); 106 free((char *) uis->_.boolean_data.cancel_chars);
109 break; 107 break;
110 default: 108 default:
111 break; 109 break;
112 }
113 } 110 }
114 free(uis);
115 } 111 }
112 free(uis);
113}
116 114
117void UI_free(UI *ui) 115void
118 { 116UI_free(UI * ui)
117{
119 if (ui == NULL) 118 if (ui == NULL)
120 return; 119 return;
121 sk_UI_STRING_pop_free(ui->strings,free_string); 120 sk_UI_STRING_pop_free(ui->strings, free_string);
122 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data); 121 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
123 free(ui); 122 free(ui);
124 } 123}
125 124
126static int allocate_string_stack(UI *ui) 125static int
127 { 126allocate_string_stack(UI * ui)
128 if (ui->strings == NULL) 127{
129 { 128 if (ui->strings == NULL) {
130 ui->strings=sk_UI_STRING_new_null(); 129 ui->strings = sk_UI_STRING_new_null();
131 if (ui->strings == NULL) 130 if (ui->strings == NULL) {
132 {
133 return -1; 131 return -1;
134 }
135 } 132 }
136 return 0;
137 } 133 }
134 return 0;
135}
138 136
139static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt, 137static UI_STRING *
140 int prompt_freeable, enum UI_string_types type, int input_flags, 138general_allocate_prompt(UI * ui, const char *prompt,
141 char *result_buf) 139 int prompt_freeable, enum UI_string_types type, int input_flags,
142 { 140 char *result_buf)
141{
143 UI_STRING *ret = NULL; 142 UI_STRING *ret = NULL;
144 143
145 if (prompt == NULL) 144 if (prompt == NULL) {
146 { 145 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, ERR_R_PASSED_NULL_PARAMETER);
147 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER); 146 } else if ((type == UIT_PROMPT || type == UIT_VERIFY
148 } 147 || type == UIT_BOOLEAN) && result_buf == NULL) {
149 else if ((type == UIT_PROMPT || type == UIT_VERIFY 148 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, UI_R_NO_RESULT_BUFFER);
150 || type == UIT_BOOLEAN) && result_buf == NULL) 149 } else if ((ret = (UI_STRING *) malloc(sizeof(UI_STRING)))) {
151 { 150 ret->out_string = prompt;
152 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER); 151 ret->flags = prompt_freeable ? OUT_STRING_FREEABLE : 0;
153 } 152 ret->input_flags = input_flags;
154 else if ((ret = (UI_STRING *)malloc(sizeof(UI_STRING)))) 153 ret->type = type;
155 { 154 ret->result_buf = result_buf;
156 ret->out_string=prompt;
157 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0;
158 ret->input_flags=input_flags;
159 ret->type=type;
160 ret->result_buf=result_buf;
161 }
162 return ret;
163 } 155 }
156 return ret;
157}
164 158
165static int general_allocate_string(UI *ui, const char *prompt, 159static int
166 int prompt_freeable, enum UI_string_types type, int input_flags, 160general_allocate_string(UI * ui, const char *prompt,
167 char *result_buf, int minsize, int maxsize, const char *test_buf) 161 int prompt_freeable, enum UI_string_types type, int input_flags,
168 { 162 char *result_buf, int minsize, int maxsize, const char *test_buf)
163{
169 int ret = -1; 164 int ret = -1;
170 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable, 165 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
171 type, input_flags, result_buf); 166 type, input_flags, result_buf);
172 167
173 if (s) 168 if (s) {
174 { 169 if (allocate_string_stack(ui) >= 0) {
175 if (allocate_string_stack(ui) >= 0) 170 s->_.string_data.result_minsize = minsize;
176 { 171 s->_.string_data.result_maxsize = maxsize;
177 s->_.string_data.result_minsize=minsize; 172 s->_.string_data.test_buf = test_buf;
178 s->_.string_data.result_maxsize=maxsize; 173 ret = sk_UI_STRING_push(ui->strings, s);
179 s->_.string_data.test_buf=test_buf;
180 ret=sk_UI_STRING_push(ui->strings, s);
181 /* sk_push() returns 0 on error. Let's addapt that */ 174 /* sk_push() returns 0 on error. Let's addapt that */
182 if (ret <= 0) ret--; 175 if (ret <= 0)
183 } 176 ret--;
184 else 177 } else
185 free_string(s); 178 free_string(s);
186 }
187 return ret;
188 } 179 }
189 180 return ret;
190static int general_allocate_boolean(UI *ui, 181}
191 const char *prompt, const char *action_desc, 182
192 const char *ok_chars, const char *cancel_chars, 183static int
193 int prompt_freeable, enum UI_string_types type, int input_flags, 184general_allocate_boolean(UI * ui,
194 char *result_buf) 185 const char *prompt, const char *action_desc,
195 { 186 const char *ok_chars, const char *cancel_chars,
187 int prompt_freeable, enum UI_string_types type, int input_flags,
188 char *result_buf)
189{
196 int ret = -1; 190 int ret = -1;
197 UI_STRING *s; 191 UI_STRING *s;
198 const char *p; 192 const char *p;
199 193
200 if (ok_chars == NULL) 194 if (ok_chars == NULL) {
201 { 195 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, ERR_R_PASSED_NULL_PARAMETER);
202 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER); 196 } else if (cancel_chars == NULL) {
203 } 197 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, ERR_R_PASSED_NULL_PARAMETER);
204 else if (cancel_chars == NULL) 198 } else {
205 { 199 for (p = ok_chars; *p; p++) {
206 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER); 200 if (strchr(cancel_chars, *p)) {
207 }
208 else
209 {
210 for(p = ok_chars; *p; p++)
211 {
212 if (strchr(cancel_chars, *p))
213 {
214 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, 201 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,
215 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS); 202 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
216 }
217 } 203 }
204 }
218 205
219 s = general_allocate_prompt(ui, prompt, prompt_freeable, 206 s = general_allocate_prompt(ui, prompt, prompt_freeable,
220 type, input_flags, result_buf); 207 type, input_flags, result_buf);
221 208
222 if (s) 209 if (s) {
223 { 210 if (allocate_string_stack(ui) >= 0) {
224 if (allocate_string_stack(ui) >= 0)
225 {
226 s->_.boolean_data.action_desc = action_desc; 211 s->_.boolean_data.action_desc = action_desc;
227 s->_.boolean_data.ok_chars = ok_chars; 212 s->_.boolean_data.ok_chars = ok_chars;
228 s->_.boolean_data.cancel_chars = cancel_chars; 213 s->_.boolean_data.cancel_chars = cancel_chars;
229 ret=sk_UI_STRING_push(ui->strings, s); 214 ret = sk_UI_STRING_push(ui->strings, s);
230 /* sk_push() returns 0 on error. 215 /*
231 Let's addapt that */ 216 * sk_push() returns 0 on error. Let's addapt
232 if (ret <= 0) ret--; 217 * that
233 } 218 */
234 else 219 if (ret <= 0)
220 ret--;
221 } else
235 free_string(s); 222 free_string(s);
236 }
237 } 223 }
238 return ret;
239 } 224 }
225 return ret;
226}
240 227
241/* Returns the index to the place in the stack or -1 for error. Uses a 228/* Returns the index to the place in the stack or -1 for error. Uses a
242 direct reference to the prompt. */ 229 direct reference to the prompt. */
243int UI_add_input_string(UI *ui, const char *prompt, int flags, 230int
244 char *result_buf, int minsize, int maxsize) 231UI_add_input_string(UI * ui, const char *prompt, int flags,
245 { 232 char *result_buf, int minsize, int maxsize)
233{
246 return general_allocate_string(ui, prompt, 0, 234 return general_allocate_string(ui, prompt, 0,
247 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL); 235 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
248 } 236}
249 237
250/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */ 238/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
251int UI_dup_input_string(UI *ui, const char *prompt, int flags, 239int
252 char *result_buf, int minsize, int maxsize) 240UI_dup_input_string(UI * ui, const char *prompt, int flags,
253 { 241 char *result_buf, int minsize, int maxsize)
254 char *prompt_copy=NULL; 242{
243 char *prompt_copy = NULL;
255 244
256 if (prompt) 245 if (prompt) {
257 { 246 prompt_copy = BUF_strdup(prompt);
258 prompt_copy=BUF_strdup(prompt); 247 if (prompt_copy == NULL) {
259 if (prompt_copy == NULL) 248 UIerr(UI_F_UI_DUP_INPUT_STRING, ERR_R_MALLOC_FAILURE);
260 {
261 UIerr(UI_F_UI_DUP_INPUT_STRING,ERR_R_MALLOC_FAILURE);
262 return 0; 249 return 0;
263 }
264 } 250 }
265
266 return general_allocate_string(ui, prompt_copy, 1,
267 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
268 } 251 }
252 return general_allocate_string(ui, prompt_copy, 1,
253 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
254}
269 255
270int UI_add_verify_string(UI *ui, const char *prompt, int flags, 256int
271 char *result_buf, int minsize, int maxsize, const char *test_buf) 257UI_add_verify_string(UI * ui, const char *prompt, int flags,
272 { 258 char *result_buf, int minsize, int maxsize, const char *test_buf)
259{
273 return general_allocate_string(ui, prompt, 0, 260 return general_allocate_string(ui, prompt, 0,
274 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); 261 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
275 } 262}
276 263
277int UI_dup_verify_string(UI *ui, const char *prompt, int flags, 264int
278 char *result_buf, int minsize, int maxsize, const char *test_buf) 265UI_dup_verify_string(UI * ui, const char *prompt, int flags,
279 { 266 char *result_buf, int minsize, int maxsize, const char *test_buf)
280 char *prompt_copy=NULL; 267{
268 char *prompt_copy = NULL;
281 269
282 if (prompt) 270 if (prompt) {
283 { 271 prompt_copy = BUF_strdup(prompt);
284 prompt_copy=BUF_strdup(prompt); 272 if (prompt_copy == NULL) {
285 if (prompt_copy == NULL) 273 UIerr(UI_F_UI_DUP_VERIFY_STRING, ERR_R_MALLOC_FAILURE);
286 {
287 UIerr(UI_F_UI_DUP_VERIFY_STRING,ERR_R_MALLOC_FAILURE);
288 return -1; 274 return -1;
289 }
290 } 275 }
291
292 return general_allocate_string(ui, prompt_copy, 1,
293 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
294 } 276 }
295 277 return general_allocate_string(ui, prompt_copy, 1,
296int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, 278 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
297 const char *ok_chars, const char *cancel_chars, 279}
298 int flags, char *result_buf) 280
299 { 281int
282UI_add_input_boolean(UI * ui, const char *prompt, const char *action_desc,
283 const char *ok_chars, const char *cancel_chars,
284 int flags, char *result_buf)
285{
300 return general_allocate_boolean(ui, prompt, action_desc, 286 return general_allocate_boolean(ui, prompt, action_desc,
301 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf); 287 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
302 } 288}
303 289
304int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, 290int
305 const char *ok_chars, const char *cancel_chars, 291UI_dup_input_boolean(UI * ui, const char *prompt, const char *action_desc,
306 int flags, char *result_buf) 292 const char *ok_chars, const char *cancel_chars,
307 { 293 int flags, char *result_buf)
294{
308 char *prompt_copy = NULL; 295 char *prompt_copy = NULL;
309 char *action_desc_copy = NULL; 296 char *action_desc_copy = NULL;
310 char *ok_chars_copy = NULL; 297 char *ok_chars_copy = NULL;
311 char *cancel_chars_copy = NULL; 298 char *cancel_chars_copy = NULL;
312 299
313 if (prompt) 300 if (prompt) {
314 { 301 prompt_copy = BUF_strdup(prompt);
315 prompt_copy=BUF_strdup(prompt); 302 if (prompt_copy == NULL) {
316 if (prompt_copy == NULL) 303 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE);
317 {
318 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
319 goto err; 304 goto err;
320 }
321 } 305 }
322 306 }
323 if (action_desc) 307 if (action_desc) {
324 { 308 action_desc_copy = BUF_strdup(action_desc);
325 action_desc_copy=BUF_strdup(action_desc); 309 if (action_desc_copy == NULL) {
326 if (action_desc_copy == NULL) 310 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE);
327 {
328 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
329 goto err; 311 goto err;
330 }
331 } 312 }
332 313 }
333 if (ok_chars) 314 if (ok_chars) {
334 { 315 ok_chars_copy = BUF_strdup(ok_chars);
335 ok_chars_copy=BUF_strdup(ok_chars); 316 if (ok_chars_copy == NULL) {
336 if (ok_chars_copy == NULL) 317 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE);
337 {
338 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
339 goto err; 318 goto err;
340 }
341 } 319 }
342 320 }
343 if (cancel_chars) 321 if (cancel_chars) {
344 { 322 cancel_chars_copy = BUF_strdup(cancel_chars);
345 cancel_chars_copy=BUF_strdup(cancel_chars); 323 if (cancel_chars_copy == NULL) {
346 if (cancel_chars_copy == NULL) 324 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE);
347 {
348 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
349 goto err; 325 goto err;
350 }
351 } 326 }
352 327 }
353 return general_allocate_boolean(ui, prompt_copy, action_desc_copy, 328 return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
354 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags, 329 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
355 result_buf); 330 result_buf);
356 err: 331err:
357 if (prompt_copy) free(prompt_copy); 332 if (prompt_copy)
358 if (action_desc_copy) free(action_desc_copy); 333 free(prompt_copy);
359 if (ok_chars_copy) free(ok_chars_copy); 334 if (action_desc_copy)
360 if (cancel_chars_copy) free(cancel_chars_copy); 335 free(action_desc_copy);
336 if (ok_chars_copy)
337 free(ok_chars_copy);
338 if (cancel_chars_copy)
339 free(cancel_chars_copy);
361 return -1; 340 return -1;
362 } 341}
363 342
364int UI_add_info_string(UI *ui, const char *text) 343int
365 { 344UI_add_info_string(UI * ui, const char *text)
345{
366 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0, 346 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
367 NULL); 347 NULL);
368 } 348}
369 349
370int UI_dup_info_string(UI *ui, const char *text) 350int
371 { 351UI_dup_info_string(UI * ui, const char *text)
372 char *text_copy=NULL; 352{
373 353 char *text_copy = NULL;
374 if (text) 354
375 { 355 if (text) {
376 text_copy=BUF_strdup(text); 356 text_copy = BUF_strdup(text);
377 if (text_copy == NULL) 357 if (text_copy == NULL) {
378 { 358 UIerr(UI_F_UI_DUP_INFO_STRING, ERR_R_MALLOC_FAILURE);
379 UIerr(UI_F_UI_DUP_INFO_STRING,ERR_R_MALLOC_FAILURE);
380 return -1; 359 return -1;
381 }
382 } 360 }
383
384 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
385 0, 0, NULL);
386 } 361 }
362 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
363 0, 0, NULL);
364}
387 365
388int UI_add_error_string(UI *ui, const char *text) 366int
389 { 367UI_add_error_string(UI * ui, const char *text)
368{
390 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0, 369 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
391 NULL); 370 NULL);
392 } 371}
393 372
394int UI_dup_error_string(UI *ui, const char *text) 373int
395 { 374UI_dup_error_string(UI * ui, const char *text)
396 char *text_copy=NULL; 375{
397 376 char *text_copy = NULL;
398 if (text) 377
399 { 378 if (text) {
400 text_copy=BUF_strdup(text); 379 text_copy = BUF_strdup(text);
401 if (text_copy == NULL) 380 if (text_copy == NULL) {
402 { 381 UIerr(UI_F_UI_DUP_ERROR_STRING, ERR_R_MALLOC_FAILURE);
403 UIerr(UI_F_UI_DUP_ERROR_STRING,ERR_R_MALLOC_FAILURE);
404 return -1; 382 return -1;
405 }
406 } 383 }
407 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
408 0, 0, NULL);
409 } 384 }
385 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
386 0, 0, NULL);
387}
410 388
411char *UI_construct_prompt(UI *ui, const char *object_desc, 389char *
412 const char *object_name) 390UI_construct_prompt(UI * ui, const char *object_desc,
413 { 391 const char *object_name)
392{
414 char *prompt = NULL; 393 char *prompt = NULL;
415 394
416 if (ui->meth->ui_construct_prompt) 395 if (ui->meth->ui_construct_prompt)
417 prompt = ui->meth->ui_construct_prompt(ui, 396 prompt = ui->meth->ui_construct_prompt(ui,
418 object_desc, object_name); 397 object_desc, object_name);
419 else 398 else {
420 {
421 char prompt1[] = "Enter "; 399 char prompt1[] = "Enter ";
422 char prompt2[] = " for "; 400 char prompt2[] = " for ";
423 char prompt3[] = ":"; 401 char prompt3[] = ":";
@@ -430,48 +408,49 @@ char *UI_construct_prompt(UI *ui, const char *object_desc,
430 len += sizeof(prompt2) - 1 + strlen(object_name); 408 len += sizeof(prompt2) - 1 + strlen(object_name);
431 len += sizeof(prompt3) - 1; 409 len += sizeof(prompt3) - 1;
432 410
433 prompt = (char *)malloc(len + 1); 411 prompt = (char *) malloc(len + 1);
434 BUF_strlcpy(prompt, prompt1, len + 1); 412 BUF_strlcpy(prompt, prompt1, len + 1);
435 BUF_strlcat(prompt, object_desc, len + 1); 413 BUF_strlcat(prompt, object_desc, len + 1);
436 if (object_name) 414 if (object_name) {
437 {
438 BUF_strlcat(prompt, prompt2, len + 1); 415 BUF_strlcat(prompt, prompt2, len + 1);
439 BUF_strlcat(prompt, object_name, len + 1); 416 BUF_strlcat(prompt, object_name, len + 1);
440 }
441 BUF_strlcat(prompt, prompt3, len + 1);
442 } 417 }
443 return prompt; 418 BUF_strlcat(prompt, prompt3, len + 1);
444 } 419 }
420 return prompt;
421}
445 422
446void *UI_add_user_data(UI *ui, void *user_data) 423void *
447 { 424UI_add_user_data(UI * ui, void *user_data)
425{
448 void *old_data = ui->user_data; 426 void *old_data = ui->user_data;
449 ui->user_data = user_data; 427 ui->user_data = user_data;
450 return old_data; 428 return old_data;
451 } 429}
452 430
453void *UI_get0_user_data(UI *ui) 431void *
454 { 432UI_get0_user_data(UI * ui)
433{
455 return ui->user_data; 434 return ui->user_data;
456 } 435}
457 436
458const char *UI_get0_result(UI *ui, int i) 437const char *
459 { 438UI_get0_result(UI * ui, int i)
460 if (i < 0) 439{
461 { 440 if (i < 0) {
462 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL); 441 UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_SMALL);
463 return NULL; 442 return NULL;
464 } 443 }
465 if (i >= sk_UI_STRING_num(ui->strings)) 444 if (i >= sk_UI_STRING_num(ui->strings)) {
466 { 445 UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_LARGE);
467 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE);
468 return NULL; 446 return NULL;
469 }
470 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
471 } 447 }
448 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
449}
472 450
473static int print_error(const char *str, size_t len, UI *ui) 451static int
474 { 452print_error(const char *str, size_t len, UI * ui)
453{
475 UI_STRING uis; 454 UI_STRING uis;
476 455
477 memset(&uis, 0, sizeof(uis)); 456 memset(&uis, 0, sizeof(uis));
@@ -479,446 +458,441 @@ static int print_error(const char *str, size_t len, UI *ui)
479 uis.out_string = str; 458 uis.out_string = str;
480 459
481 if (ui->meth->ui_write_string 460 if (ui->meth->ui_write_string
482 && !ui->meth->ui_write_string(ui, &uis)) 461 && !ui->meth->ui_write_string(ui, &uis))
483 return -1; 462 return -1;
484 return 0; 463 return 0;
485 } 464}
486 465
487int UI_process(UI *ui) 466int
488 { 467UI_process(UI * ui)
489 int i, ok=0; 468{
469 int i, ok = 0;
490 470
491 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui)) 471 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui))
492 return -1; 472 return -1;
493 473
494 if (ui->flags & UI_FLAG_PRINT_ERRORS) 474 if (ui->flags & UI_FLAG_PRINT_ERRORS)
495 ERR_print_errors_cb( 475 ERR_print_errors_cb(
496 (int (*)(const char *, size_t, void *))print_error, 476 (int (*) (const char *, size_t, void *)) print_error,
497 (void *)ui); 477 (void *) ui);
498 478
499 for(i=0; i<sk_UI_STRING_num(ui->strings); i++) 479 for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
500 {
501 if (ui->meth->ui_write_string 480 if (ui->meth->ui_write_string
502 && !ui->meth->ui_write_string(ui, 481 && !ui->meth->ui_write_string(ui,
503 sk_UI_STRING_value(ui->strings, i))) 482 sk_UI_STRING_value(ui->strings, i))) {
504 { 483 ok = -1;
505 ok=-1;
506 goto err; 484 goto err;
507 }
508 } 485 }
486 }
509 487
510 if (ui->meth->ui_flush) 488 if (ui->meth->ui_flush)
511 switch(ui->meth->ui_flush(ui)) 489 switch (ui->meth->ui_flush(ui)) {
512 { 490 case -1: /* Interrupt/Cancel/something... */
513 case -1: /* Interrupt/Cancel/something... */
514 ok = -2; 491 ok = -2;
515 goto err; 492 goto err;
516 case 0: /* Errors */ 493 case 0: /* Errors */
517 ok = -1; 494 ok = -1;
518 goto err; 495 goto err;
519 default: /* Success */ 496 default: /* Success */
520 ok = 0; 497 ok = 0;
521 break; 498 break;
522 } 499 }
523 500
524 for(i=0; i<sk_UI_STRING_num(ui->strings); i++) 501 for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
525 { 502 if (ui->meth->ui_read_string) {
526 if (ui->meth->ui_read_string) 503 switch (ui->meth->ui_read_string(ui,
527 { 504 sk_UI_STRING_value(ui->strings, i))) {
528 switch(ui->meth->ui_read_string(ui, 505 case -1: /* Interrupt/Cancel/something... */
529 sk_UI_STRING_value(ui->strings, i)))
530 {
531 case -1: /* Interrupt/Cancel/something... */
532 ok = -2; 506 ok = -2;
533 goto err; 507 goto err;
534 case 0: /* Errors */ 508 case 0:/* Errors */
535 ok = -1; 509 ok = -1;
536 goto err; 510 goto err;
537 default: /* Success */ 511 default: /* Success */
538 ok = 0; 512 ok = 0;
539 break; 513 break;
540 }
541 } 514 }
542 } 515 }
543 err: 516 }
517err:
544 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui)) 518 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui))
545 return -1; 519 return -1;
546 return ok; 520 return ok;
547 } 521}
548 522
549int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)) 523int
550 { 524UI_ctrl(UI * ui, int cmd, long i, void *p, void (*f) (void))
551 if (ui == NULL) 525{
552 { 526 if (ui == NULL) {
553 UIerr(UI_F_UI_CTRL,ERR_R_PASSED_NULL_PARAMETER); 527 UIerr(UI_F_UI_CTRL, ERR_R_PASSED_NULL_PARAMETER);
554 return -1; 528 return -1;
555 } 529 }
556 switch(cmd) 530 switch (cmd) {
557 {
558 case UI_CTRL_PRINT_ERRORS: 531 case UI_CTRL_PRINT_ERRORS:
559 { 532 {
560 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS); 533 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS);
561 if (i) 534 if (i)
562 ui->flags |= UI_FLAG_PRINT_ERRORS; 535 ui->flags |= UI_FLAG_PRINT_ERRORS;
563 else 536 else
564 ui->flags &= ~UI_FLAG_PRINT_ERRORS; 537 ui->flags &= ~UI_FLAG_PRINT_ERRORS;
565 return save_flag; 538 return save_flag;
566 } 539 }
567 case UI_CTRL_IS_REDOABLE: 540 case UI_CTRL_IS_REDOABLE:
568 return !!(ui->flags & UI_FLAG_REDOABLE); 541 return !!(ui->flags & UI_FLAG_REDOABLE);
569 default: 542 default:
570 break; 543 break;
571 }
572 UIerr(UI_F_UI_CTRL,UI_R_UNKNOWN_CONTROL_COMMAND);
573 return -1;
574 } 544 }
545 UIerr(UI_F_UI_CTRL, UI_R_UNKNOWN_CONTROL_COMMAND);
546 return -1;
547}
575 548
576int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 549int
577 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) 550UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new * new_func,
578 { 551 CRYPTO_EX_dup * dup_func, CRYPTO_EX_free * free_func)
552{
579 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp, 553 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
580 new_func, dup_func, free_func); 554 new_func, dup_func, free_func);
581 } 555}
582 556
583int UI_set_ex_data(UI *r, int idx, void *arg) 557int
584 { 558UI_set_ex_data(UI * r, int idx, void *arg)
585 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); 559{
586 } 560 return (CRYPTO_set_ex_data(&r->ex_data, idx, arg));
587 561}
588void *UI_get_ex_data(UI *r, int idx) 562
589 { 563void *
590 return(CRYPTO_get_ex_data(&r->ex_data,idx)); 564UI_get_ex_data(UI * r, int idx)
591 } 565{
592 566 return (CRYPTO_get_ex_data(&r->ex_data, idx));
593void UI_set_default_method(const UI_METHOD *meth) 567}
594 { 568
595 default_UI_meth=meth; 569void
570UI_set_default_method(const UI_METHOD * meth)
571{
572 default_UI_meth = meth;
573}
574
575const UI_METHOD *
576UI_get_default_method(void)
577{
578 if (default_UI_meth == NULL) {
579 default_UI_meth = UI_OpenSSL();
596 } 580 }
597
598const UI_METHOD *UI_get_default_method(void)
599 {
600 if (default_UI_meth == NULL)
601 {
602 default_UI_meth=UI_OpenSSL();
603 }
604 return default_UI_meth; 581 return default_UI_meth;
605 } 582}
606 583
607const UI_METHOD *UI_get_method(UI *ui) 584const UI_METHOD *
608 { 585UI_get_method(UI * ui)
586{
609 return ui->meth; 587 return ui->meth;
610 } 588}
611 589
612const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth) 590const UI_METHOD *
613 { 591UI_set_method(UI * ui, const UI_METHOD * meth)
614 ui->meth=meth; 592{
593 ui->meth = meth;
615 return ui->meth; 594 return ui->meth;
616 } 595}
617 596
618 597
619UI_METHOD *UI_create_method(char *name) 598UI_METHOD *
620 { 599UI_create_method(char *name)
621 UI_METHOD *ui_method = (UI_METHOD *)malloc(sizeof(UI_METHOD)); 600{
601 UI_METHOD *ui_method = (UI_METHOD *) malloc(sizeof(UI_METHOD));
622 602
623 if (ui_method) 603 if (ui_method) {
624 {
625 memset(ui_method, 0, sizeof(*ui_method)); 604 memset(ui_method, 0, sizeof(*ui_method));
626 ui_method->name = BUF_strdup(name); 605 ui_method->name = BUF_strdup(name);
627 }
628 return ui_method;
629 } 606 }
607 return ui_method;
608}
630 609
631/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method 610/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
632 (that is, it hasn't been allocated using UI_create_method(), you deserve 611 (that is, it hasn't been allocated using UI_create_method(), you deserve
633 anything Murphy can throw at you and more! You have been warned. */ 612 anything Murphy can throw at you and more! You have been warned. */
634void UI_destroy_method(UI_METHOD *ui_method) 613void
635 { 614UI_destroy_method(UI_METHOD * ui_method)
615{
636 free(ui_method->name); 616 free(ui_method->name);
637 ui_method->name = NULL; 617 ui_method->name = NULL;
638 free(ui_method); 618 free(ui_method);
639 } 619}
640 620
641int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) 621int
642 { 622UI_method_set_opener(UI_METHOD * method, int (*opener) (UI * ui))
643 if (method) 623{
644 { 624 if (method) {
645 method->ui_open_session = opener; 625 method->ui_open_session = opener;
646 return 0; 626 return 0;
647 } 627 } else
648 else
649 return -1; 628 return -1;
650 } 629}
651 630
652int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)) 631int
653 { 632UI_method_set_writer(UI_METHOD * method, int (*writer) (UI * ui, UI_STRING * uis))
654 if (method) 633{
655 { 634 if (method) {
656 method->ui_write_string = writer; 635 method->ui_write_string = writer;
657 return 0; 636 return 0;
658 } 637 } else
659 else
660 return -1; 638 return -1;
661 } 639}
662 640
663int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)) 641int
664 { 642UI_method_set_flusher(UI_METHOD * method, int (*flusher) (UI * ui))
665 if (method) 643{
666 { 644 if (method) {
667 method->ui_flush = flusher; 645 method->ui_flush = flusher;
668 return 0; 646 return 0;
669 } 647 } else
670 else
671 return -1; 648 return -1;
672 } 649}
673 650
674int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)) 651int
675 { 652UI_method_set_reader(UI_METHOD * method, int (*reader) (UI * ui, UI_STRING * uis))
676 if (method) 653{
677 { 654 if (method) {
678 method->ui_read_string = reader; 655 method->ui_read_string = reader;
679 return 0; 656 return 0;
680 } 657 } else
681 else
682 return -1; 658 return -1;
683 } 659}
684 660
685int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)) 661int
686 { 662UI_method_set_closer(UI_METHOD * method, int (*closer) (UI * ui))
687 if (method) 663{
688 { 664 if (method) {
689 method->ui_close_session = closer; 665 method->ui_close_session = closer;
690 return 0; 666 return 0;
691 } 667 } else
692 else
693 return -1; 668 return -1;
694 } 669}
695 670
696int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name)) 671int
697 { 672UI_method_set_prompt_constructor(UI_METHOD * method, char *(*prompt_constructor) (UI * ui, const char *object_desc, const char *object_name))
698 if (method) 673{
699 { 674 if (method) {
700 method->ui_construct_prompt = prompt_constructor; 675 method->ui_construct_prompt = prompt_constructor;
701 return 0; 676 return 0;
702 } 677 } else
703 else
704 return -1; 678 return -1;
705 } 679}
706 680
707int (*UI_method_get_opener(UI_METHOD *method))(UI*) 681int (*
708 { 682 UI_method_get_opener(UI_METHOD * method)) (UI *)
683{
709 if (method) 684 if (method)
710 return method->ui_open_session; 685 return method->ui_open_session;
711 else 686 else
712 return NULL; 687 return NULL;
713 } 688}
714 689
715int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*) 690int (*
716 { 691 UI_method_get_writer(UI_METHOD * method)) (UI *, UI_STRING *)
692{
717 if (method) 693 if (method)
718 return method->ui_write_string; 694 return method->ui_write_string;
719 else 695 else
720 return NULL; 696 return NULL;
721 } 697}
722 698
723int (*UI_method_get_flusher(UI_METHOD *method))(UI*) 699int (*
724 { 700 UI_method_get_flusher(UI_METHOD * method)) (UI *)
701{
725 if (method) 702 if (method)
726 return method->ui_flush; 703 return method->ui_flush;
727 else 704 else
728 return NULL; 705 return NULL;
729 } 706}
730 707
731int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*) 708int (*
732 { 709 UI_method_get_reader(UI_METHOD * method)) (UI *, UI_STRING *)
710{
733 if (method) 711 if (method)
734 return method->ui_read_string; 712 return method->ui_read_string;
735 else 713 else
736 return NULL; 714 return NULL;
737 } 715}
738 716
739int (*UI_method_get_closer(UI_METHOD *method))(UI*) 717int (*
740 { 718 UI_method_get_closer(UI_METHOD * method)) (UI *)
719{
741 if (method) 720 if (method)
742 return method->ui_close_session; 721 return method->ui_close_session;
743 else 722 else
744 return NULL; 723 return NULL;
745 } 724}
746 725
747char* (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, const char*) 726char *(*
748 { 727 UI_method_get_prompt_constructor(UI_METHOD * method)) (UI *, const char *, const char *)
728{
749 if (method) 729 if (method)
750 return method->ui_construct_prompt; 730 return method->ui_construct_prompt;
751 else 731 else
752 return NULL; 732 return NULL;
753 } 733}
754 734
755enum UI_string_types UI_get_string_type(UI_STRING *uis) 735enum UI_string_types
756 { 736UI_get_string_type(UI_STRING * uis)
737{
757 if (!uis) 738 if (!uis)
758 return UIT_NONE; 739 return UIT_NONE;
759 return uis->type; 740 return uis->type;
760 } 741}
761 742
762int UI_get_input_flags(UI_STRING *uis) 743int
763 { 744UI_get_input_flags(UI_STRING * uis)
745{
764 if (!uis) 746 if (!uis)
765 return 0; 747 return 0;
766 return uis->input_flags; 748 return uis->input_flags;
767 } 749}
768 750
769const char *UI_get0_output_string(UI_STRING *uis) 751const char *
770 { 752UI_get0_output_string(UI_STRING * uis)
753{
771 if (!uis) 754 if (!uis)
772 return NULL; 755 return NULL;
773 return uis->out_string; 756 return uis->out_string;
774 } 757}
775 758
776const char *UI_get0_action_string(UI_STRING *uis) 759const char *
777 { 760UI_get0_action_string(UI_STRING * uis)
761{
778 if (!uis) 762 if (!uis)
779 return NULL; 763 return NULL;
780 switch(uis->type) 764 switch (uis->type) {
781 {
782 case UIT_PROMPT: 765 case UIT_PROMPT:
783 case UIT_BOOLEAN: 766 case UIT_BOOLEAN:
784 return uis->_.boolean_data.action_desc; 767 return uis->_.boolean_data.action_desc;
785 default: 768 default:
786 return NULL; 769 return NULL;
787 }
788 } 770 }
771}
789 772
790const char *UI_get0_result_string(UI_STRING *uis) 773const char *
791 { 774UI_get0_result_string(UI_STRING * uis)
775{
792 if (!uis) 776 if (!uis)
793 return NULL; 777 return NULL;
794 switch(uis->type) 778 switch (uis->type) {
795 {
796 case UIT_PROMPT: 779 case UIT_PROMPT:
797 case UIT_VERIFY: 780 case UIT_VERIFY:
798 return uis->result_buf; 781 return uis->result_buf;
799 default: 782 default:
800 return NULL; 783 return NULL;
801 }
802 } 784 }
785}
803 786
804const char *UI_get0_test_string(UI_STRING *uis) 787const char *
805 { 788UI_get0_test_string(UI_STRING * uis)
789{
806 if (!uis) 790 if (!uis)
807 return NULL; 791 return NULL;
808 switch(uis->type) 792 switch (uis->type) {
809 {
810 case UIT_VERIFY: 793 case UIT_VERIFY:
811 return uis->_.string_data.test_buf; 794 return uis->_.string_data.test_buf;
812 default: 795 default:
813 return NULL; 796 return NULL;
814 }
815 } 797 }
798}
816 799
817int UI_get_result_minsize(UI_STRING *uis) 800int
818 { 801UI_get_result_minsize(UI_STRING * uis)
802{
819 if (!uis) 803 if (!uis)
820 return -1; 804 return -1;
821 switch(uis->type) 805 switch (uis->type) {
822 {
823 case UIT_PROMPT: 806 case UIT_PROMPT:
824 case UIT_VERIFY: 807 case UIT_VERIFY:
825 return uis->_.string_data.result_minsize; 808 return uis->_.string_data.result_minsize;
826 default: 809 default:
827 return -1; 810 return -1;
828 }
829 } 811 }
812}
830 813
831int UI_get_result_maxsize(UI_STRING *uis) 814int
832 { 815UI_get_result_maxsize(UI_STRING * uis)
816{
833 if (!uis) 817 if (!uis)
834 return -1; 818 return -1;
835 switch(uis->type) 819 switch (uis->type) {
836 {
837 case UIT_PROMPT: 820 case UIT_PROMPT:
838 case UIT_VERIFY: 821 case UIT_VERIFY:
839 return uis->_.string_data.result_maxsize; 822 return uis->_.string_data.result_maxsize;
840 default: 823 default:
841 return -1; 824 return -1;
842 }
843 } 825 }
826}
844 827
845int UI_set_result(UI *ui, UI_STRING *uis, const char *result) 828int
846 { 829UI_set_result(UI * ui, UI_STRING * uis, const char *result)
830{
847 int l = strlen(result); 831 int l = strlen(result);
848 832
849 ui->flags &= ~UI_FLAG_REDOABLE; 833 ui->flags &= ~UI_FLAG_REDOABLE;
850 834
851 if (!uis) 835 if (!uis)
852 return -1; 836 return -1;
853 switch (uis->type) 837 switch (uis->type) {
854 {
855 case UIT_PROMPT: 838 case UIT_PROMPT:
856 case UIT_VERIFY: 839 case UIT_VERIFY:
857 { 840 {
858 char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize)+1]; 841 char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize) + 1];
859 char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize)+1]; 842 char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize) + 1];
860 843
861 (void) snprintf(number1, sizeof(number1), "%d", 844 (void) snprintf(number1, sizeof(number1), "%d",
862 uis->_.string_data.result_minsize); 845 uis->_.string_data.result_minsize);
863 (void) snprintf(number2, sizeof(number2), "%d", 846 (void) snprintf(number2, sizeof(number2), "%d",
864 uis->_.string_data.result_maxsize); 847 uis->_.string_data.result_maxsize);
865 848
866 if (l < uis->_.string_data.result_minsize) 849 if (l < uis->_.string_data.result_minsize) {
867 { 850 ui->flags |= UI_FLAG_REDOABLE;
868 ui->flags |= UI_FLAG_REDOABLE; 851 UIerr(UI_F_UI_SET_RESULT, UI_R_RESULT_TOO_SMALL);
869 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_SMALL); 852 ERR_add_error_data(5, "You must type in ",
870 ERR_add_error_data(5,"You must type in ", 853 number1, " to ", number2, " characters");
871 number1," to ",number2," characters"); 854 return -1;
872 return -1;
873 } 855 }
874 if (l > uis->_.string_data.result_maxsize) 856 if (l > uis->_.string_data.result_maxsize) {
875 { 857 ui->flags |= UI_FLAG_REDOABLE;
876 ui->flags |= UI_FLAG_REDOABLE; 858 UIerr(UI_F_UI_SET_RESULT, UI_R_RESULT_TOO_LARGE);
877 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_LARGE); 859 ERR_add_error_data(5, "You must type in ",
878 ERR_add_error_data(5,"You must type in ", 860 number1, " to ", number2, " characters");
879 number1," to ",number2," characters"); 861 return -1;
880 return -1;
881 } 862 }
882 } 863 }
883 864
884 if (!uis->result_buf) 865 if (!uis->result_buf) {
885 { 866 UIerr(UI_F_UI_SET_RESULT, UI_R_NO_RESULT_BUFFER);
886 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
887 return -1; 867 return -1;
888 } 868 }
889
890 BUF_strlcpy(uis->result_buf, result, 869 BUF_strlcpy(uis->result_buf, result,
891 uis->_.string_data.result_maxsize + 1); 870 uis->_.string_data.result_maxsize + 1);
892 break; 871 break;
893 case UIT_BOOLEAN: 872 case UIT_BOOLEAN:
894 { 873 {
895 const char *p; 874 const char *p;
896 875
897 if (!uis->result_buf) 876 if (!uis->result_buf) {
898 { 877 UIerr(UI_F_UI_SET_RESULT, UI_R_NO_RESULT_BUFFER);
899 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER); 878 return -1;
900 return -1;
901 } 879 }
902 880 uis->result_buf[0] = '\0';
903 uis->result_buf[0] = '\0'; 881 for (p = result; *p; p++) {
904 for(p = result; *p; p++) 882 if (strchr(uis->_.boolean_data.ok_chars, *p)) {
905 { 883 uis->result_buf[0] =
906 if (strchr(uis->_.boolean_data.ok_chars, *p)) 884 uis->_.boolean_data.ok_chars[0];
907 { 885 break;
908 uis->result_buf[0] =
909 uis->_.boolean_data.ok_chars[0];
910 break;
911 } 886 }
912 if (strchr(uis->_.boolean_data.cancel_chars, *p)) 887 if (strchr(uis->_.boolean_data.cancel_chars, *p)) {
913 { 888 uis->result_buf[0] =
914 uis->result_buf[0] = 889 uis->_.boolean_data.cancel_chars[0];
915 uis->_.boolean_data.cancel_chars[0]; 890 break;
916 break;
917 } 891 }
918 } 892 }
919 default: 893 default:
920 break; 894 break;
921 }
922 } 895 }
923 return 0;
924 } 896 }
897 return 0;
898}
diff --git a/src/lib/libssl/src/crypto/ui/ui_openssl.c b/src/lib/libssl/src/crypto/ui/ui_openssl.c
index 6000c24b1c..94a999baa8 100644
--- a/src/lib/libssl/src/crypto/ui/ui_openssl.c
+++ b/src/lib/libssl/src/crypto/ui/ui_openssl.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -63,21 +63,21 @@
63 * This package is an SSL implementation written 63 * This package is an SSL implementation written
64 * by Eric Young (eay@cryptsoft.com). 64 * by Eric Young (eay@cryptsoft.com).
65 * The implementation was written so as to conform with Netscapes SSL. 65 * The implementation was written so as to conform with Netscapes SSL.
66 * 66 *
67 * This library is free for commercial and non-commercial use as long as 67 * This library is free for commercial and non-commercial use as long as
68 * the following conditions are aheared to. The following conditions 68 * the following conditions are aheared to. The following conditions
69 * apply to all code found in this distribution, be it the RC4, RSA, 69 * apply to all code found in this distribution, be it the RC4, RSA,
70 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 70 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
71 * included with this distribution is covered by the same copyright terms 71 * included with this distribution is covered by the same copyright terms
72 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 72 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
73 * 73 *
74 * Copyright remains Eric Young's, and as such any Copyright notices in 74 * Copyright remains Eric Young's, and as such any Copyright notices in
75 * the code are not to be removed. 75 * the code are not to be removed.
76 * If this package is used in a product, Eric Young should be given attribution 76 * If this package is used in a product, Eric Young should be given attribution
77 * as the author of the parts of the library used. 77 * as the author of the parts of the library used.
78 * This can be in the form of a textual message at program startup or 78 * This can be in the form of a textual message at program startup or
79 * in documentation (online or textual) provided with the package. 79 * in documentation (online or textual) provided with the package.
80 * 80 *
81 * Redistribution and use in source and binary forms, with or without 81 * Redistribution and use in source and binary forms, with or without
82 * modification, are permitted provided that the following conditions 82 * modification, are permitted provided that the following conditions
83 * are met: 83 * are met:
@@ -92,10 +92,10 @@
92 * Eric Young (eay@cryptsoft.com)" 92 * Eric Young (eay@cryptsoft.com)"
93 * The word 'cryptographic' can be left out if the rouines from the library 93 * The word 'cryptographic' can be left out if the rouines from the library
94 * being used are not cryptographic related :-). 94 * being used are not cryptographic related :-).
95 * 4. If you include any Windows specific code (or a derivative thereof) from 95 * 4. If you include any Windows specific code (or a derivative thereof) from
96 * the apps directory (application code) you must include an acknowledgement: 96 * the apps directory (application code) you must include an acknowledgement:
97 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 97 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
98 * 98 *
99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -107,7 +107,7 @@
107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
109 * SUCH DAMAGE. 109 * SUCH DAMAGE.
110 * 110 *
111 * The licence and distribution terms for any publically available version or 111 * The licence and distribution terms for any publically available version or
112 * derivative of this code cannot be changed. i.e. this code cannot simply be 112 * derivative of this code cannot be changed. i.e. this code cannot simply be
113 * copied and put under another distribution licence 113 * copied and put under another distribution licence
@@ -125,14 +125,14 @@
125#include <unistd.h> 125#include <unistd.h>
126/* If unistd.h defines _POSIX_VERSION, we conclude that we 126/* If unistd.h defines _POSIX_VERSION, we conclude that we
127 * are on a POSIX system and have sigaction and termios. */ 127 * are on a POSIX system and have sigaction and termios. */
128# if defined(_POSIX_VERSION) 128#if defined(_POSIX_VERSION)
129 129
130# define SIGACTION 130#define SIGACTION
131# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY) 131#if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
132# define TERMIOS 132#define TERMIOS
133# endif 133#endif
134 134
135# endif 135#endif
136 136
137#include "ui_locl.h" 137#include "ui_locl.h"
138#include "cryptlib.h" 138#include "cryptlib.h"
@@ -143,31 +143,31 @@
143 */ 143 */
144 144
145#ifdef _LIBC 145#ifdef _LIBC
146# undef TERMIOS 146#undef TERMIOS
147# define TERMIO 147#define TERMIO
148# undef SGTTY 148#undef SGTTY
149#endif 149#endif
150 150
151#ifdef TERMIOS 151#ifdef TERMIOS
152# include <termios.h> 152#include <termios.h>
153# define TTY_STRUCT struct termios 153#define TTY_STRUCT struct termios
154# define TTY_FLAGS c_lflag 154#define TTY_FLAGS c_lflag
155# define TTY_get(tty,data) tcgetattr(tty,data) 155#define TTY_get(tty,data) tcgetattr(tty,data)
156# define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data) 156#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
157#endif 157#endif
158 158
159#ifdef TERMIO 159#ifdef TERMIO
160# include <termio.h> 160#include <termio.h>
161# define TTY_STRUCT struct termio 161#define TTY_STRUCT struct termio
162# define TTY_FLAGS c_lflag 162#define TTY_FLAGS c_lflag
163# define TTY_get(tty,data) ioctl(tty,TCGETA,data) 163#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
164# define TTY_set(tty,data) ioctl(tty,TCSETA,data) 164#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
165#endif 165#endif
166 166
167# include <sys/ioctl.h> 167#include <sys/ioctl.h>
168 168
169#ifndef NX509_SIG 169#ifndef NX509_SIG
170# define NX509_SIG 32 170#define NX509_SIG 32
171#endif 171#endif
172 172
173 173
@@ -175,10 +175,10 @@
175#ifdef SIGACTION 175#ifdef SIGACTION
176static struct sigaction savsig[NX509_SIG]; 176static struct sigaction savsig[NX509_SIG];
177#else 177#else
178static void (*savsig[NX509_SIG])(int ); 178static void (*savsig[NX509_SIG]) (int);
179#endif 179#endif
180 180
181static TTY_STRUCT tty_orig,tty_new; 181static TTY_STRUCT tty_orig, tty_new;
182static FILE *tty_in, *tty_out; 182static FILE *tty_in, *tty_out;
183static int is_a_tty; 183static int is_a_tty;
184 184
@@ -187,18 +187,18 @@ static int read_till_nl(FILE *);
187static void recsig(int); 187static void recsig(int);
188static void pushsig(void); 188static void pushsig(void);
189static void popsig(void); 189static void popsig(void);
190static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl); 190static int read_string_inner(UI * ui, UI_STRING * uis, int echo, int strip_nl);
191 191
192static int read_string(UI *ui, UI_STRING *uis); 192static int read_string(UI * ui, UI_STRING * uis);
193static int write_string(UI *ui, UI_STRING *uis); 193static int write_string(UI * ui, UI_STRING * uis);
194 194
195static int open_console(UI *ui); 195static int open_console(UI * ui);
196static int echo_console(UI *ui); 196static int echo_console(UI * ui);
197static int noecho_console(UI *ui); 197static int noecho_console(UI * ui);
198static int close_console(UI *ui); 198static int close_console(UI * ui);
199 199
200static UI_METHOD ui_openssl = 200static UI_METHOD ui_openssl =
201 { 201{
202 "OpenSSL default user interface", 202 "OpenSSL default user interface",
203 open_console, 203 open_console,
204 write_string, 204 write_string,
@@ -206,216 +206,226 @@ static UI_METHOD ui_openssl =
206 read_string, 206 read_string,
207 close_console, 207 close_console,
208 NULL 208 NULL
209 }; 209};
210 210
211/* The method with all the built-in thingies */ 211/* The method with all the built-in thingies */
212UI_METHOD *UI_OpenSSL(void) 212UI_METHOD *
213 { 213UI_OpenSSL(void)
214{
214 return &ui_openssl; 215 return &ui_openssl;
215 } 216}
216 217
217/* The following function makes sure that info and error strings are printed 218/* The following function makes sure that info and error strings are printed
218 before any prompt. */ 219 before any prompt. */
219static int write_string(UI *ui, UI_STRING *uis) 220static int
220 { 221write_string(UI * ui, UI_STRING * uis)
221 switch (UI_get_string_type(uis)) 222{
222 { 223 switch (UI_get_string_type(uis)) {
223 case UIT_ERROR: 224 case UIT_ERROR:
224 case UIT_INFO: 225 case UIT_INFO:
225 fputs(UI_get0_output_string(uis), tty_out); 226 fputs(UI_get0_output_string(uis), tty_out);
226 fflush(tty_out); 227 fflush(tty_out);
227 break; 228 break;
228 default: 229 default:
229 break; 230 break;
230 }
231 return 1;
232 } 231 }
232 return 1;
233}
233 234
234static int read_string(UI *ui, UI_STRING *uis) 235static int
235 { 236read_string(UI * ui, UI_STRING * uis)
237{
236 int ok = 0; 238 int ok = 0;
237 239
238 switch (UI_get_string_type(uis)) 240 switch (UI_get_string_type(uis)) {
239 {
240 case UIT_BOOLEAN: 241 case UIT_BOOLEAN:
241 fputs(UI_get0_output_string(uis), tty_out); 242 fputs(UI_get0_output_string(uis), tty_out);
242 fputs(UI_get0_action_string(uis), tty_out); 243 fputs(UI_get0_action_string(uis), tty_out);
243 fflush(tty_out); 244 fflush(tty_out);
244 return read_string_inner(ui, uis, 245 return read_string_inner(ui, uis,
245 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0); 246 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
246 case UIT_PROMPT: 247 case UIT_PROMPT:
247 fputs(UI_get0_output_string(uis), tty_out); 248 fputs(UI_get0_output_string(uis), tty_out);
248 fflush(tty_out); 249 fflush(tty_out);
249 return read_string_inner(ui, uis, 250 return read_string_inner(ui, uis,
250 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1); 251 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
251 case UIT_VERIFY: 252 case UIT_VERIFY:
252 fprintf(tty_out,"Verifying - %s", 253 fprintf(tty_out, "Verifying - %s",
253 UI_get0_output_string(uis)); 254 UI_get0_output_string(uis));
254 fflush(tty_out); 255 fflush(tty_out);
255 if ((ok = read_string_inner(ui, uis, 256 if ((ok = read_string_inner(ui, uis,
256 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0) 257 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
257 return ok; 258 return ok;
258 if (strcmp(UI_get0_result_string(uis), 259 if (strcmp(UI_get0_result_string(uis),
259 UI_get0_test_string(uis)) != 0) 260 UI_get0_test_string(uis)) != 0) {
260 { 261 fprintf(tty_out, "Verify failure\n");
261 fprintf(tty_out,"Verify failure\n");
262 fflush(tty_out); 262 fflush(tty_out);
263 return 0; 263 return 0;
264 } 264 }
265 break; 265 break;
266 default: 266 default:
267 break; 267 break;
268 }
269 return 1;
270 } 268 }
269 return 1;
270}
271 271
272 272
273/* Internal functions to read a string without echoing */ 273/* Internal functions to read a string without echoing */
274static int read_till_nl(FILE *in) 274static int
275 { 275read_till_nl(FILE * in)
276{
276#define SIZE 4 277#define SIZE 4
277 char buf[SIZE+1]; 278 char buf[SIZE + 1];
278 279
279 do { 280 do {
280 if (!fgets(buf,SIZE,in)) 281 if (!fgets(buf, SIZE, in))
281 return 0; 282 return 0;
282 } while (strchr(buf,'\n') == NULL); 283 } while (strchr(buf, '\n') == NULL);
283 return 1; 284 return 1;
284 } 285}
285 286
286static volatile sig_atomic_t intr_signal; 287static volatile sig_atomic_t intr_signal;
287 288
288static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) 289static int
289 { 290read_string_inner(UI * ui, UI_STRING * uis, int echo, int strip_nl)
291{
290 static int ps; 292 static int ps;
291 int ok; 293 int ok;
292 char result[BUFSIZ]; 294 char result[BUFSIZ];
293 int maxsize = BUFSIZ-1; 295 int maxsize = BUFSIZ - 1;
294 char *p; 296 char *p;
295 297
296 intr_signal=0; 298 intr_signal = 0;
297 ok=0; 299 ok = 0;
298 ps=0; 300 ps = 0;
299 301
300 pushsig(); 302 pushsig();
301 ps=1; 303 ps = 1;
302 304
303 if (!echo && !noecho_console(ui)) 305 if (!echo && !noecho_console(ui))
304 goto error; 306 goto error;
305 ps=2; 307 ps = 2;
306 308
307 result[0]='\0'; 309 result[0] = '\0';
308 p=fgets(result,maxsize,tty_in); 310 p = fgets(result, maxsize, tty_in);
309 if(!p) 311 if (!p)
310 goto error; 312 goto error;
311 if (feof(tty_in)) goto error; 313 if (feof(tty_in))
312 if (ferror(tty_in)) goto error; 314 goto error;
313 if ((p=(char *)strchr(result,'\n')) != NULL) 315 if (ferror(tty_in))
314 { 316 goto error;
317 if ((p = (char *) strchr(result, '\n')) != NULL) {
315 if (strip_nl) 318 if (strip_nl)
316 *p='\0'; 319 *p = '\0';
317 } 320 } else if (!read_till_nl(tty_in))
318 else 321 goto error;
319 if (!read_till_nl(tty_in))
320 goto error;
321 if (UI_set_result(ui, uis, result) >= 0) 322 if (UI_set_result(ui, uis, result) >= 0)
322 ok=1; 323 ok = 1;
323 324
324error: 325error:
325 if (intr_signal == SIGINT) 326 if (intr_signal == SIGINT)
326 ok=-1; 327 ok = -1;
327 if (!echo) fprintf(tty_out,"\n"); 328 if (!echo)
329 fprintf(tty_out, "\n");
328 if (ps >= 2 && !echo && !echo_console(ui)) 330 if (ps >= 2 && !echo && !echo_console(ui))
329 ok=0; 331 ok = 0;
330 332
331 if (ps >= 1) 333 if (ps >= 1)
332 popsig(); 334 popsig();
333 335
334 OPENSSL_cleanse(result,BUFSIZ); 336 OPENSSL_cleanse(result, BUFSIZ);
335 return ok; 337 return ok;
336 } 338}
337 339
338 340
339/* Internal functions to open, handle and close a channel to the console. */ 341/* Internal functions to open, handle and close a channel to the console. */
340static int open_console(UI *ui) 342static int
341 { 343open_console(UI * ui)
344{
342 CRYPTO_w_lock(CRYPTO_LOCK_UI); 345 CRYPTO_w_lock(CRYPTO_LOCK_UI);
343 is_a_tty = 1; 346 is_a_tty = 1;
344 347
345# define DEV_TTY "/dev/tty" 348#define DEV_TTY "/dev/tty"
346 if ((tty_in=fopen(DEV_TTY,"r")) == NULL) 349 if ((tty_in = fopen(DEV_TTY, "r")) == NULL)
347 tty_in=stdin; 350 tty_in = stdin;
348 if ((tty_out=fopen(DEV_TTY,"w")) == NULL) 351 if ((tty_out = fopen(DEV_TTY, "w")) == NULL)
349 tty_out=stderr; 352 tty_out = stderr;
350 353
351#if defined(TTY_get) 354#if defined(TTY_get)
352 if (TTY_get(fileno(tty_in),&tty_orig) == -1) 355 if (TTY_get(fileno(tty_in), &tty_orig) == -1) {
353 {
354 if (errno == ENOTTY) 356 if (errno == ENOTTY)
355 is_a_tty=0; 357 is_a_tty = 0;
356 else 358 else
357 /* Ariel Glenn ariel@columbia.edu reports that solaris 359 /*
358 * can return EINVAL instead. This should be ok */ 360 * Ariel Glenn ariel@columbia.edu reports that
361 * solaris can return EINVAL instead. This should be
362 * ok
363 */
359 if (errno == EINVAL) 364 if (errno == EINVAL)
360 is_a_tty=0; 365 is_a_tty = 0;
361 else 366 else
362 return 0; 367 return 0;
363 } 368 }
364#endif 369#endif
365 return 1; 370 return 1;
366 } 371}
367 372
368static int noecho_console(UI *ui) 373static int
369 { 374noecho_console(UI * ui)
375{
370#ifdef TTY_FLAGS 376#ifdef TTY_FLAGS
371 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); 377 memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
372 tty_new.TTY_FLAGS &= ~ECHO; 378 tty_new.TTY_FLAGS &= ~ECHO;
373#endif 379#endif
374 380
375#if defined(TTY_set) 381#if defined(TTY_set)
376 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) 382 if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
377 return 0; 383 return 0;
378#endif 384#endif
379 return 1; 385 return 1;
380 } 386}
381 387
382static int echo_console(UI *ui) 388static int
383 { 389echo_console(UI * ui)
390{
384#if defined(TTY_set) 391#if defined(TTY_set)
385 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); 392 memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
386 tty_new.TTY_FLAGS |= ECHO; 393 tty_new.TTY_FLAGS |= ECHO;
387#endif 394#endif
388 395
389#if defined(TTY_set) 396#if defined(TTY_set)
390 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) 397 if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
391 return 0; 398 return 0;
392#endif 399#endif
393 return 1; 400 return 1;
394 } 401}
395 402
396static int close_console(UI *ui) 403static int
397 { 404close_console(UI * ui)
398 if (tty_in != stdin) fclose(tty_in); 405{
399 if (tty_out != stderr) fclose(tty_out); 406 if (tty_in != stdin)
407 fclose(tty_in);
408 if (tty_out != stderr)
409 fclose(tty_out);
400 CRYPTO_w_unlock(CRYPTO_LOCK_UI); 410 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
401 411
402 return 1; 412 return 1;
403 } 413}
404 414
405 415
406/* Internal functions to handle signals and act on them */ 416/* Internal functions to handle signals and act on them */
407static void pushsig(void) 417static void
408 { 418pushsig(void)
419{
409 int i; 420 int i;
410#ifdef SIGACTION 421#ifdef SIGACTION
411 struct sigaction sa; 422 struct sigaction sa;
412 423
413 memset(&sa,0,sizeof sa); 424 memset(&sa, 0, sizeof sa);
414 sa.sa_handler=recsig; 425 sa.sa_handler = recsig;
415#endif 426#endif
416 427
417 for (i=1; i<NX509_SIG; i++) 428 for (i = 1; i < NX509_SIG; i++) {
418 {
419#ifdef SIGUSR1 429#ifdef SIGUSR1
420 if (i == SIGUSR1) 430 if (i == SIGUSR1)
421 continue; 431 continue;
@@ -425,39 +435,40 @@ static void pushsig(void)
425 continue; 435 continue;
426#endif 436#endif
427#ifdef SIGKILL 437#ifdef SIGKILL
428 if (i == SIGKILL) /* We can't make any action on that. */ 438 if (i == SIGKILL) /* We can't make any action on that. */
429 continue; 439 continue;
430#endif 440#endif
431#ifdef SIGACTION 441#ifdef SIGACTION
432 sigaction(i,&sa,&savsig[i]); 442 sigaction(i, &sa, &savsig[i]);
433#else 443#else
434 savsig[i]=signal(i,recsig); 444 savsig[i] = signal(i, recsig);
435#endif 445#endif
436 } 446 }
437 447
438#ifdef SIGWINCH 448#ifdef SIGWINCH
439 signal(SIGWINCH,SIG_DFL); 449 signal(SIGWINCH, SIG_DFL);
440#endif 450#endif
441 } 451}
442 452
443static void popsig(void) 453static void
444 { 454popsig(void)
455{
445 int i; 456 int i;
446 for (i=1; i<NX509_SIG; i++) 457 for (i = 1; i < NX509_SIG; i++) {
447 {
448 if (i == SIGUSR1) 458 if (i == SIGUSR1)
449 continue; 459 continue;
450 if (i == SIGUSR2) 460 if (i == SIGUSR2)
451 continue; 461 continue;
452#ifdef SIGACTION 462#ifdef SIGACTION
453 sigaction(i,&savsig[i],NULL); 463 sigaction(i, &savsig[i], NULL);
454#else 464#else
455 signal(i,savsig[i]); 465 signal(i, savsig[i]);
456#endif 466#endif
457 }
458 } 467 }
468}
459 469
460static void recsig(int i) 470static void
461 { 471recsig(int i)
462 intr_signal=i; 472{
463 } 473 intr_signal = i;
474}
diff --git a/src/lib/libssl/src/crypto/ui/ui_util.c b/src/lib/libssl/src/crypto/ui/ui_util.c
index 5d9760bb7b..af50451403 100644
--- a/src/lib/libssl/src/crypto/ui/ui_util.c
+++ b/src/lib/libssl/src/crypto/ui/ui_util.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -56,18 +56,20 @@
56#include <string.h> 56#include <string.h>
57#include "ui_locl.h" 57#include "ui_locl.h"
58 58
59int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify) 59int
60 { 60UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
61{
61 char buff[BUFSIZ]; 62 char buff[BUFSIZ];
62 int ret; 63 int ret;
63 64
64 ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); 65 ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length, prompt, verify);
65 OPENSSL_cleanse(buff,BUFSIZ); 66 OPENSSL_cleanse(buff, BUFSIZ);
66 return(ret); 67 return (ret);
67 } 68}
68 69
69int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify) 70int
70 { 71UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
72{
71 int ok = 0; 73 int ok = 0;
72 UI *ui; 74 UI *ui;
73 75
@@ -75,17 +77,16 @@ int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
75 return -1; 77 return -1;
76 78
77 ui = UI_new(); 79 ui = UI_new();
78 if (ui) 80 if (ui) {
79 { 81 ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1);
80 ok = UI_add_input_string(ui,prompt,0,buf,0,size-1);
81 if (ok >= 0 && verify) 82 if (ok >= 0 && verify)
82 ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1, 83 ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1,
83 buf); 84 buf);
84 if (ok >= 0) 85 if (ok >= 0)
85 ok=UI_process(ui); 86 ok = UI_process(ui);
86 UI_free(ui); 87 UI_free(ui);
87 } 88 }
88 if (ok > 0) 89 if (ok > 0)
89 ok = 0; 90 ok = 0;
90 return(ok); 91 return (ok);
91 } 92}