sl@0: /* crypto/ui/ui_openssl.c -*- mode:C; c-file-style: "eay" -*- */ sl@0: /* Written by Richard Levitte (richard@levitte.org) and others sl@0: * for the OpenSSL project 2001. sl@0: */ sl@0: /* ==================================================================== sl@0: * Copyright (c) 2001 The OpenSSL Project. All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in sl@0: * the documentation and/or other materials provided with the sl@0: * distribution. sl@0: * sl@0: * 3. All advertising materials mentioning features or use of this sl@0: * software must display the following acknowledgment: sl@0: * "This product includes software developed by the OpenSSL Project sl@0: * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" sl@0: * sl@0: * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to sl@0: * endorse or promote products derived from this software without sl@0: * prior written permission. For written permission, please contact sl@0: * openssl-core@openssl.org. sl@0: * sl@0: * 5. Products derived from this software may not be called "OpenSSL" sl@0: * nor may "OpenSSL" appear in their names without prior written sl@0: * permission of the OpenSSL Project. sl@0: * sl@0: * 6. Redistributions of any form whatsoever must retain the following sl@0: * acknowledgment: sl@0: * "This product includes software developed by the OpenSSL Project sl@0: * for use in the OpenSSL Toolkit (http://www.openssl.org/)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY sl@0: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR sl@0: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR sl@0: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, sl@0: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT sl@0: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; sl@0: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, sl@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) sl@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED sl@0: * OF THE POSSIBILITY OF SUCH DAMAGE. sl@0: * ==================================================================== sl@0: * sl@0: * This product includes cryptographic software written by Eric Young sl@0: * (eay@cryptsoft.com). This product includes software written by Tim sl@0: * Hudson (tjh@cryptsoft.com). sl@0: * sl@0: */ sl@0: sl@0: /* The lowest level part of this file was previously in crypto/des/read_pwd.c, sl@0: * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) sl@0: * All rights reserved. sl@0: * sl@0: * This package is an SSL implementation written sl@0: * by Eric Young (eay@cryptsoft.com). sl@0: * The implementation was written so as to conform with Netscapes SSL. sl@0: * sl@0: * This library is free for commercial and non-commercial use as long as sl@0: * the following conditions are aheared to. The following conditions sl@0: * apply to all code found in this distribution, be it the RC4, RSA, sl@0: * lhash, DES, etc., code; not just the SSL code. The SSL documentation sl@0: * included with this distribution is covered by the same copyright terms sl@0: * except that the holder is Tim Hudson (tjh@cryptsoft.com). sl@0: * sl@0: * Copyright remains Eric Young's, and as such any Copyright notices in sl@0: * the code are not to be removed. sl@0: * If this package is used in a product, Eric Young should be given attribution sl@0: * as the author of the parts of the library used. sl@0: * This can be in the form of a textual message at program startup or sl@0: * in documentation (online or textual) provided with the package. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * 3. All advertising materials mentioning features or use of this software sl@0: * must display the following acknowledgement: sl@0: * "This product includes cryptographic software written by sl@0: * Eric Young (eay@cryptsoft.com)" sl@0: * The word 'cryptographic' can be left out if the rouines from the library sl@0: * being used are not cryptographic related :-). sl@0: * 4. If you include any Windows specific code (or a derivative thereof) from sl@0: * the apps directory (application code) you must include an acknowledgement: sl@0: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND sl@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE sl@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL sl@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS sl@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT sl@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY sl@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF sl@0: * SUCH DAMAGE. sl@0: * sl@0: * The licence and distribution terms for any publically available version or sl@0: * derivative of this code cannot be changed. i.e. this code cannot simply be sl@0: * copied and put under another distribution licence sl@0: * [including the GNU Public Licence.] sl@0: */ sl@0: /* sl@0: © Portions copyright (c) 2006 Nokia Corporation. All rights reserved. sl@0: */ sl@0: sl@0: sl@0: #include sl@0: sl@0: /* need for #define _POSIX_C_SOURCE arises whenever you pass -ansi to gcc sl@0: * [maybe others?], because it masks interfaces not discussed in standard, sl@0: * sigaction and fileno included. -pedantic would be more appropriate for sl@0: * the intended purposes, but we can't prevent users from adding -ansi. sl@0: */ sl@0: sl@0: #define _POSIX_C_SOURCE 1 sl@0: #if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__))) sl@0: #undef _POSIX_C_SOURCE sl@0: #endif sl@0: #ifndef SYMBIAN sl@0: #include sl@0: #endif sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: #if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) sl@0: # ifdef OPENSSL_UNISTD sl@0: # include OPENSSL_UNISTD sl@0: # else sl@0: # include sl@0: # endif sl@0: /* If unistd.h defines _POSIX_VERSION, we conclude that we sl@0: * are on a POSIX system and have sigaction and termios. */ sl@0: # if defined(_POSIX_VERSION) && !defined(SYMBIAN) sl@0: # define SIGACTION sl@0: # if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY) sl@0: # define TERMIOS sl@0: # endif sl@0: sl@0: # endif sl@0: #endif sl@0: sl@0: #ifdef WIN16TTY sl@0: # undef OPENSSL_SYS_WIN16 sl@0: # undef WIN16 sl@0: # undef _WINDOWS sl@0: # include sl@0: #endif sl@0: sl@0: /* 06-Apr-92 Luke Brennan Support for VMS */ sl@0: #include "ui_locl.h" sl@0: #include "cryptlib.h" sl@0: sl@0: #ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */ sl@0: # include sl@0: # ifdef __DECC sl@0: # pragma message disable DOLLARID sl@0: # endif sl@0: #endif sl@0: sl@0: #ifndef SYMBIAN sl@0: #ifdef WIN_CONSOLE_BUG sl@0: # include sl@0: #ifndef OPENSSL_SYS_WINCE sl@0: # include sl@0: #endif sl@0: #endif sl@0: #endif sl@0: sl@0: /* There are 5 types of terminal interface supported, sl@0: * TERMIO, TERMIOS, VMS, MSDOS and SGTTY sl@0: */ sl@0: sl@0: #if defined(__sgi) && !defined(TERMIOS) sl@0: # define TERMIOS sl@0: # undef TERMIO sl@0: # undef SGTTY sl@0: #endif sl@0: sl@0: #if defined(linux) && !defined(TERMIO) sl@0: # undef TERMIOS sl@0: # define TERMIO sl@0: # undef SGTTY sl@0: #endif sl@0: sl@0: #ifdef _LIBC sl@0: # undef TERMIOS sl@0: # define TERMIO sl@0: # undef SGTTY sl@0: #endif sl@0: sl@0: #if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE) sl@0: # undef TERMIOS sl@0: # undef TERMIO sl@0: # define SGTTY sl@0: #endif sl@0: sl@0: #if defined(OPENSSL_SYS_VXWORKS) sl@0: #undef TERMIOS sl@0: #undef TERMIO sl@0: #undef SGTTY sl@0: #endif sl@0: sl@0: #if defined(OPENSSL_SYS_NETWARE) sl@0: #undef TERMIOS sl@0: #undef TERMIO sl@0: #undef SGTTY sl@0: #endif sl@0: sl@0: #if defined(SYMBIAN) sl@0: #undef TERMIOS sl@0: #undef TERMIO sl@0: #undef SGTTY sl@0: #endif sl@0: sl@0: #ifdef TERMIOS sl@0: # include sl@0: # define TTY_STRUCT struct termios sl@0: # define TTY_FLAGS c_lflag sl@0: # define TTY_get(tty,data) tcgetattr(tty,data) sl@0: # define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data) sl@0: #endif sl@0: sl@0: #ifdef TERMIO sl@0: # include sl@0: # define TTY_STRUCT struct termio sl@0: # define TTY_FLAGS c_lflag sl@0: # define TTY_get(tty,data) ioctl(tty,TCGETA,data) sl@0: # define TTY_set(tty,data) ioctl(tty,TCSETA,data) sl@0: #endif sl@0: sl@0: #ifdef SGTTY sl@0: # include sl@0: # define TTY_STRUCT struct sgttyb sl@0: # define TTY_FLAGS sg_flags sl@0: # define TTY_get(tty,data) ioctl(tty,TIOCGETP,data) sl@0: # define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) sl@0: #endif sl@0: sl@0: #if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS) sl@0: # include sl@0: #endif sl@0: sl@0: #ifdef OPENSSL_SYS_MSDOS sl@0: # include sl@0: #endif sl@0: sl@0: #ifdef OPENSSL_SYS_VMS sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: struct IOSB { sl@0: short iosb$w_value; sl@0: short iosb$w_count; sl@0: long iosb$l_info; sl@0: }; sl@0: #endif sl@0: #if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__))) sl@0: #include "libcrypto_wsd_macros.h" sl@0: #include "libcrypto_wsd.h" sl@0: #endif sl@0: sl@0: #ifdef OPENSSL_SYS_SUNOS sl@0: typedef int sig_atomic_t; sl@0: #endif sl@0: sl@0: #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE) || defined(OPENSSL_SYS_NETWARE) sl@0: /* sl@0: * This one needs work. As a matter of fact the code is unoperational sl@0: * and this is only a trick to get it compiled. sl@0: * sl@0: */ sl@0: # define TTY_STRUCT int sl@0: #endif sl@0: sl@0: #ifndef NX509_SIG sl@0: # define NX509_SIG 32 sl@0: #endif sl@0: sl@0: sl@0: /* Define globals. They are protected by a lock */ sl@0: #ifdef SIGACTION sl@0: static struct sigaction savsig[NX509_SIG]; sl@0: #else sl@0: static void (*savsig[NX509_SIG])(int ); sl@0: #endif sl@0: sl@0: #ifdef OPENSSL_SYS_VMS sl@0: static struct IOSB iosb; sl@0: static $DESCRIPTOR(terminal,"TT"); sl@0: static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */ sl@0: static long status; sl@0: static unsigned short channel = 0; sl@0: #else sl@0: #ifndef SYMBIAN sl@0: #if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__) sl@0: static TTY_STRUCT tty_orig,tty_new; sl@0: #endif sl@0: #endif sl@0: #endif sl@0: #ifndef EMULATOR sl@0: static FILE *tty_in, *tty_out; sl@0: static int is_a_tty; sl@0: #else sl@0: GET_STATIC_VAR_FROM_TLS(tty_in,ui_openssl,FILE *) sl@0: #define tty_in (*GET_WSD_VAR_NAME(tty_in,ui_openssl, s)()) sl@0: sl@0: GET_STATIC_VAR_FROM_TLS(tty_out,ui_openssl,FILE *) sl@0: #define tty_out (*GET_WSD_VAR_NAME(tty_out,ui_openssl, s)()) sl@0: sl@0: GET_STATIC_VAR_FROM_TLS(is_a_tty,ui_openssl,int) sl@0: #define is_a_tty (*GET_WSD_VAR_NAME(is_a_tty,ui_openssl, s)()) sl@0: sl@0: #endif sl@0: /* Declare static functions */ sl@0: #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) sl@0: static void read_till_nl(FILE *); sl@0: static void recsig(int); sl@0: static void pushsig(void); sl@0: static void popsig(void); sl@0: #endif sl@0: #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) sl@0: static int noecho_fgets(char *buf, int size, FILE *tty); sl@0: #endif sl@0: static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl); sl@0: sl@0: static int read_string(UI *ui, UI_STRING *uis); sl@0: static int write_string(UI *ui, UI_STRING *uis); sl@0: sl@0: static int open_console(UI *ui); sl@0: static int echo_console(UI *ui); sl@0: static int noecho_console(UI *ui); sl@0: static int close_console(UI *ui); sl@0: sl@0: #ifndef EMULATOR sl@0: static UI_METHOD ui_openssl = sl@0: { sl@0: "OpenSSL default user interface", sl@0: open_console, sl@0: write_string, sl@0: NULL, /* No flusher is needed for command lines */ sl@0: read_string, sl@0: close_console, sl@0: NULL sl@0: }; sl@0: #else sl@0: GET_STATIC_VAR_FROM_TLS(ui_openssl,ui_openssl,UI_METHOD) sl@0: #define ui_openssl (*GET_WSD_VAR_NAME(ui_openssl,ui_openssl, s)()) sl@0: const UI_METHOD temp_s_ui_openssl = sl@0: { sl@0: "OpenSSL default user interface", sl@0: open_console, sl@0: write_string, sl@0: NULL, /* No flusher is needed for command lines */ sl@0: read_string, sl@0: close_console, sl@0: NULL sl@0: }; sl@0: sl@0: #endif sl@0: /* The method with all the built-in thingies */ sl@0: EXPORT_C UI_METHOD *UI_OpenSSL(void) sl@0: { sl@0: return &ui_openssl; sl@0: } sl@0: sl@0: /* The following function makes sure that info and error strings are printed sl@0: before any prompt. */ sl@0: static int write_string(UI *ui, UI_STRING *uis) sl@0: { sl@0: switch (UI_get_string_type(uis)) sl@0: { sl@0: case UIT_ERROR: sl@0: case UIT_INFO: sl@0: fputs(UI_get0_output_string(uis), tty_out); sl@0: fflush(tty_out); sl@0: break; sl@0: default: sl@0: break; sl@0: } sl@0: return 1; sl@0: } sl@0: sl@0: static int read_string(UI *ui, UI_STRING *uis) sl@0: { sl@0: int ok = 0; sl@0: sl@0: switch (UI_get_string_type(uis)) sl@0: { sl@0: case UIT_BOOLEAN: sl@0: fputs(UI_get0_output_string(uis), tty_out); sl@0: fputs(UI_get0_action_string(uis), tty_out); sl@0: fflush(tty_out); sl@0: return read_string_inner(ui, uis, sl@0: UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0); sl@0: case UIT_PROMPT: sl@0: fputs(UI_get0_output_string(uis), tty_out); sl@0: fflush(tty_out); sl@0: return read_string_inner(ui, uis, sl@0: UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1); sl@0: case UIT_VERIFY: sl@0: fprintf(tty_out,"Verifying - %s", sl@0: UI_get0_output_string(uis)); sl@0: fflush(tty_out); sl@0: if ((ok = read_string_inner(ui, uis, sl@0: UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0) sl@0: return ok; sl@0: if (strcmp(UI_get0_result_string(uis), sl@0: UI_get0_test_string(uis)) != 0) sl@0: { sl@0: fprintf(tty_out,"Verify failure\n"); sl@0: fflush(tty_out); sl@0: return 0; sl@0: } sl@0: break; sl@0: default: sl@0: break; sl@0: } sl@0: return 1; sl@0: } sl@0: sl@0: #ifndef SYMBIAN sl@0: #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) sl@0: /* Internal functions to read a string without echoing */ sl@0: static void read_till_nl(FILE *in) sl@0: { sl@0: #define SIZE 4 sl@0: char buf[SIZE+1]; sl@0: sl@0: do { sl@0: fgets(buf,SIZE,in); sl@0: } while (strchr(buf,'\n') == NULL); sl@0: } sl@0: sl@0: static volatile sig_atomic_t intr_signal; sl@0: #endif sl@0: #endif sl@0: static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) sl@0: { sl@0: static int ps; sl@0: int ok; sl@0: char result[BUFSIZ]; sl@0: int maxsize = BUFSIZ-1; sl@0: #ifndef SYMBIAN sl@0: #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) sl@0: char *p; sl@0: sl@0: intr_signal=0; sl@0: ok=0; sl@0: ps=0; sl@0: sl@0: pushsig(); sl@0: ps=1; sl@0: sl@0: if (!echo && !noecho_console(ui)) sl@0: goto error; sl@0: ps=2; sl@0: sl@0: result[0]='\0'; sl@0: #ifdef OPENSSL_SYS_MSDOS sl@0: if (!echo) sl@0: { sl@0: noecho_fgets(result,maxsize,tty_in); sl@0: p=result; /* FIXME: noecho_fgets doesn't return errors */ sl@0: } sl@0: else sl@0: p=fgets(result,maxsize,tty_in); sl@0: #else sl@0: p=fgets(result,maxsize,tty_in); sl@0: #endif sl@0: if(!p) sl@0: goto error; sl@0: if (feof(tty_in)) goto error; sl@0: if (ferror(tty_in)) goto error; sl@0: if ((p=(char *)strchr(result,'\n')) != NULL) sl@0: { sl@0: if (strip_nl) sl@0: *p='\0'; sl@0: } sl@0: else sl@0: read_till_nl(tty_in); sl@0: if (UI_set_result(ui, uis, result) >= 0) sl@0: ok=1; sl@0: sl@0: error: sl@0: if (intr_signal == SIGINT) sl@0: ok=-1; sl@0: if (!echo) fprintf(tty_out,"\n"); sl@0: if (ps >= 2 && !echo && !echo_console(ui)) sl@0: ok=0; sl@0: sl@0: if (ps >= 1) sl@0: popsig(); sl@0: #else sl@0: ok=1; sl@0: #endif sl@0: #endif sl@0: OPENSSL_cleanse(result,BUFSIZ); sl@0: return ok; sl@0: } sl@0: sl@0: sl@0: /* Internal functions to open, handle and close a channel to the console. */ sl@0: static int open_console(UI *ui) sl@0: { sl@0: CRYPTO_w_lock(CRYPTO_LOCK_UI); sl@0: is_a_tty = 1; sl@0: sl@0: #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) sl@0: tty_in=stdin; sl@0: tty_out=stderr; sl@0: #else sl@0: # ifdef OPENSSL_SYS_MSDOS sl@0: # define DEV_TTY "con" sl@0: # else sl@0: # define DEV_TTY "/dev/tty" sl@0: # endif sl@0: if ((tty_in=fopen(DEV_TTY,"r")) == NULL) sl@0: tty_in=stdin; sl@0: if ((tty_out=fopen(DEV_TTY,"w")) == NULL) sl@0: tty_out=stderr; sl@0: #endif sl@0: sl@0: #if defined(TTY_get) && !defined(OPENSSL_SYS_VMS) sl@0: if (TTY_get(fileno(tty_in),&tty_orig) == -1) sl@0: { sl@0: #ifdef ENOTTY sl@0: if (errno == ENOTTY) sl@0: is_a_tty=0; sl@0: else sl@0: #endif sl@0: #ifdef EINVAL sl@0: /* Ariel Glenn ariel@columbia.edu reports that solaris sl@0: * can return EINVAL instead. This should be ok */ sl@0: if (errno == EINVAL) sl@0: is_a_tty=0; sl@0: else sl@0: #endif sl@0: return 0; sl@0: } sl@0: #endif sl@0: #ifdef OPENSSL_SYS_VMS sl@0: status = sys$assign(&terminal,&channel,0,0); sl@0: if (status != SS$_NORMAL) sl@0: return 0; sl@0: status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); sl@0: if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) sl@0: return 0; sl@0: #endif sl@0: return 1; sl@0: } sl@0: sl@0: static int noecho_console(UI *ui) sl@0: { sl@0: #ifdef TTY_FLAGS sl@0: memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); sl@0: tty_new.TTY_FLAGS &= ~ECHO; sl@0: #endif sl@0: sl@0: #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) sl@0: if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) sl@0: return 0; sl@0: #endif sl@0: #ifdef OPENSSL_SYS_VMS sl@0: tty_new[0] = tty_orig[0]; sl@0: tty_new[1] = tty_orig[1] | TT$M_NOECHO; sl@0: tty_new[2] = tty_orig[2]; sl@0: status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); sl@0: if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) sl@0: return 0; sl@0: #endif sl@0: return 1; sl@0: } sl@0: sl@0: static int echo_console(UI *ui) sl@0: { sl@0: #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) sl@0: memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); sl@0: tty_new.TTY_FLAGS |= ECHO; sl@0: #endif sl@0: sl@0: #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) sl@0: if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1)) sl@0: return 0; sl@0: #endif sl@0: #ifdef OPENSSL_SYS_VMS sl@0: tty_new[0] = tty_orig[0]; sl@0: tty_new[1] = tty_orig[1] & ~TT$M_NOECHO; sl@0: tty_new[2] = tty_orig[2]; sl@0: status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); sl@0: if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) sl@0: return 0; sl@0: #endif sl@0: return 1; sl@0: } sl@0: sl@0: static int close_console(UI *ui) sl@0: { sl@0: if (tty_in != stdin) fclose(tty_in); sl@0: if (tty_out != stderr) fclose(tty_out); sl@0: #ifdef OPENSSL_SYS_VMS sl@0: status = sys$dassgn(channel); sl@0: #endif sl@0: CRYPTO_w_unlock(CRYPTO_LOCK_UI); sl@0: sl@0: return 1; sl@0: } sl@0: sl@0: sl@0: #ifndef SYMBIAN sl@0: #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) sl@0: /* Internal functions to handle signals and act on them */ sl@0: static void pushsig(void) sl@0: { sl@0: #ifndef OPENSSL_SYS_WIN32 sl@0: int i; sl@0: #endif sl@0: #ifdef SIGACTION sl@0: struct sigaction sa; sl@0: sl@0: memset(&sa,0,sizeof sa); sl@0: sa.sa_handler=recsig; sl@0: #endif sl@0: sl@0: #ifdef OPENSSL_SYS_WIN32 sl@0: savsig[SIGABRT]=signal(SIGABRT,recsig); sl@0: savsig[SIGFPE]=signal(SIGFPE,recsig); sl@0: savsig[SIGILL]=signal(SIGILL,recsig); sl@0: savsig[SIGINT]=signal(SIGINT,recsig); sl@0: savsig[SIGSEGV]=signal(SIGSEGV,recsig); sl@0: savsig[SIGTERM]=signal(SIGTERM,recsig); sl@0: #else sl@0: for (i=1; i