125 #if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS)
126 #define _POSIX_C_SOURCE 2
133 #if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
134 # ifdef OPENSSL_UNISTD
135 # include OPENSSL_UNISTD
141 # if defined(_POSIX_VERSION)
144 # if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
152 # undef OPENSSL_SYS_WIN16
162 #ifdef OPENSSL_SYS_VMS
163 # include <starlet.h>
165 # pragma message disable DOLLARID
169 #ifdef WIN_CONSOLE_BUG
170 # include <windows.h>
171 #ifndef OPENSSL_SYS_WINCE
181 #if defined(__sgi) && !defined(TERMIOS)
187 #if defined(linux) && !defined(TERMIO)
199 #if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
205 #if defined(OPENSSL_SYS_VXWORKS)
211 #if defined(OPENSSL_SYS_NETWARE)
218 # include <termios.h>
219 # define TTY_STRUCT struct termios
220 # define TTY_FLAGS c_lflag
221 # define TTY_get(tty,data) tcgetattr(tty,data)
222 # define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
227 # define TTY_STRUCT struct termio
228 # define TTY_FLAGS c_lflag
229 # define TTY_get(tty,data) ioctl(tty,TCGETA,data)
230 # define TTY_set(tty,data) ioctl(tty,TCSETA,data)
235 # define TTY_STRUCT struct sgttyb
236 # define TTY_FLAGS sg_flags
237 # define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
238 # define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
241 #if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS)
242 # include <sys/ioctl.h>
245 #ifdef OPENSSL_SYS_MSDOS
249 #ifdef OPENSSL_SYS_VMS
253 # include <descrip.h>
261 #ifdef OPENSSL_SYS_SUNOS
262 typedef int sig_atomic_t;
265 #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE) || defined(OPENSSL_SYS_NETWARE)
271 # define TTY_STRUCT int
275 # define NX509_SIG 32
281 static struct sigaction savsig[
NX509_SIG];
286 #ifdef OPENSSL_SYS_VMS
287 static struct IOSB iosb;
288 static $DESCRIPTOR(terminal,
"TT");
289 static long tty_orig[3], tty_new[3];
291 static unsigned short channel = 0;
293 #if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
297 static FILE *tty_in, *tty_out;
301 #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
302 static int read_till_nl(FILE *);
303 static void recsig(
int);
304 static void pushsig(
void);
305 static void popsig(
void);
307 #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
308 static int noecho_fgets(
char *buf,
int size, FILE *tty);
310 static int read_string_inner(
UI *ui,
UI_STRING *uis,
int echo,
int strip_nl);
315 static int open_console(
UI *ui);
316 static int echo_console(
UI *ui);
317 static int noecho_console(
UI *ui);
318 static int close_console(
UI *ui);
322 "OpenSSL default user interface",
364 return read_string_inner(ui, uis,
369 return read_string_inner(ui, uis,
372 fprintf(tty_out,
"Verifying - %s",
375 if ((ok = read_string_inner(ui, uis,
381 fprintf(tty_out,
"Verify failure\n");
393 #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
395 static int read_till_nl(FILE *in)
401 if (!fgets(buf,SIZE,in))
403 }
while (strchr(buf,
'\n') == NULL);
407 static volatile sig_atomic_t intr_signal;
410 static int read_string_inner(
UI *ui,
UI_STRING *uis,
int echo,
int strip_nl)
415 int maxsize = BUFSIZ-1;
416 #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
426 if (!echo && !noecho_console(ui))
431 #ifdef OPENSSL_SYS_MSDOS
434 noecho_fgets(result,maxsize,tty_in);
438 p=fgets(result,maxsize,tty_in);
440 p=fgets(result,maxsize,tty_in);
444 if (feof(tty_in))
goto error;
445 if (ferror(tty_in))
goto error;
446 if ((p=(
char *)strchr(result,
'\n')) != NULL)
452 if (!read_till_nl(tty_in))
458 if (intr_signal == SIGINT)
460 if (!echo) fprintf(tty_out,
"\n");
461 if (ps >= 2 && !echo && !echo_console(ui))
476 static int open_console(
UI *ui)
481 #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS)
485 # ifdef OPENSSL_SYS_MSDOS
486 # define DEV_TTY "con"
488 # define DEV_TTY "/dev/tty"
490 if ((tty_in=fopen(DEV_TTY,
"r")) == NULL)
492 if ((tty_out=fopen(DEV_TTY,
"w")) == NULL)
496 #if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
497 if (
TTY_get(fileno(tty_in),&tty_orig) == -1)
514 #ifdef OPENSSL_SYS_VMS
515 status = sys$assign(&terminal,&channel,0,0);
516 if (status != SS$_NORMAL)
518 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
519 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
525 static int noecho_console(
UI *ui)
528 memcpy(&(tty_new),&(tty_orig),
sizeof(tty_orig));
529 tty_new.TTY_FLAGS &= ~ECHO;
532 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
533 if (is_a_tty && (
TTY_set(fileno(tty_in),&tty_new) == -1))
536 #ifdef OPENSSL_SYS_VMS
537 tty_new[0] = tty_orig[0];
538 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
539 tty_new[2] = tty_orig[2];
540 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
541 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
547 static int echo_console(
UI *ui)
549 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
550 memcpy(&(tty_new),&(tty_orig),
sizeof(tty_orig));
551 tty_new.TTY_FLAGS |= ECHO;
554 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
555 if (is_a_tty && (
TTY_set(fileno(tty_in),&tty_new) == -1))
558 #ifdef OPENSSL_SYS_VMS
559 tty_new[0] = tty_orig[0];
560 tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
561 tty_new[2] = tty_orig[2];
562 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
563 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
569 static int close_console(
UI *ui)
571 if (tty_in != stdin) fclose(tty_in);
572 if (tty_out != stderr) fclose(tty_out);
573 #ifdef OPENSSL_SYS_VMS
574 status = sys$dassgn(channel);
582 #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
584 static void pushsig(
void)
586 #ifndef OPENSSL_SYS_WIN32
592 memset(&sa,0,
sizeof sa);
593 sa.sa_handler=recsig;
596 #ifdef OPENSSL_SYS_WIN32
597 savsig[SIGABRT]=signal(SIGABRT,recsig);
598 savsig[SIGFPE]=signal(SIGFPE,recsig);
599 savsig[SIGILL]=signal(SIGILL,recsig);
600 savsig[SIGINT]=signal(SIGINT,recsig);
601 savsig[SIGSEGV]=signal(SIGSEGV,recsig);
602 savsig[SIGTERM]=signal(SIGTERM,recsig);
619 sigaction(i,&sa,&savsig[i]);
621 savsig[i]=signal(i,recsig);
627 signal(SIGWINCH,SIG_DFL);
631 static void popsig(
void)
633 #ifdef OPENSSL_SYS_WIN32
634 signal(SIGABRT,savsig[SIGABRT]);
635 signal(SIGFPE,savsig[SIGFPE]);
636 signal(SIGILL,savsig[SIGILL]);
637 signal(SIGINT,savsig[SIGINT]);
638 signal(SIGSEGV,savsig[SIGSEGV]);
639 signal(SIGTERM,savsig[SIGTERM]);
653 sigaction(i,&savsig[i],NULL);
661 static void recsig(
int i)
668 #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
669 static int noecho_fgets(
char *buf,
int size, FILE *tty)
685 #elif defined(_WIN32)
690 if (i ==
'\r') i=
'\n';
698 #ifdef WIN_CONSOLE_BUG
706 inh = GetStdHandle(STD_INPUT_HANDLE);
707 FlushConsoleInputBuffer(inh);