summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortedu <>2014-04-16 17:55:34 +0000
committertedu <>2014-04-16 17:55:34 +0000
commit2a02c4f91789a07715ed68ed2af2782ad52c815a (patch)
tree1ffa0c6dcc9924c7b89c4cd991a12546ac2c4bdd
parent80df2005d14af067c12bee6b5c4c382edaa97edb (diff)
downloadopenbsd-2a02c4f91789a07715ed68ed2af2782ad52c815a.tar.gz
openbsd-2a02c4f91789a07715ed68ed2af2782ad52c815a.tar.bz2
openbsd-2a02c4f91789a07715ed68ed2af2782ad52c815a.zip
whack the ifdef pinata:
OPENSSL_SYSNAME_VXWORKS OPENSSL_SYS_VMS OPENSSL_SYS_MSDOS OPENSSL_UNISTD OPENSSL_SYS_WIN16 WIN_CONSOLE_BUG OPENSSL_SYS_WINCE SGTTY OPENSSL_SYS_MACINTOSH_CLASSIC MAC_OS_GUSI_SOURCE OPENSSL_SYS_NETWARE OPENSSL_SYS_SUNOS __DJGPP__ OPENSSL_SYS_BEOS OPENSSL_SYS_WIN32
-rw-r--r--src/lib/libcrypto/ui/ui_openssl.c265
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_openssl.c265
2 files changed, 10 insertions, 520 deletions
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c
index a38c7581e6..6000c24b1c 100644
--- a/src/lib/libcrypto/ui/ui_openssl.c
+++ b/src/lib/libcrypto/ui/ui_openssl.c
@@ -117,31 +117,12 @@
117 117
118#include <openssl/e_os2.h> 118#include <openssl/e_os2.h>
119 119
120/* need for #define _POSIX_C_SOURCE arises whenever you pass -ansi to gcc
121 * [maybe others?], because it masks interfaces not discussed in standard,
122 * sigaction and fileno included. -pedantic would be more appropriate for
123 * the intended purposes, but we can't prevent users from adding -ansi.
124 */
125#if defined(OPENSSL_SYSNAME_VXWORKS)
126#include <sys/types.h>
127#endif
128
129#if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS)
130#ifndef _POSIX_C_SOURCE
131#define _POSIX_C_SOURCE 2
132#endif
133#endif
134#include <signal.h> 120#include <signal.h>
135#include <stdio.h> 121#include <stdio.h>
136#include <string.h> 122#include <string.h>
137#include <errno.h> 123#include <errno.h>
138 124
139#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) 125#include <unistd.h>
140# ifdef OPENSSL_UNISTD
141# include OPENSSL_UNISTD
142# else
143# include <unistd.h>
144# endif
145/* If unistd.h defines _POSIX_VERSION, we conclude that we 126/* If unistd.h defines _POSIX_VERSION, we conclude that we
146 * are on a POSIX system and have sigaction and termios. */ 127 * are on a POSIX system and have sigaction and termios. */
147# if defined(_POSIX_VERSION) 128# if defined(_POSIX_VERSION)
@@ -152,74 +133,21 @@
152# endif 133# endif
153 134
154# endif 135# endif
155#endif
156 136
157#ifdef WIN16TTY
158# undef OPENSSL_SYS_WIN16
159# undef WIN16
160# undef _WINDOWS
161# include <graph.h>
162#endif
163
164/* 06-Apr-92 Luke Brennan Support for VMS */
165#include "ui_locl.h" 137#include "ui_locl.h"
166#include "cryptlib.h" 138#include "cryptlib.h"
167 139
168#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
169# include <starlet.h>
170# ifdef __DECC
171# pragma message disable DOLLARID
172# endif
173#endif
174
175#ifdef WIN_CONSOLE_BUG
176# include <windows.h>
177#ifndef OPENSSL_SYS_WINCE
178# include <wincon.h>
179#endif
180#endif
181
182 140
183/* There are 5 types of terminal interface supported, 141/* There are 5 types of terminal interface supported,
184 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY 142 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
185 */ 143 */
186 144
187#if defined(__sgi) && !defined(TERMIOS)
188# define TERMIOS
189# undef TERMIO
190# undef SGTTY
191#endif
192
193#if defined(linux) && !defined(TERMIO)
194# undef TERMIOS
195# define TERMIO
196# undef SGTTY
197#endif
198
199#ifdef _LIBC 145#ifdef _LIBC
200# undef TERMIOS 146# undef TERMIOS
201# define TERMIO 147# define TERMIO
202# undef SGTTY 148# undef SGTTY
203#endif 149#endif
204 150
205#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
206# undef TERMIOS
207# undef TERMIO
208# define SGTTY
209#endif
210
211#if defined(OPENSSL_SYS_VXWORKS)
212#undef TERMIOS
213#undef TERMIO
214#undef SGTTY
215#endif
216
217#if defined(OPENSSL_SYS_NETWARE)
218#undef TERMIOS
219#undef TERMIO
220#undef SGTTY
221#endif
222
223#ifdef TERMIOS 151#ifdef TERMIOS
224# include <termios.h> 152# include <termios.h>
225# define TTY_STRUCT struct termios 153# define TTY_STRUCT struct termios
@@ -236,46 +164,7 @@
236# define TTY_set(tty,data) ioctl(tty,TCSETA,data) 164# define TTY_set(tty,data) ioctl(tty,TCSETA,data)
237#endif 165#endif
238 166
239#ifdef SGTTY
240# include <sgtty.h>
241# define TTY_STRUCT struct sgttyb
242# define TTY_FLAGS sg_flags
243# define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
244# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
245#endif
246
247#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS)
248# include <sys/ioctl.h> 167# include <sys/ioctl.h>
249#endif
250
251#ifdef OPENSSL_SYS_MSDOS
252# include <conio.h>
253#endif
254
255#ifdef OPENSSL_SYS_VMS
256# include <ssdef.h>
257# include <iodef.h>
258# include <ttdef.h>
259# include <descrip.h>
260struct IOSB {
261 short iosb$w_value;
262 short iosb$w_count;
263 long iosb$l_info;
264 };
265#endif
266
267#ifdef OPENSSL_SYS_SUNOS
268 typedef int sig_atomic_t;
269#endif
270
271#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE) || defined(OPENSSL_SYS_NETWARE)
272/*
273 * This one needs work. As a matter of fact the code is unoperational
274 * and this is only a trick to get it compiled.
275 * <appro@fy.chalmers.se>
276 */
277# define TTY_STRUCT int
278#endif
279 168
280#ifndef NX509_SIG 169#ifndef NX509_SIG
281# define NX509_SIG 32 170# define NX509_SIG 32
@@ -289,30 +178,15 @@ static struct sigaction savsig[NX509_SIG];
289static void (*savsig[NX509_SIG])(int ); 178static void (*savsig[NX509_SIG])(int );
290#endif 179#endif
291 180
292#ifdef OPENSSL_SYS_VMS
293static struct IOSB iosb;
294static $DESCRIPTOR(terminal,"TT");
295static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */
296static long status;
297static unsigned short channel = 0;
298#else
299#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
300static TTY_STRUCT tty_orig,tty_new; 181static TTY_STRUCT tty_orig,tty_new;
301#endif
302#endif
303static FILE *tty_in, *tty_out; 182static FILE *tty_in, *tty_out;
304static int is_a_tty; 183static int is_a_tty;
305 184
306/* Declare static functions */ 185/* Declare static functions */
307#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
308static int read_till_nl(FILE *); 186static int read_till_nl(FILE *);
309static void recsig(int); 187static void recsig(int);
310static void pushsig(void); 188static void pushsig(void);
311static void popsig(void); 189static void popsig(void);
312#endif
313#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
314static int noecho_fgets(char *buf, int size, FILE *tty);
315#endif
316static 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);
317 191
318static int read_string(UI *ui, UI_STRING *uis); 192static int read_string(UI *ui, UI_STRING *uis);
@@ -396,7 +270,6 @@ static int read_string(UI *ui, UI_STRING *uis)
396 } 270 }
397 271
398 272
399#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
400/* Internal functions to read a string without echoing */ 273/* Internal functions to read a string without echoing */
401static int read_till_nl(FILE *in) 274static int read_till_nl(FILE *in)
402 { 275 {
@@ -411,7 +284,6 @@ static int read_till_nl(FILE *in)
411 } 284 }
412 285
413static volatile sig_atomic_t intr_signal; 286static volatile sig_atomic_t intr_signal;
414#endif
415 287
416static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) 288static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
417 { 289 {
@@ -419,7 +291,6 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
419 int ok; 291 int ok;
420 char result[BUFSIZ]; 292 char result[BUFSIZ];
421 int maxsize = BUFSIZ-1; 293 int maxsize = BUFSIZ-1;
422#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
423 char *p; 294 char *p;
424 295
425 intr_signal=0; 296 intr_signal=0;
@@ -434,17 +305,7 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
434 ps=2; 305 ps=2;
435 306
436 result[0]='\0'; 307 result[0]='\0';
437#ifdef OPENSSL_SYS_MSDOS
438 if (!echo)
439 {
440 noecho_fgets(result,maxsize,tty_in);
441 p=result; /* FIXME: noecho_fgets doesn't return errors */
442 }
443 else
444 p=fgets(result,maxsize,tty_in);
445#else
446 p=fgets(result,maxsize,tty_in); 308 p=fgets(result,maxsize,tty_in);
447#endif
448 if(!p) 309 if(!p)
449 goto error; 310 goto error;
450 if (feof(tty_in)) goto error; 311 if (feof(tty_in)) goto error;
@@ -469,9 +330,6 @@ error:
469 330
470 if (ps >= 1) 331 if (ps >= 1)
471 popsig(); 332 popsig();
472#else
473 ok=1;
474#endif
475 333
476 OPENSSL_cleanse(result,BUFSIZ); 334 OPENSSL_cleanse(result,BUFSIZ);
477 return ok; 335 return ok;
@@ -484,47 +342,26 @@ static int open_console(UI *ui)
484 CRYPTO_w_lock(CRYPTO_LOCK_UI); 342 CRYPTO_w_lock(CRYPTO_LOCK_UI);
485 is_a_tty = 1; 343 is_a_tty = 1;
486 344
487#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS)
488 tty_in=stdin;
489 tty_out=stderr;
490#else
491# ifdef OPENSSL_SYS_MSDOS
492# define DEV_TTY "con"
493# else
494# define DEV_TTY "/dev/tty" 345# define DEV_TTY "/dev/tty"
495# endif
496 if ((tty_in=fopen(DEV_TTY,"r")) == NULL) 346 if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
497 tty_in=stdin; 347 tty_in=stdin;
498 if ((tty_out=fopen(DEV_TTY,"w")) == NULL) 348 if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
499 tty_out=stderr; 349 tty_out=stderr;
500#endif
501 350
502#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS) 351#if defined(TTY_get)
503 if (TTY_get(fileno(tty_in),&tty_orig) == -1) 352 if (TTY_get(fileno(tty_in),&tty_orig) == -1)
504 { 353 {
505#ifdef ENOTTY
506 if (errno == ENOTTY) 354 if (errno == ENOTTY)
507 is_a_tty=0; 355 is_a_tty=0;
508 else 356 else
509#endif
510#ifdef EINVAL
511 /* Ariel Glenn ariel@columbia.edu reports that solaris 357 /* Ariel Glenn ariel@columbia.edu reports that solaris
512 * can return EINVAL instead. This should be ok */ 358 * can return EINVAL instead. This should be ok */
513 if (errno == EINVAL) 359 if (errno == EINVAL)
514 is_a_tty=0; 360 is_a_tty=0;
515 else 361 else
516#endif
517 return 0; 362 return 0;
518 } 363 }
519#endif 364#endif
520#ifdef OPENSSL_SYS_VMS
521 status = sys$assign(&terminal,&channel,0,0);
522 if (status != SS$_NORMAL)
523 return 0;
524 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
525 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
526 return 0;
527#endif
528 return 1; 365 return 1;
529 } 366 }
530 367
@@ -535,40 +372,24 @@ static int noecho_console(UI *ui)
535 tty_new.TTY_FLAGS &= ~ECHO; 372 tty_new.TTY_FLAGS &= ~ECHO;
536#endif 373#endif
537 374
538#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) 375#if defined(TTY_set)
539 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) 376 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
540 return 0; 377 return 0;
541#endif 378#endif
542#ifdef OPENSSL_SYS_VMS
543 tty_new[0] = tty_orig[0];
544 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
545 tty_new[2] = tty_orig[2];
546 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
547 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
548 return 0;
549#endif
550 return 1; 379 return 1;
551 } 380 }
552 381
553static int echo_console(UI *ui) 382static int echo_console(UI *ui)
554 { 383 {
555#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) 384#if defined(TTY_set)
556 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); 385 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
557 tty_new.TTY_FLAGS |= ECHO; 386 tty_new.TTY_FLAGS |= ECHO;
558#endif 387#endif
559 388
560#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) 389#if defined(TTY_set)
561 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) 390 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
562 return 0; 391 return 0;
563#endif 392#endif
564#ifdef OPENSSL_SYS_VMS
565 tty_new[0] = tty_orig[0];
566 tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
567 tty_new[2] = tty_orig[2];
568 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
569 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
570 return 0;
571#endif
572 return 1; 393 return 1;
573 } 394 }
574 395
@@ -576,22 +397,16 @@ static int close_console(UI *ui)
576 { 397 {
577 if (tty_in != stdin) fclose(tty_in); 398 if (tty_in != stdin) fclose(tty_in);
578 if (tty_out != stderr) fclose(tty_out); 399 if (tty_out != stderr) fclose(tty_out);
579#ifdef OPENSSL_SYS_VMS
580 status = sys$dassgn(channel);
581#endif
582 CRYPTO_w_unlock(CRYPTO_LOCK_UI); 400 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
583 401
584 return 1; 402 return 1;
585 } 403 }
586 404
587 405
588#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
589/* Internal functions to handle signals and act on them */ 406/* Internal functions to handle signals and act on them */
590static void pushsig(void) 407static void pushsig(void)
591 { 408 {
592#ifndef OPENSSL_SYS_WIN32
593 int i; 409 int i;
594#endif
595#ifdef SIGACTION 410#ifdef SIGACTION
596 struct sigaction sa; 411 struct sigaction sa;
597 412
@@ -599,14 +414,6 @@ static void pushsig(void)
599 sa.sa_handler=recsig; 414 sa.sa_handler=recsig;
600#endif 415#endif
601 416
602#ifdef OPENSSL_SYS_WIN32
603 savsig[SIGABRT]=signal(SIGABRT,recsig);
604 savsig[SIGFPE]=signal(SIGFPE,recsig);
605 savsig[SIGILL]=signal(SIGILL,recsig);
606 savsig[SIGINT]=signal(SIGINT,recsig);
607 savsig[SIGSEGV]=signal(SIGSEGV,recsig);
608 savsig[SIGTERM]=signal(SIGTERM,recsig);
609#else
610 for (i=1; i<NX509_SIG; i++) 417 for (i=1; i<NX509_SIG; i++)
611 { 418 {
612#ifdef SIGUSR1 419#ifdef SIGUSR1
@@ -627,7 +434,6 @@ static void pushsig(void)
627 savsig[i]=signal(i,recsig); 434 savsig[i]=signal(i,recsig);
628#endif 435#endif
629 } 436 }
630#endif
631 437
632#ifdef SIGWINCH 438#ifdef SIGWINCH
633 signal(SIGWINCH,SIG_DFL); 439 signal(SIGWINCH,SIG_DFL);
@@ -636,83 +442,22 @@ static void pushsig(void)
636 442
637static void popsig(void) 443static void popsig(void)
638 { 444 {
639#ifdef OPENSSL_SYS_WIN32
640 signal(SIGABRT,savsig[SIGABRT]);
641 signal(SIGFPE,savsig[SIGFPE]);
642 signal(SIGILL,savsig[SIGILL]);
643 signal(SIGINT,savsig[SIGINT]);
644 signal(SIGSEGV,savsig[SIGSEGV]);
645 signal(SIGTERM,savsig[SIGTERM]);
646#else
647 int i; 445 int i;
648 for (i=1; i<NX509_SIG; i++) 446 for (i=1; i<NX509_SIG; i++)
649 { 447 {
650#ifdef SIGUSR1
651 if (i == SIGUSR1) 448 if (i == SIGUSR1)
652 continue; 449 continue;
653#endif
654#ifdef SIGUSR2
655 if (i == SIGUSR2) 450 if (i == SIGUSR2)
656 continue; 451 continue;
657#endif
658#ifdef SIGACTION 452#ifdef SIGACTION
659 sigaction(i,&savsig[i],NULL); 453 sigaction(i,&savsig[i],NULL);
660#else 454#else
661 signal(i,savsig[i]); 455 signal(i,savsig[i]);
662#endif 456#endif
663 } 457 }
664#endif
665 } 458 }
666 459
667static void recsig(int i) 460static void recsig(int i)
668 { 461 {
669 intr_signal=i; 462 intr_signal=i;
670 } 463 }
671#endif
672
673/* Internal functions specific for Windows */
674#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
675static int noecho_fgets(char *buf, int size, FILE *tty)
676 {
677 int i;
678 char *p;
679
680 p=buf;
681 for (;;)
682 {
683 if (size == 0)
684 {
685 *p='\0';
686 break;
687 }
688 size--;
689#ifdef WIN16TTY
690 i=_inchar();
691#elif defined(_WIN32)
692 i=_getch();
693#else
694 i=getch();
695#endif
696 if (i == '\r') i='\n';
697 *(p++)=i;
698 if (i == '\n')
699 {
700 *p='\0';
701 break;
702 }
703 }
704#ifdef WIN_CONSOLE_BUG
705/* Win95 has several evil console bugs: one of these is that the
706 * last character read using getch() is passed to the next read: this is
707 * usually a CR so this can be trouble. No STDIO fix seems to work but
708 * flushing the console appears to do the trick.
709 */
710 {
711 HANDLE inh;
712 inh = GetStdHandle(STD_INPUT_HANDLE);
713 FlushConsoleInputBuffer(inh);
714 }
715#endif
716 return(strlen(buf));
717 }
718#endif
diff --git a/src/lib/libssl/src/crypto/ui/ui_openssl.c b/src/lib/libssl/src/crypto/ui/ui_openssl.c
index a38c7581e6..6000c24b1c 100644
--- a/src/lib/libssl/src/crypto/ui/ui_openssl.c
+++ b/src/lib/libssl/src/crypto/ui/ui_openssl.c
@@ -117,31 +117,12 @@
117 117
118#include <openssl/e_os2.h> 118#include <openssl/e_os2.h>
119 119
120/* need for #define _POSIX_C_SOURCE arises whenever you pass -ansi to gcc
121 * [maybe others?], because it masks interfaces not discussed in standard,
122 * sigaction and fileno included. -pedantic would be more appropriate for
123 * the intended purposes, but we can't prevent users from adding -ansi.
124 */
125#if defined(OPENSSL_SYSNAME_VXWORKS)
126#include <sys/types.h>
127#endif
128
129#if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS)
130#ifndef _POSIX_C_SOURCE
131#define _POSIX_C_SOURCE 2
132#endif
133#endif
134#include <signal.h> 120#include <signal.h>
135#include <stdio.h> 121#include <stdio.h>
136#include <string.h> 122#include <string.h>
137#include <errno.h> 123#include <errno.h>
138 124
139#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) 125#include <unistd.h>
140# ifdef OPENSSL_UNISTD
141# include OPENSSL_UNISTD
142# else
143# include <unistd.h>
144# endif
145/* If unistd.h defines _POSIX_VERSION, we conclude that we 126/* If unistd.h defines _POSIX_VERSION, we conclude that we
146 * are on a POSIX system and have sigaction and termios. */ 127 * are on a POSIX system and have sigaction and termios. */
147# if defined(_POSIX_VERSION) 128# if defined(_POSIX_VERSION)
@@ -152,74 +133,21 @@
152# endif 133# endif
153 134
154# endif 135# endif
155#endif
156 136
157#ifdef WIN16TTY
158# undef OPENSSL_SYS_WIN16
159# undef WIN16
160# undef _WINDOWS
161# include <graph.h>
162#endif
163
164/* 06-Apr-92 Luke Brennan Support for VMS */
165#include "ui_locl.h" 137#include "ui_locl.h"
166#include "cryptlib.h" 138#include "cryptlib.h"
167 139
168#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
169# include <starlet.h>
170# ifdef __DECC
171# pragma message disable DOLLARID
172# endif
173#endif
174
175#ifdef WIN_CONSOLE_BUG
176# include <windows.h>
177#ifndef OPENSSL_SYS_WINCE
178# include <wincon.h>
179#endif
180#endif
181
182 140
183/* There are 5 types of terminal interface supported, 141/* There are 5 types of terminal interface supported,
184 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY 142 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
185 */ 143 */
186 144
187#if defined(__sgi) && !defined(TERMIOS)
188# define TERMIOS
189# undef TERMIO
190# undef SGTTY
191#endif
192
193#if defined(linux) && !defined(TERMIO)
194# undef TERMIOS
195# define TERMIO
196# undef SGTTY
197#endif
198
199#ifdef _LIBC 145#ifdef _LIBC
200# undef TERMIOS 146# undef TERMIOS
201# define TERMIO 147# define TERMIO
202# undef SGTTY 148# undef SGTTY
203#endif 149#endif
204 150
205#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
206# undef TERMIOS
207# undef TERMIO
208# define SGTTY
209#endif
210
211#if defined(OPENSSL_SYS_VXWORKS)
212#undef TERMIOS
213#undef TERMIO
214#undef SGTTY
215#endif
216
217#if defined(OPENSSL_SYS_NETWARE)
218#undef TERMIOS
219#undef TERMIO
220#undef SGTTY
221#endif
222
223#ifdef TERMIOS 151#ifdef TERMIOS
224# include <termios.h> 152# include <termios.h>
225# define TTY_STRUCT struct termios 153# define TTY_STRUCT struct termios
@@ -236,46 +164,7 @@
236# define TTY_set(tty,data) ioctl(tty,TCSETA,data) 164# define TTY_set(tty,data) ioctl(tty,TCSETA,data)
237#endif 165#endif
238 166
239#ifdef SGTTY
240# include <sgtty.h>
241# define TTY_STRUCT struct sgttyb
242# define TTY_FLAGS sg_flags
243# define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
244# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
245#endif
246
247#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS)
248# include <sys/ioctl.h> 167# include <sys/ioctl.h>
249#endif
250
251#ifdef OPENSSL_SYS_MSDOS
252# include <conio.h>
253#endif
254
255#ifdef OPENSSL_SYS_VMS
256# include <ssdef.h>
257# include <iodef.h>
258# include <ttdef.h>
259# include <descrip.h>
260struct IOSB {
261 short iosb$w_value;
262 short iosb$w_count;
263 long iosb$l_info;
264 };
265#endif
266
267#ifdef OPENSSL_SYS_SUNOS
268 typedef int sig_atomic_t;
269#endif
270
271#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE) || defined(OPENSSL_SYS_NETWARE)
272/*
273 * This one needs work. As a matter of fact the code is unoperational
274 * and this is only a trick to get it compiled.
275 * <appro@fy.chalmers.se>
276 */
277# define TTY_STRUCT int
278#endif
279 168
280#ifndef NX509_SIG 169#ifndef NX509_SIG
281# define NX509_SIG 32 170# define NX509_SIG 32
@@ -289,30 +178,15 @@ static struct sigaction savsig[NX509_SIG];
289static void (*savsig[NX509_SIG])(int ); 178static void (*savsig[NX509_SIG])(int );
290#endif 179#endif
291 180
292#ifdef OPENSSL_SYS_VMS
293static struct IOSB iosb;
294static $DESCRIPTOR(terminal,"TT");
295static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */
296static long status;
297static unsigned short channel = 0;
298#else
299#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
300static TTY_STRUCT tty_orig,tty_new; 181static TTY_STRUCT tty_orig,tty_new;
301#endif
302#endif
303static FILE *tty_in, *tty_out; 182static FILE *tty_in, *tty_out;
304static int is_a_tty; 183static int is_a_tty;
305 184
306/* Declare static functions */ 185/* Declare static functions */
307#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
308static int read_till_nl(FILE *); 186static int read_till_nl(FILE *);
309static void recsig(int); 187static void recsig(int);
310static void pushsig(void); 188static void pushsig(void);
311static void popsig(void); 189static void popsig(void);
312#endif
313#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
314static int noecho_fgets(char *buf, int size, FILE *tty);
315#endif
316static 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);
317 191
318static int read_string(UI *ui, UI_STRING *uis); 192static int read_string(UI *ui, UI_STRING *uis);
@@ -396,7 +270,6 @@ static int read_string(UI *ui, UI_STRING *uis)
396 } 270 }
397 271
398 272
399#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
400/* Internal functions to read a string without echoing */ 273/* Internal functions to read a string without echoing */
401static int read_till_nl(FILE *in) 274static int read_till_nl(FILE *in)
402 { 275 {
@@ -411,7 +284,6 @@ static int read_till_nl(FILE *in)
411 } 284 }
412 285
413static volatile sig_atomic_t intr_signal; 286static volatile sig_atomic_t intr_signal;
414#endif
415 287
416static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) 288static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
417 { 289 {
@@ -419,7 +291,6 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
419 int ok; 291 int ok;
420 char result[BUFSIZ]; 292 char result[BUFSIZ];
421 int maxsize = BUFSIZ-1; 293 int maxsize = BUFSIZ-1;
422#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
423 char *p; 294 char *p;
424 295
425 intr_signal=0; 296 intr_signal=0;
@@ -434,17 +305,7 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
434 ps=2; 305 ps=2;
435 306
436 result[0]='\0'; 307 result[0]='\0';
437#ifdef OPENSSL_SYS_MSDOS
438 if (!echo)
439 {
440 noecho_fgets(result,maxsize,tty_in);
441 p=result; /* FIXME: noecho_fgets doesn't return errors */
442 }
443 else
444 p=fgets(result,maxsize,tty_in);
445#else
446 p=fgets(result,maxsize,tty_in); 308 p=fgets(result,maxsize,tty_in);
447#endif
448 if(!p) 309 if(!p)
449 goto error; 310 goto error;
450 if (feof(tty_in)) goto error; 311 if (feof(tty_in)) goto error;
@@ -469,9 +330,6 @@ error:
469 330
470 if (ps >= 1) 331 if (ps >= 1)
471 popsig(); 332 popsig();
472#else
473 ok=1;
474#endif
475 333
476 OPENSSL_cleanse(result,BUFSIZ); 334 OPENSSL_cleanse(result,BUFSIZ);
477 return ok; 335 return ok;
@@ -484,47 +342,26 @@ static int open_console(UI *ui)
484 CRYPTO_w_lock(CRYPTO_LOCK_UI); 342 CRYPTO_w_lock(CRYPTO_LOCK_UI);
485 is_a_tty = 1; 343 is_a_tty = 1;
486 344
487#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS)
488 tty_in=stdin;
489 tty_out=stderr;
490#else
491# ifdef OPENSSL_SYS_MSDOS
492# define DEV_TTY "con"
493# else
494# define DEV_TTY "/dev/tty" 345# define DEV_TTY "/dev/tty"
495# endif
496 if ((tty_in=fopen(DEV_TTY,"r")) == NULL) 346 if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
497 tty_in=stdin; 347 tty_in=stdin;
498 if ((tty_out=fopen(DEV_TTY,"w")) == NULL) 348 if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
499 tty_out=stderr; 349 tty_out=stderr;
500#endif
501 350
502#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS) 351#if defined(TTY_get)
503 if (TTY_get(fileno(tty_in),&tty_orig) == -1) 352 if (TTY_get(fileno(tty_in),&tty_orig) == -1)
504 { 353 {
505#ifdef ENOTTY
506 if (errno == ENOTTY) 354 if (errno == ENOTTY)
507 is_a_tty=0; 355 is_a_tty=0;
508 else 356 else
509#endif
510#ifdef EINVAL
511 /* Ariel Glenn ariel@columbia.edu reports that solaris 357 /* Ariel Glenn ariel@columbia.edu reports that solaris
512 * can return EINVAL instead. This should be ok */ 358 * can return EINVAL instead. This should be ok */
513 if (errno == EINVAL) 359 if (errno == EINVAL)
514 is_a_tty=0; 360 is_a_tty=0;
515 else 361 else
516#endif
517 return 0; 362 return 0;
518 } 363 }
519#endif 364#endif
520#ifdef OPENSSL_SYS_VMS
521 status = sys$assign(&terminal,&channel,0,0);
522 if (status != SS$_NORMAL)
523 return 0;
524 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
525 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
526 return 0;
527#endif
528 return 1; 365 return 1;
529 } 366 }
530 367
@@ -535,40 +372,24 @@ static int noecho_console(UI *ui)
535 tty_new.TTY_FLAGS &= ~ECHO; 372 tty_new.TTY_FLAGS &= ~ECHO;
536#endif 373#endif
537 374
538#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) 375#if defined(TTY_set)
539 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) 376 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
540 return 0; 377 return 0;
541#endif 378#endif
542#ifdef OPENSSL_SYS_VMS
543 tty_new[0] = tty_orig[0];
544 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
545 tty_new[2] = tty_orig[2];
546 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
547 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
548 return 0;
549#endif
550 return 1; 379 return 1;
551 } 380 }
552 381
553static int echo_console(UI *ui) 382static int echo_console(UI *ui)
554 { 383 {
555#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) 384#if defined(TTY_set)
556 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); 385 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
557 tty_new.TTY_FLAGS |= ECHO; 386 tty_new.TTY_FLAGS |= ECHO;
558#endif 387#endif
559 388
560#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) 389#if defined(TTY_set)
561 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) 390 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
562 return 0; 391 return 0;
563#endif 392#endif
564#ifdef OPENSSL_SYS_VMS
565 tty_new[0] = tty_orig[0];
566 tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
567 tty_new[2] = tty_orig[2];
568 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
569 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
570 return 0;
571#endif
572 return 1; 393 return 1;
573 } 394 }
574 395
@@ -576,22 +397,16 @@ static int close_console(UI *ui)
576 { 397 {
577 if (tty_in != stdin) fclose(tty_in); 398 if (tty_in != stdin) fclose(tty_in);
578 if (tty_out != stderr) fclose(tty_out); 399 if (tty_out != stderr) fclose(tty_out);
579#ifdef OPENSSL_SYS_VMS
580 status = sys$dassgn(channel);
581#endif
582 CRYPTO_w_unlock(CRYPTO_LOCK_UI); 400 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
583 401
584 return 1; 402 return 1;
585 } 403 }
586 404
587 405
588#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
589/* Internal functions to handle signals and act on them */ 406/* Internal functions to handle signals and act on them */
590static void pushsig(void) 407static void pushsig(void)
591 { 408 {
592#ifndef OPENSSL_SYS_WIN32
593 int i; 409 int i;
594#endif
595#ifdef SIGACTION 410#ifdef SIGACTION
596 struct sigaction sa; 411 struct sigaction sa;
597 412
@@ -599,14 +414,6 @@ static void pushsig(void)
599 sa.sa_handler=recsig; 414 sa.sa_handler=recsig;
600#endif 415#endif
601 416
602#ifdef OPENSSL_SYS_WIN32
603 savsig[SIGABRT]=signal(SIGABRT,recsig);
604 savsig[SIGFPE]=signal(SIGFPE,recsig);
605 savsig[SIGILL]=signal(SIGILL,recsig);
606 savsig[SIGINT]=signal(SIGINT,recsig);
607 savsig[SIGSEGV]=signal(SIGSEGV,recsig);
608 savsig[SIGTERM]=signal(SIGTERM,recsig);
609#else
610 for (i=1; i<NX509_SIG; i++) 417 for (i=1; i<NX509_SIG; i++)
611 { 418 {
612#ifdef SIGUSR1 419#ifdef SIGUSR1
@@ -627,7 +434,6 @@ static void pushsig(void)
627 savsig[i]=signal(i,recsig); 434 savsig[i]=signal(i,recsig);
628#endif 435#endif
629 } 436 }
630#endif
631 437
632#ifdef SIGWINCH 438#ifdef SIGWINCH
633 signal(SIGWINCH,SIG_DFL); 439 signal(SIGWINCH,SIG_DFL);
@@ -636,83 +442,22 @@ static void pushsig(void)
636 442
637static void popsig(void) 443static void popsig(void)
638 { 444 {
639#ifdef OPENSSL_SYS_WIN32
640 signal(SIGABRT,savsig[SIGABRT]);
641 signal(SIGFPE,savsig[SIGFPE]);
642 signal(SIGILL,savsig[SIGILL]);
643 signal(SIGINT,savsig[SIGINT]);
644 signal(SIGSEGV,savsig[SIGSEGV]);
645 signal(SIGTERM,savsig[SIGTERM]);
646#else
647 int i; 445 int i;
648 for (i=1; i<NX509_SIG; i++) 446 for (i=1; i<NX509_SIG; i++)
649 { 447 {
650#ifdef SIGUSR1
651 if (i == SIGUSR1) 448 if (i == SIGUSR1)
652 continue; 449 continue;
653#endif
654#ifdef SIGUSR2
655 if (i == SIGUSR2) 450 if (i == SIGUSR2)
656 continue; 451 continue;
657#endif
658#ifdef SIGACTION 452#ifdef SIGACTION
659 sigaction(i,&savsig[i],NULL); 453 sigaction(i,&savsig[i],NULL);
660#else 454#else
661 signal(i,savsig[i]); 455 signal(i,savsig[i]);
662#endif 456#endif
663 } 457 }
664#endif
665 } 458 }
666 459
667static void recsig(int i) 460static void recsig(int i)
668 { 461 {
669 intr_signal=i; 462 intr_signal=i;
670 } 463 }
671#endif
672
673/* Internal functions specific for Windows */
674#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
675static int noecho_fgets(char *buf, int size, FILE *tty)
676 {
677 int i;
678 char *p;
679
680 p=buf;
681 for (;;)
682 {
683 if (size == 0)
684 {
685 *p='\0';
686 break;
687 }
688 size--;
689#ifdef WIN16TTY
690 i=_inchar();
691#elif defined(_WIN32)
692 i=_getch();
693#else
694 i=getch();
695#endif
696 if (i == '\r') i='\n';
697 *(p++)=i;
698 if (i == '\n')
699 {
700 *p='\0';
701 break;
702 }
703 }
704#ifdef WIN_CONSOLE_BUG
705/* Win95 has several evil console bugs: one of these is that the
706 * last character read using getch() is passed to the next read: this is
707 * usually a CR so this can be trouble. No STDIO fix seems to work but
708 * flushing the console appears to do the trick.
709 */
710 {
711 HANDLE inh;
712 inh = GetStdHandle(STD_INPUT_HANDLE);
713 FlushConsoleInputBuffer(inh);
714 }
715#endif
716 return(strlen(buf));
717 }
718#endif