diff options
Diffstat (limited to 'src/lib/libcrypto/des/read_pwd.c')
-rw-r--r-- | src/lib/libcrypto/des/read_pwd.c | 218 |
1 files changed, 135 insertions, 83 deletions
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c index 99920f2f86..00000190f8 100644 --- a/src/lib/libcrypto/des/read_pwd.c +++ b/src/lib/libcrypto/des/read_pwd.c | |||
@@ -56,20 +56,55 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <openssl/e_os2.h> | ||
60 | #if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WIN32) | ||
61 | #ifdef OPENSSL_UNISTD | ||
62 | # include OPENSSL_UNISTD | ||
63 | #else | ||
64 | # include <unistd.h> | ||
65 | #endif | ||
66 | /* If unistd.h defines _POSIX_VERSION, we conclude that we | ||
67 | * are on a POSIX system and have sigaction and termios. */ | ||
68 | #if defined(_POSIX_VERSION) | ||
69 | |||
70 | # define SIGACTION | ||
71 | # if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY) | ||
72 | # define TERMIOS | ||
73 | # endif | ||
74 | |||
75 | #endif | ||
76 | #endif | ||
77 | |||
59 | /* #define SIGACTION */ /* Define this if you have sigaction() */ | 78 | /* #define SIGACTION */ /* Define this if you have sigaction() */ |
79 | |||
60 | #ifdef WIN16TTY | 80 | #ifdef WIN16TTY |
61 | #undef WIN16 | 81 | #undef OPENSSL_SYS_WIN16 |
62 | #undef _WINDOWS | 82 | #undef _WINDOWS |
63 | #include <graph.h> | 83 | #include <graph.h> |
64 | #endif | 84 | #endif |
65 | 85 | ||
66 | /* 06-Apr-92 Luke Brennan Support for VMS */ | 86 | /* 06-Apr-92 Luke Brennan Support for VMS */ |
67 | #include "des_locl.h" | 87 | #include "des_locl.h" |
88 | #include "cryptlib.h" | ||
68 | #include <signal.h> | 89 | #include <signal.h> |
90 | #include <stdio.h> | ||
69 | #include <string.h> | 91 | #include <string.h> |
70 | #include <setjmp.h> | 92 | #include <setjmp.h> |
71 | #include <errno.h> | 93 | #include <errno.h> |
72 | 94 | ||
95 | #ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */ | ||
96 | #include <starlet.h> | ||
97 | #ifdef __DECC | ||
98 | #pragma message disable DOLLARID | ||
99 | #endif | ||
100 | #endif | ||
101 | |||
102 | #ifdef WIN_CONSOLE_BUG | ||
103 | #include <windows.h> | ||
104 | #include <wincon.h> | ||
105 | #endif | ||
106 | |||
107 | |||
73 | /* There are 5 types of terminal interface supported, | 108 | /* There are 5 types of terminal interface supported, |
74 | * TERMIO, TERMIOS, VMS, MSDOS and SGTTY | 109 | * TERMIO, TERMIOS, VMS, MSDOS and SGTTY |
75 | */ | 110 | */ |
@@ -92,12 +127,18 @@ | |||
92 | #undef SGTTY | 127 | #undef SGTTY |
93 | #endif | 128 | #endif |
94 | 129 | ||
95 | #if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) | 130 | #if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(MAC_OS_pre_X) && !defined(MAC_OS_GUSI_SOURCE) |
96 | #undef TERMIOS | 131 | #undef TERMIOS |
97 | #undef TERMIO | 132 | #undef TERMIO |
98 | #define SGTTY | 133 | #define SGTTY |
99 | #endif | 134 | #endif |
100 | 135 | ||
136 | #if defined(OPENSSL_SYS_VSWORKS) | ||
137 | #undef TERMIOS | ||
138 | #undef TERMIO | ||
139 | #undef SGTTY | ||
140 | #endif | ||
141 | |||
101 | #ifdef TERMIOS | 142 | #ifdef TERMIOS |
102 | #include <termios.h> | 143 | #include <termios.h> |
103 | #define TTY_STRUCT struct termios | 144 | #define TTY_STRUCT struct termios |
@@ -122,16 +163,16 @@ | |||
122 | #define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) | 163 | #define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) |
123 | #endif | 164 | #endif |
124 | 165 | ||
125 | #if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS) | 166 | #if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(MAC_OS_pre_X) |
126 | #include <sys/ioctl.h> | 167 | #include <sys/ioctl.h> |
127 | #endif | 168 | #endif |
128 | 169 | ||
129 | #ifdef MSDOS | 170 | #if defined(OPENSSL_SYS_MSDOS) && !defined(__CYGWIN32__) |
130 | #include <conio.h> | 171 | #include <conio.h> |
131 | #define fgets(a,b,c) noecho_fgets(a,b,c) | 172 | #define fgets(a,b,c) noecho_fgets(a,b,c) |
132 | #endif | 173 | #endif |
133 | 174 | ||
134 | #ifdef VMS | 175 | #ifdef OPENSSL_SYS_VMS |
135 | #include <ssdef.h> | 176 | #include <ssdef.h> |
136 | #include <iodef.h> | 177 | #include <iodef.h> |
137 | #include <ttdef.h> | 178 | #include <ttdef.h> |
@@ -143,44 +184,35 @@ struct IOSB { | |||
143 | }; | 184 | }; |
144 | #endif | 185 | #endif |
145 | 186 | ||
187 | #if defined(MAC_OS_pre_X) || defined(MAC_OS_GUSI_SOURCE) | ||
188 | /* | ||
189 | * This one needs work. As a matter of fact the code is unoperational | ||
190 | * and this is only a trick to get it compiled. | ||
191 | * <appro@fy.chalmers.se> | ||
192 | */ | ||
193 | #define TTY_STRUCT int | ||
194 | #endif | ||
195 | |||
146 | #ifndef NX509_SIG | 196 | #ifndef NX509_SIG |
147 | #define NX509_SIG 32 | 197 | #define NX509_SIG 32 |
148 | #endif | 198 | #endif |
149 | 199 | ||
150 | #ifndef NOPROTO | ||
151 | static void read_till_nl(FILE *); | 200 | static void read_till_nl(FILE *); |
152 | static void recsig(int); | 201 | static void recsig(int); |
153 | static void pushsig(void); | 202 | static void pushsig(void); |
154 | static void popsig(void); | 203 | static void popsig(void); |
155 | #if defined(MSDOS) && !defined(WIN16) | 204 | #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) |
156 | static int noecho_fgets(char *buf, int size, FILE *tty); | 205 | static int noecho_fgets(char *buf, int size, FILE *tty); |
157 | #endif | 206 | #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 | 207 | #ifdef SIGACTION |
169 | static struct sigaction savsig[NX509_SIG]; | 208 | static struct sigaction savsig[NX509_SIG]; |
170 | #else | 209 | #else |
171 | # ifndef NOPROTO | ||
172 | static void (*savsig[NX509_SIG])(int ); | 210 | static void (*savsig[NX509_SIG])(int ); |
173 | # else | ||
174 | static void (*savsig[NX509_SIG])(); | ||
175 | # endif | ||
176 | #endif | 211 | #endif |
177 | static jmp_buf save; | 212 | static jmp_buf save; |
178 | 213 | ||
179 | int des_read_pw_string(buf, length, prompt, verify) | 214 | int des_read_pw_string(char *buf, int length, const char *prompt, |
180 | char *buf; | 215 | int verify) |
181 | int length; | ||
182 | char *prompt; | ||
183 | int verify; | ||
184 | { | 216 | { |
185 | char buff[BUFSIZ]; | 217 | char buff[BUFSIZ]; |
186 | int ret; | 218 | int ret; |
@@ -190,10 +222,9 @@ int verify; | |||
190 | return(ret); | 222 | return(ret); |
191 | } | 223 | } |
192 | 224 | ||
193 | #ifndef WIN16 | 225 | #ifndef OPENSSL_SYS_WIN16 |
194 | 226 | ||
195 | static void read_till_nl(in) | 227 | static void read_till_nl(FILE *in) |
196 | FILE *in; | ||
197 | { | 228 | { |
198 | #define SIZE 4 | 229 | #define SIZE 4 |
199 | char buf[SIZE+1]; | 230 | char buf[SIZE+1]; |
@@ -205,41 +236,54 @@ FILE *in; | |||
205 | 236 | ||
206 | 237 | ||
207 | /* return 0 if ok, 1 (or -1) otherwise */ | 238 | /* return 0 if ok, 1 (or -1) otherwise */ |
208 | int des_read_pw(buf, buff, size, prompt, verify) | 239 | int des_read_pw(char *buf, char *buff, int size, const char *prompt, |
209 | char *buf; | 240 | int verify) |
210 | char *buff; | ||
211 | int size; | ||
212 | char *prompt; | ||
213 | int verify; | ||
214 | { | 241 | { |
215 | #ifdef VMS | 242 | #ifdef OPENSSL_SYS_VMS |
216 | struct IOSB iosb; | 243 | struct IOSB iosb; |
217 | $DESCRIPTOR(terminal,"TT"); | 244 | $DESCRIPTOR(terminal,"TT"); |
218 | long tty_orig[3], tty_new[3]; | 245 | long tty_orig[3], tty_new[3]; |
219 | long status; | 246 | long status; |
220 | unsigned short channel = 0; | 247 | unsigned short channel = 0; |
221 | #else | 248 | #else |
222 | #ifndef MSDOS | 249 | #ifndef OPENSSL_SYS_MSDOS |
223 | TTY_STRUCT tty_orig,tty_new; | 250 | TTY_STRUCT tty_orig,tty_new; |
224 | #endif | 251 | #endif |
225 | #endif | 252 | #endif |
226 | int number=5; | 253 | int number; |
227 | int ok=0; | 254 | int ok; |
228 | int ps=0; | 255 | /* statics are simply to avoid warnings about longjmp clobbering |
229 | int is_a_tty=1; | 256 | things */ |
230 | 257 | static int ps; | |
231 | FILE *tty=NULL; | 258 | int is_a_tty; |
259 | static FILE *tty; | ||
232 | char *p; | 260 | char *p; |
233 | 261 | ||
234 | #ifndef MSDOS | 262 | if (setjmp(save)) |
235 | if ((tty=fopen("/dev/tty","r")) == NULL) | 263 | { |
236 | tty=stdin; | 264 | ok=0; |
237 | #else /* MSDOS */ | 265 | goto error; |
266 | } | ||
267 | |||
268 | number=5; | ||
269 | ok=0; | ||
270 | ps=0; | ||
271 | is_a_tty=1; | ||
272 | tty=NULL; | ||
273 | |||
274 | #ifdef OPENSSL_SYS_MSDOS | ||
238 | if ((tty=fopen("con","r")) == NULL) | 275 | if ((tty=fopen("con","r")) == NULL) |
239 | tty=stdin; | 276 | tty=stdin; |
240 | #endif /* MSDOS */ | 277 | #elif defined(MAC_OS_pre_X) || defined(OPENSSL_SYS_VSWORKS) |
278 | tty=stdin; | ||
279 | #else | ||
280 | #ifndef OPENSSL_SYS_MPE | ||
281 | if ((tty=fopen("/dev/tty","r")) == NULL) | ||
282 | #endif | ||
283 | tty=stdin; | ||
284 | #endif | ||
241 | 285 | ||
242 | #if defined(TTY_get) && !defined(VMS) | 286 | #if defined(TTY_get) && !defined(OPENSSL_SYS_VMS) |
243 | if (TTY_get(fileno(tty),&tty_orig) == -1) | 287 | if (TTY_get(fileno(tty),&tty_orig) == -1) |
244 | { | 288 | { |
245 | #ifdef ENOTTY | 289 | #ifdef ENOTTY |
@@ -258,20 +302,15 @@ int verify; | |||
258 | } | 302 | } |
259 | memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); | 303 | memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); |
260 | #endif | 304 | #endif |
261 | #ifdef VMS | 305 | #ifdef OPENSSL_SYS_VMS |
262 | status = SYS$ASSIGN(&terminal,&channel,0,0); | 306 | status = sys$assign(&terminal,&channel,0,0); |
263 | if (status != SS$_NORMAL) | 307 | if (status != SS$_NORMAL) |
264 | return(-1); | 308 | return(-1); |
265 | status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); | 309 | 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)) | 310 | if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) |
267 | return(-1); | 311 | return(-1); |
268 | #endif | 312 | #endif |
269 | 313 | ||
270 | if (setjmp(save)) | ||
271 | { | ||
272 | ok=0; | ||
273 | goto error; | ||
274 | } | ||
275 | pushsig(); | 314 | pushsig(); |
276 | ps=1; | 315 | ps=1; |
277 | 316 | ||
@@ -279,15 +318,19 @@ int verify; | |||
279 | tty_new.TTY_FLAGS &= ~ECHO; | 318 | tty_new.TTY_FLAGS &= ~ECHO; |
280 | #endif | 319 | #endif |
281 | 320 | ||
282 | #if defined(TTY_set) && !defined(VMS) | 321 | #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) |
283 | if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1)) | 322 | if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1)) |
323 | #ifdef OPENSSL_SYS_MPE | ||
324 | ; /* MPE lies -- echo really has been disabled */ | ||
325 | #else | ||
284 | return(-1); | 326 | return(-1); |
285 | #endif | 327 | #endif |
286 | #ifdef VMS | 328 | #endif |
329 | #ifdef OPENSSL_SYS_VMS | ||
287 | tty_new[0] = tty_orig[0]; | 330 | tty_new[0] = tty_orig[0]; |
288 | tty_new[1] = tty_orig[1] | TT$M_NOECHO; | 331 | tty_new[1] = tty_orig[1] | TT$M_NOECHO; |
289 | tty_new[2] = tty_orig[2]; | 332 | tty_new[2] = tty_orig[2]; |
290 | status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); | 333 | 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)) | 334 | if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) |
292 | return(-1); | 335 | return(-1); |
293 | #endif | 336 | #endif |
@@ -329,35 +372,30 @@ int verify; | |||
329 | 372 | ||
330 | error: | 373 | error: |
331 | fprintf(stderr,"\n"); | 374 | fprintf(stderr,"\n"); |
332 | #ifdef DEBUG | 375 | #if 0 |
333 | perror("fgets(tty)"); | 376 | perror("fgets(tty)"); |
334 | #endif | 377 | #endif |
335 | /* What can we do if there is an error? */ | 378 | /* What can we do if there is an error? */ |
336 | #if defined(TTY_set) && !defined(VMS) | 379 | #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) |
337 | if (ps >= 2) TTY_set(fileno(tty),&tty_orig); | 380 | if (ps >= 2) TTY_set(fileno(tty),&tty_orig); |
338 | #endif | 381 | #endif |
339 | #ifdef VMS | 382 | #ifdef OPENSSL_SYS_VMS |
340 | if (ps >= 2) | 383 | if (ps >= 2) |
341 | status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0 | 384 | status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0 |
342 | ,tty_orig,12,0,0,0,0); | 385 | ,tty_orig,12,0,0,0,0); |
343 | #endif | 386 | #endif |
344 | 387 | ||
345 | if (ps >= 1) popsig(); | 388 | if (ps >= 1) popsig(); |
346 | if (stdin != tty) fclose(tty); | 389 | if (stdin != tty) fclose(tty); |
347 | #ifdef VMS | 390 | #ifdef OPENSSL_SYS_VMS |
348 | status = SYS$DASSGN(channel); | 391 | status = sys$dassgn(channel); |
349 | #endif | 392 | #endif |
350 | return(!ok); | 393 | return(!ok); |
351 | } | 394 | } |
352 | 395 | ||
353 | #else /* WIN16 */ | 396 | #else /* OPENSSL_SYS_WIN16 */ |
354 | 397 | ||
355 | int des_read_pw(buf, buff, size, prompt, verify) | 398 | 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 | { | 399 | { |
362 | memset(buf,0,size); | 400 | memset(buf,0,size); |
363 | memset(buff,0,size); | 401 | memset(buff,0,size); |
@@ -366,9 +404,15 @@ int verify; | |||
366 | 404 | ||
367 | #endif | 405 | #endif |
368 | 406 | ||
369 | static void pushsig() | 407 | static void pushsig(void) |
370 | { | 408 | { |
371 | int i; | 409 | int i; |
410 | #ifdef SIGACTION | ||
411 | struct sigaction sa; | ||
412 | |||
413 | memset(&sa,0,sizeof sa); | ||
414 | sa.sa_handler=recsig; | ||
415 | #endif | ||
372 | 416 | ||
373 | for (i=1; i<NX509_SIG; i++) | 417 | for (i=1; i<NX509_SIG; i++) |
374 | { | 418 | { |
@@ -381,7 +425,7 @@ static void pushsig() | |||
381 | continue; | 425 | continue; |
382 | #endif | 426 | #endif |
383 | #ifdef SIGACTION | 427 | #ifdef SIGACTION |
384 | sigaction(i,NULL,&savsig[i]); | 428 | sigaction(i,&sa,&savsig[i]); |
385 | #else | 429 | #else |
386 | savsig[i]=signal(i,recsig); | 430 | savsig[i]=signal(i,recsig); |
387 | #endif | 431 | #endif |
@@ -392,7 +436,7 @@ static void pushsig() | |||
392 | #endif | 436 | #endif |
393 | } | 437 | } |
394 | 438 | ||
395 | static void popsig() | 439 | static void popsig(void) |
396 | { | 440 | { |
397 | int i; | 441 | int i; |
398 | 442 | ||
@@ -414,8 +458,7 @@ static void popsig() | |||
414 | } | 458 | } |
415 | } | 459 | } |
416 | 460 | ||
417 | static void recsig(i) | 461 | static void recsig(int i) |
418 | int i; | ||
419 | { | 462 | { |
420 | longjmp(save,1); | 463 | longjmp(save,1); |
421 | #ifdef LINT | 464 | #ifdef LINT |
@@ -423,11 +466,8 @@ int i; | |||
423 | #endif | 466 | #endif |
424 | } | 467 | } |
425 | 468 | ||
426 | #if defined(MSDOS) && !defined(WIN16) | 469 | #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) |
427 | static int noecho_fgets(buf,size,tty) | 470 | static int noecho_fgets(char *buf, int size, FILE *tty) |
428 | char *buf; | ||
429 | int size; | ||
430 | FILE *tty; | ||
431 | { | 471 | { |
432 | int i; | 472 | int i; |
433 | char *p; | 473 | char *p; |
@@ -454,6 +494,18 @@ FILE *tty; | |||
454 | break; | 494 | break; |
455 | } | 495 | } |
456 | } | 496 | } |
497 | #ifdef WIN_CONSOLE_BUG | ||
498 | /* Win95 has several evil console bugs: one of these is that the | ||
499 | * last character read using getch() is passed to the next read: this is | ||
500 | * usually a CR so this can be trouble. No STDIO fix seems to work but | ||
501 | * flushing the console appears to do the trick. | ||
502 | */ | ||
503 | { | ||
504 | HANDLE inh; | ||
505 | inh = GetStdHandle(STD_INPUT_HANDLE); | ||
506 | FlushConsoleInputBuffer(inh); | ||
507 | } | ||
508 | #endif | ||
457 | return(strlen(buf)); | 509 | return(strlen(buf)); |
458 | } | 510 | } |
459 | #endif | 511 | #endif |