diff options
Diffstat (limited to 'crypto/libdes/read_pwd.c')
-rw-r--r-- | crypto/libdes/read_pwd.c | 242 |
1 files changed, 138 insertions, 104 deletions
diff --git a/crypto/libdes/read_pwd.c b/crypto/libdes/read_pwd.c index 2f4b9ee..fed4965 100644 --- a/crypto/libdes/read_pwd.c +++ b/crypto/libdes/read_pwd.c @@ -1,9 +1,9 @@ /* crypto/des/read_pwd.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written - * by Eric Young (eay@mincom.oz.au). + * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as @@ -11,7 +11,7 @@ * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@mincom.oz.au). + * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. @@ -31,12 +31,12 @@ * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by - * Eric Young (eay@mincom.oz.au)" + * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)" + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -56,6 +56,23 @@ * [including the GNU Public Licence.] */ +#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) +#include <openssl/opensslconf.h> +#include OPENSSL_UNISTD +/* 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 @@ -64,32 +81,51 @@ /* 06-Apr-92 Luke Brennan Support for VMS */ #include "des_locl.h" +#include "cryptlib.h" #include <signal.h> +#include <stdio.h> #include <string.h> #include <setjmp.h> #include <errno.h> +#ifdef VMS /* prototypes for sys$whatever */ +#include <starlet.h> +#ifdef __DECC +#pragma message disable DOLLARID +#endif +#endif + +#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 */ #if defined(__sgi) && !defined(TERMIOS) #define TERMIOS -#undef TERMIO -#undef SGTTY +#undef TERMIO +#undef SGTTY #endif #if defined(linux) && !defined(TERMIO) -#undef TERMIOS +#undef TERMIOS #define TERMIO -#undef SGTTY +#undef SGTTY #endif #ifdef _LIBC +#undef TERMIOS #define TERMIO +#undef SGTTY #endif #if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) +#undef TERMIOS +#undef TERMIO #define SGTTY #endif @@ -142,82 +178,34 @@ struct IOSB { #define NX509_SIG 32 #endif -#ifndef NOPROTO static void read_till_nl(FILE *); -static int read_pw(char *buf, char *buff, int size, char *prompt, int verify); static void recsig(int); static void pushsig(void); static void popsig(void); #if defined(MSDOS) && !defined(WIN16) static int noecho_fgets(char *buf, int size, FILE *tty); #endif +#ifdef SIGACTION + static struct sigaction savsig[NX509_SIG]; #else -static void read_till_nl(); -static int read_pw(); -static void recsig(); -static void pushsig(); -static void popsig(); -#if defined(MSDOS) && !defined(WIN16) -static int noecho_fgets(); -#endif -#endif - -#ifndef NOPROTO -static void (*savsig[NX509_SIG])(int ); -#else -static void (*savsig[NX509_SIG])(); + static void (*savsig[NX509_SIG])(int ); #endif static jmp_buf save; -int des_read_password(key, prompt, verify) -des_cblock (*key); -char *prompt; -int verify; - { - int ok; - char buf[BUFSIZ],buff[BUFSIZ]; - - if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0) - des_string_to_key(buf,key); - memset(buf,0,BUFSIZ); - memset(buff,0,BUFSIZ); - return(ok); - } - -int des_read_2passwords(key1, key2, prompt, verify) -des_cblock (*key1); -des_cblock (*key2); -char *prompt; -int verify; - { - int ok; - char buf[BUFSIZ],buff[BUFSIZ]; - - if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0) - des_string_to_2keys(buf,key1,key2); - memset(buf,0,BUFSIZ); - memset(buff,0,BUFSIZ); - return(ok); - } - -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; - ret=read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); + ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); memset(buff,0,BUFSIZ); return(ret); } #ifndef WIN16 -static void read_till_nl(in) -FILE *in; +static void read_till_nl(FILE *in) { #define SIZE 4 char buf[SIZE+1]; @@ -229,12 +217,8 @@ FILE *in; /* return 0 if ok, 1 (or -1) otherwise */ -static int 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, const char *prompt, + int verify) { #ifdef VMS struct IOSB iosb; @@ -247,17 +231,28 @@ 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; -#ifdef __CYGWIN32__ - tty = stdin; -#elif !defined(MSDOS) + 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; #else /* MSDOS */ @@ -273,24 +268,26 @@ int verify; is_a_tty=0; else #endif +#ifdef EINVAL + /* Ariel Glenn ariel@columbia.edu reports that solaris + * can return EINVAL instead. This should be ok */ + if (errno == EINVAL) + is_a_tty=0; + else +#endif return(-1); } memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); #endif #ifdef VMS - status = SYS$ASSIGN(&terminal,&channel,0,0); + status = sys$assign(&terminal,&channel,0,0); if (status != SS$_NORMAL) return(-1); - status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); + status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) return(-1); #endif - if (setjmp(save)) - { - ok=0; - goto error; - } pushsig(); ps=1; @@ -306,7 +303,7 @@ int verify; tty_new[0] = tty_orig[0]; tty_new[1] = tty_orig[1] | TT$M_NOECHO; tty_new[2] = tty_orig[2]; - status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); + status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) return(-1); #endif @@ -352,31 +349,26 @@ error: perror("fgets(tty)"); #endif /* What can we do if there is an error? */ -#if defined(TTY_set) && !defined(VMS) +#if defined(TTY_set) && !defined(VMS) if (ps >= 2) TTY_set(fileno(tty),&tty_orig); #endif #ifdef VMS if (ps >= 2) - status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0 + status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0 ,tty_orig,12,0,0,0,0); #endif if (ps >= 1) popsig(); if (stdin != tty) fclose(tty); #ifdef VMS - status = SYS$DASSGN(channel); + status = sys$dassgn(channel); #endif return(!ok); } #else /* WIN16 */ -static int 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); @@ -385,28 +377,61 @@ 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++) + { +#ifdef SIGUSR1 + if (i == SIGUSR1) + continue; +#endif +#ifdef SIGUSR2 + if (i == SIGUSR2) + continue; +#endif +#ifdef SIGACTION + sigaction(i,&sa,&savsig[i]); +#else savsig[i]=signal(i,recsig); +#endif + } #ifdef SIGWINCH signal(SIGWINCH,SIG_DFL); #endif } -static void popsig() +static void popsig(void) { int i; for (i=1; i<NX509_SIG; i++) + { +#ifdef SIGUSR1 + if (i == SIGUSR1) + continue; +#endif +#ifdef SIGUSR2 + if (i == SIGUSR2) + continue; +#endif +#ifdef SIGACTION + sigaction(i,&savsig[i],NULL); +#else signal(i,savsig[i]); +#endif + } } -static void recsig(i) -int i; +static void recsig(int i) { longjmp(save,1); #ifdef LINT @@ -415,10 +440,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; @@ -445,6 +467,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 |