diff options
Diffstat (limited to 'src/lib/libssl/src/crypto/des/read_pwd.c')
-rw-r--r-- | src/lib/libssl/src/crypto/des/read_pwd.c | 145 |
1 files changed, 85 insertions, 60 deletions
diff --git a/src/lib/libssl/src/crypto/des/read_pwd.c b/src/lib/libssl/src/crypto/des/read_pwd.c index 99920f2f86..fed49652c0 100644 --- a/src/lib/libssl/src/crypto/des/read_pwd.c +++ b/src/lib/libssl/src/crypto/des/read_pwd.c | |||
@@ -56,7 +56,23 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) | ||
60 | #include <openssl/opensslconf.h> | ||
61 | #include OPENSSL_UNISTD | ||
62 | /* If unistd.h defines _POSIX_VERSION, we conclude that we | ||
63 | * are on a POSIX system and have sigaction and termios. */ | ||
64 | #if defined(_POSIX_VERSION) | ||
65 | |||
66 | # define SIGACTION | ||
67 | # if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY) | ||
68 | # define TERMIOS | ||
69 | # endif | ||
70 | |||
71 | #endif | ||
72 | #endif | ||
73 | |||
59 | /* #define SIGACTION */ /* Define this if you have sigaction() */ | 74 | /* #define SIGACTION */ /* Define this if you have sigaction() */ |
75 | |||
60 | #ifdef WIN16TTY | 76 | #ifdef WIN16TTY |
61 | #undef WIN16 | 77 | #undef WIN16 |
62 | #undef _WINDOWS | 78 | #undef _WINDOWS |
@@ -65,11 +81,26 @@ | |||
65 | 81 | ||
66 | /* 06-Apr-92 Luke Brennan Support for VMS */ | 82 | /* 06-Apr-92 Luke Brennan Support for VMS */ |
67 | #include "des_locl.h" | 83 | #include "des_locl.h" |
84 | #include "cryptlib.h" | ||
68 | #include <signal.h> | 85 | #include <signal.h> |
86 | #include <stdio.h> | ||
69 | #include <string.h> | 87 | #include <string.h> |
70 | #include <setjmp.h> | 88 | #include <setjmp.h> |
71 | #include <errno.h> | 89 | #include <errno.h> |
72 | 90 | ||
91 | #ifdef VMS /* prototypes for sys$whatever */ | ||
92 | #include <starlet.h> | ||
93 | #ifdef __DECC | ||
94 | #pragma message disable DOLLARID | ||
95 | #endif | ||
96 | #endif | ||
97 | |||
98 | #ifdef WIN_CONSOLE_BUG | ||
99 | #include <windows.h> | ||
100 | #include <wincon.h> | ||
101 | #endif | ||
102 | |||
103 | |||
73 | /* There are 5 types of terminal interface supported, | 104 | /* There are 5 types of terminal interface supported, |
74 | * TERMIO, TERMIOS, VMS, MSDOS and SGTTY | 105 | * TERMIO, TERMIOS, VMS, MSDOS and SGTTY |
75 | */ | 106 | */ |
@@ -147,7 +178,6 @@ struct IOSB { | |||
147 | #define NX509_SIG 32 | 178 | #define NX509_SIG 32 |
148 | #endif | 179 | #endif |
149 | 180 | ||
150 | #ifndef NOPROTO | ||
151 | static void read_till_nl(FILE *); | 181 | static void read_till_nl(FILE *); |
152 | static void recsig(int); | 182 | static void recsig(int); |
153 | static void pushsig(void); | 183 | static void pushsig(void); |
@@ -155,32 +185,15 @@ static void popsig(void); | |||
155 | #if defined(MSDOS) && !defined(WIN16) | 185 | #if defined(MSDOS) && !defined(WIN16) |
156 | static int noecho_fgets(char *buf, int size, FILE *tty); | 186 | static int noecho_fgets(char *buf, int size, FILE *tty); |
157 | #endif | 187 | #endif |
158 | #else | ||
159 | static void read_till_nl(); | ||
160 | static void recsig(); | ||
161 | static void pushsig(); | ||
162 | static void popsig(); | ||
163 | #if defined(MSDOS) && !defined(WIN16) | ||
164 | static int noecho_fgets(); | ||
165 | #endif | ||
166 | #endif | ||
167 | |||
168 | #ifdef SIGACTION | 188 | #ifdef SIGACTION |
169 | static struct sigaction savsig[NX509_SIG]; | 189 | static struct sigaction savsig[NX509_SIG]; |
170 | #else | 190 | #else |
171 | # ifndef NOPROTO | ||
172 | static void (*savsig[NX509_SIG])(int ); | 191 | static void (*savsig[NX509_SIG])(int ); |
173 | # else | ||
174 | static void (*savsig[NX509_SIG])(); | ||
175 | # endif | ||
176 | #endif | 192 | #endif |
177 | static jmp_buf save; | 193 | static jmp_buf save; |
178 | 194 | ||
179 | int des_read_pw_string(buf, length, prompt, verify) | 195 | int des_read_pw_string(char *buf, int length, const char *prompt, |
180 | char *buf; | 196 | int verify) |
181 | int length; | ||
182 | char *prompt; | ||
183 | int verify; | ||
184 | { | 197 | { |
185 | char buff[BUFSIZ]; | 198 | char buff[BUFSIZ]; |
186 | int ret; | 199 | int ret; |
@@ -192,8 +205,7 @@ int verify; | |||
192 | 205 | ||
193 | #ifndef WIN16 | 206 | #ifndef WIN16 |
194 | 207 | ||
195 | static void read_till_nl(in) | 208 | static void read_till_nl(FILE *in) |
196 | FILE *in; | ||
197 | { | 209 | { |
198 | #define SIZE 4 | 210 | #define SIZE 4 |
199 | char buf[SIZE+1]; | 211 | char buf[SIZE+1]; |
@@ -205,12 +217,8 @@ FILE *in; | |||
205 | 217 | ||
206 | 218 | ||
207 | /* return 0 if ok, 1 (or -1) otherwise */ | 219 | /* return 0 if ok, 1 (or -1) otherwise */ |
208 | int des_read_pw(buf, buff, size, prompt, verify) | 220 | int des_read_pw(char *buf, char *buff, int size, const char *prompt, |
209 | char *buf; | 221 | int verify) |
210 | char *buff; | ||
211 | int size; | ||
212 | char *prompt; | ||
213 | int verify; | ||
214 | { | 222 | { |
215 | #ifdef VMS | 223 | #ifdef VMS |
216 | struct IOSB iosb; | 224 | struct IOSB iosb; |
@@ -223,14 +231,27 @@ int verify; | |||
223 | TTY_STRUCT tty_orig,tty_new; | 231 | TTY_STRUCT tty_orig,tty_new; |
224 | #endif | 232 | #endif |
225 | #endif | 233 | #endif |
226 | int number=5; | 234 | int number; |
227 | int ok=0; | 235 | int ok; |
228 | int ps=0; | 236 | /* statics are simply to avoid warnings about longjmp clobbering |
229 | int is_a_tty=1; | 237 | things */ |
230 | 238 | static int ps; | |
231 | FILE *tty=NULL; | 239 | int is_a_tty; |
240 | static FILE *tty; | ||
232 | char *p; | 241 | char *p; |
233 | 242 | ||
243 | if (setjmp(save)) | ||
244 | { | ||
245 | ok=0; | ||
246 | goto error; | ||
247 | } | ||
248 | |||
249 | number=5; | ||
250 | ok=0; | ||
251 | ps=0; | ||
252 | is_a_tty=1; | ||
253 | tty=NULL; | ||
254 | |||
234 | #ifndef MSDOS | 255 | #ifndef MSDOS |
235 | if ((tty=fopen("/dev/tty","r")) == NULL) | 256 | if ((tty=fopen("/dev/tty","r")) == NULL) |
236 | tty=stdin; | 257 | tty=stdin; |
@@ -259,19 +280,14 @@ int verify; | |||
259 | memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); | 280 | memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); |
260 | #endif | 281 | #endif |
261 | #ifdef VMS | 282 | #ifdef VMS |
262 | status = SYS$ASSIGN(&terminal,&channel,0,0); | 283 | status = sys$assign(&terminal,&channel,0,0); |
263 | if (status != SS$_NORMAL) | 284 | if (status != SS$_NORMAL) |
264 | return(-1); | 285 | return(-1); |
265 | status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); | 286 | status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); |
266 | if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) | 287 | if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) |
267 | return(-1); | 288 | return(-1); |
268 | #endif | 289 | #endif |
269 | 290 | ||
270 | if (setjmp(save)) | ||
271 | { | ||
272 | ok=0; | ||
273 | goto error; | ||
274 | } | ||
275 | pushsig(); | 291 | pushsig(); |
276 | ps=1; | 292 | ps=1; |
277 | 293 | ||
@@ -287,7 +303,7 @@ int verify; | |||
287 | tty_new[0] = tty_orig[0]; | 303 | tty_new[0] = tty_orig[0]; |
288 | tty_new[1] = tty_orig[1] | TT$M_NOECHO; | 304 | tty_new[1] = tty_orig[1] | TT$M_NOECHO; |
289 | tty_new[2] = tty_orig[2]; | 305 | tty_new[2] = tty_orig[2]; |
290 | status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); | 306 | status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); |
291 | if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) | 307 | if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) |
292 | return(-1); | 308 | return(-1); |
293 | #endif | 309 | #endif |
@@ -333,31 +349,26 @@ error: | |||
333 | perror("fgets(tty)"); | 349 | perror("fgets(tty)"); |
334 | #endif | 350 | #endif |
335 | /* What can we do if there is an error? */ | 351 | /* What can we do if there is an error? */ |
336 | #if defined(TTY_set) && !defined(VMS) | 352 | #if defined(TTY_set) && !defined(VMS) |
337 | if (ps >= 2) TTY_set(fileno(tty),&tty_orig); | 353 | if (ps >= 2) TTY_set(fileno(tty),&tty_orig); |
338 | #endif | 354 | #endif |
339 | #ifdef VMS | 355 | #ifdef VMS |
340 | if (ps >= 2) | 356 | if (ps >= 2) |
341 | status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0 | 357 | status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0 |
342 | ,tty_orig,12,0,0,0,0); | 358 | ,tty_orig,12,0,0,0,0); |
343 | #endif | 359 | #endif |
344 | 360 | ||
345 | if (ps >= 1) popsig(); | 361 | if (ps >= 1) popsig(); |
346 | if (stdin != tty) fclose(tty); | 362 | if (stdin != tty) fclose(tty); |
347 | #ifdef VMS | 363 | #ifdef VMS |
348 | status = SYS$DASSGN(channel); | 364 | status = sys$dassgn(channel); |
349 | #endif | 365 | #endif |
350 | return(!ok); | 366 | return(!ok); |
351 | } | 367 | } |
352 | 368 | ||
353 | #else /* WIN16 */ | 369 | #else /* WIN16 */ |
354 | 370 | ||
355 | int des_read_pw(buf, buff, size, prompt, verify) | 371 | int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify) |
356 | char *buf; | ||
357 | char *buff; | ||
358 | int size; | ||
359 | char *prompt; | ||
360 | int verify; | ||
361 | { | 372 | { |
362 | memset(buf,0,size); | 373 | memset(buf,0,size); |
363 | memset(buff,0,size); | 374 | memset(buff,0,size); |
@@ -366,9 +377,15 @@ int verify; | |||
366 | 377 | ||
367 | #endif | 378 | #endif |
368 | 379 | ||
369 | static void pushsig() | 380 | static void pushsig(void) |
370 | { | 381 | { |
371 | int i; | 382 | int i; |
383 | #ifdef SIGACTION | ||
384 | struct sigaction sa; | ||
385 | |||
386 | memset(&sa,0,sizeof sa); | ||
387 | sa.sa_handler=recsig; | ||
388 | #endif | ||
372 | 389 | ||
373 | for (i=1; i<NX509_SIG; i++) | 390 | for (i=1; i<NX509_SIG; i++) |
374 | { | 391 | { |
@@ -381,7 +398,7 @@ static void pushsig() | |||
381 | continue; | 398 | continue; |
382 | #endif | 399 | #endif |
383 | #ifdef SIGACTION | 400 | #ifdef SIGACTION |
384 | sigaction(i,NULL,&savsig[i]); | 401 | sigaction(i,&sa,&savsig[i]); |
385 | #else | 402 | #else |
386 | savsig[i]=signal(i,recsig); | 403 | savsig[i]=signal(i,recsig); |
387 | #endif | 404 | #endif |
@@ -392,7 +409,7 @@ static void pushsig() | |||
392 | #endif | 409 | #endif |
393 | } | 410 | } |
394 | 411 | ||
395 | static void popsig() | 412 | static void popsig(void) |
396 | { | 413 | { |
397 | int i; | 414 | int i; |
398 | 415 | ||
@@ -414,8 +431,7 @@ static void popsig() | |||
414 | } | 431 | } |
415 | } | 432 | } |
416 | 433 | ||
417 | static void recsig(i) | 434 | static void recsig(int i) |
418 | int i; | ||
419 | { | 435 | { |
420 | longjmp(save,1); | 436 | longjmp(save,1); |
421 | #ifdef LINT | 437 | #ifdef LINT |
@@ -424,10 +440,7 @@ int i; | |||
424 | } | 440 | } |
425 | 441 | ||
426 | #if defined(MSDOS) && !defined(WIN16) | 442 | #if defined(MSDOS) && !defined(WIN16) |
427 | static int noecho_fgets(buf,size,tty) | 443 | static int noecho_fgets(char *buf, int size, FILE *tty) |
428 | char *buf; | ||
429 | int size; | ||
430 | FILE *tty; | ||
431 | { | 444 | { |
432 | int i; | 445 | int i; |
433 | char *p; | 446 | char *p; |
@@ -454,6 +467,18 @@ FILE *tty; | |||
454 | break; | 467 | break; |
455 | } | 468 | } |
456 | } | 469 | } |
470 | #ifdef WIN_CONSOLE_BUG | ||
471 | /* Win95 has several evil console bugs: one of these is that the | ||
472 | * last character read using getch() is passed to the next read: this is | ||
473 | * usually a CR so this can be trouble. No STDIO fix seems to work but | ||
474 | * flushing the console appears to do the trick. | ||
475 | */ | ||
476 | { | ||
477 | HANDLE inh; | ||
478 | inh = GetStdHandle(STD_INPUT_HANDLE); | ||
479 | FlushConsoleInputBuffer(inh); | ||
480 | } | ||
481 | #endif | ||
457 | return(strlen(buf)); | 482 | return(strlen(buf)); |
458 | } | 483 | } |
459 | #endif | 484 | #endif |