Remove NOPROTO definitions and error code comments.
[openssl.git] / crypto / des / read_pwd.c
index dfc61cf0d9cd8176ba5b9f3506f7bd3201232e86..24e814ec76e4994e51ed1ec5c6eafb142383d483 100644 (file)
  * [including the GNU Public Licence.]
  */
 
+#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32)
+#include <unistd.h>
+/* If unistd.h defines _POSIX_VERSION, we conclude that we
+ * are on a POSIX system and have sigaction and termios. */
+#if defined(_POSIX_VERSION)
+
+# define SIGACTION
+# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
+# define TERMIOS
+# endif
+
+#endif
+#endif
+
 /* #define SIGACTION */ /* Define this if you have sigaction() */
+
 #ifdef WIN16TTY
 #undef WIN16
 #undef _WINDOWS
 
 /* 06-Apr-92 Luke Brennan    Support for VMS */
 #include "des_locl.h"
+#include "cryptlib.h"
 #include <signal.h>
 #include <string.h>
 #include <setjmp.h>
 #include <errno.h>
 
+#ifdef WIN_CONSOLE_BUG
+#include <windows.h>
+#include <wincon.h>
+#endif
+
+
 /* There are 5 types of terminal interface supported,
  * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
  */
@@ -147,7 +169,6 @@ struct IOSB {
 #define NX509_SIG 32
 #endif
 
-#ifndef NOPROTO
 static void read_till_nl(FILE *);
 static void recsig(int);
 static void pushsig(void);
@@ -155,16 +176,6 @@ static void popsig(void);
 #if defined(MSDOS) && !defined(WIN16)
 static int noecho_fgets(char *buf, int size, FILE *tty);
 #endif
-#else
-static void read_till_nl();
-static void recsig();
-static void pushsig();
-static void popsig();
-#if defined(MSDOS) && !defined(WIN16)
-static int noecho_fgets();
-#endif
-#endif
-
 #ifdef SIGACTION
  static struct sigaction savsig[NX509_SIG];
 #else
@@ -176,11 +187,8 @@ static int noecho_fgets();
 #endif
 static jmp_buf save;
 
-int des_read_pw_string(buf, length, prompt, verify)
-char *buf;
-int length;
-char *prompt;
-int verify;
+int des_read_pw_string(char *buf, int length, const char *prompt,
+            int verify)
        {
        char buff[BUFSIZ];
        int ret;
@@ -192,8 +200,7 @@ int verify;
 
 #ifndef WIN16
 
-static void read_till_nl(in)
-FILE *in;
+static void read_till_nl(FILE *in)
        {
 #define SIZE 4
        char buf[SIZE+1];
@@ -205,12 +212,8 @@ FILE *in;
 
 
 /* return 0 if ok, 1 (or -1) otherwise */
-int des_read_pw(buf, buff, size, prompt, verify)
-char *buf;
-char *buff;
-int size;
-const char *prompt;
-int verify;
+int des_read_pw(char *buf, char *buff, int size, const char *prompt,
+            int verify)
        {
 #ifdef VMS
        struct IOSB iosb;
@@ -223,14 +226,27 @@ int verify;
        TTY_STRUCT tty_orig,tty_new;
 #endif
 #endif
-       int number=5;
-       int ok=0;
-       int ps=0;
-       int is_a_tty=1;
-
-       FILE *tty=NULL;
+       int number;
+       int ok;
+       /* statics are simply to avoid warnings about longjmp clobbering
+          things */
+       static int ps;
+       int is_a_tty;
+       static FILE *tty;
        char *p;
 
+       if (setjmp(save))
+               {
+               ok=0;
+               goto error;
+               }
+
+       number=5;
+       ok=0;
+       ps=0;
+       is_a_tty=1;
+       tty=NULL;
+
 #ifndef MSDOS
        if ((tty=fopen("/dev/tty","r")) == NULL)
                tty=stdin;
@@ -267,11 +283,6 @@ int verify;
                return(-1);
 #endif
 
-       if (setjmp(save))
-               {
-               ok=0;
-               goto error;
-               }
        pushsig();
        ps=1;
 
@@ -352,12 +363,7 @@ error:
 
 #else /* WIN16 */
 
-int des_read_pw(buf, buff, size, prompt, verify)
-char *buf;
-char *buff;
-int size;
-char *prompt;
-int verify;
+int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
        { 
        memset(buf,0,size);
        memset(buff,0,size);
@@ -366,9 +372,15 @@ int verify;
 
 #endif
 
-static void pushsig()
+static void pushsig(void)
        {
        int i;
+#ifdef SIGACTION
+       struct sigaction sa;
+
+       memset(&sa,0,sizeof sa);
+       sa.sa_handler=recsig;
+#endif
 
        for (i=1; i<NX509_SIG; i++)
                {
@@ -381,7 +393,7 @@ static void pushsig()
                        continue;
 #endif
 #ifdef SIGACTION
-               sigaction(i,NULL,&savsig[i]);
+               sigaction(i,&sa,&savsig[i]);
 #else
                savsig[i]=signal(i,recsig);
 #endif
@@ -392,7 +404,7 @@ static void pushsig()
 #endif
        }
 
-static void popsig()
+static void popsig(void)
        {
        int i;
 
@@ -414,8 +426,7 @@ static void popsig()
                }
        }
 
-static void recsig(i)
-int i;
+static void recsig(int i)
        {
        longjmp(save,1);
 #ifdef LINT
@@ -424,10 +435,7 @@ int i;
        }
 
 #if defined(MSDOS) && !defined(WIN16)
-static int noecho_fgets(buf,size,tty)
-char *buf;
-int size;
-FILE *tty;
+static int noecho_fgets(char *buf, int size, FILE *tty)
        {
        int i;
        char *p;
@@ -454,6 +462,18 @@ FILE *tty;
                        break;
                        }
                }
+#ifdef WIN_CONSOLE_BUG
+/* Win95 has several evil console bugs: one of these is that the
+ * last character read using getch() is passed to the next read: this is
+ * usually a CR so this can be trouble. No STDIO fix seems to work but
+ * flushing the console appears to do the trick.
+ */
+                {
+                        HANDLE inh;
+                        inh = GetStdHandle(STD_INPUT_HANDLE);
+                        FlushConsoleInputBuffer(inh);
+                }
+#endif
        return(strlen(buf));
        }
 #endif