Updated to libdes 4.01
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1923 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
/* lib/des/read_pwd.c */
|
||||
/* Copyright (C) 1995 Eric Young (eay@mincom.oz.au)
|
||||
/* crypto/des/read_pwd.c */
|
||||
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of an SSL implementation written
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@mincom.oz.au).
|
||||
* The implementation was written so as to conform with Netscapes SSL
|
||||
* specification. This library and applications are
|
||||
* FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
|
||||
* as long as the following conditions are aheared to.
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* 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).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed. If this code is used in a product,
|
||||
* Eric Young should be given attribution as the author of the parts used.
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
@@ -25,7 +30,13 @@
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Eric Young (eay@mincom.oz.au)
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@mincom.oz.au)"
|
||||
* 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 SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
@@ -45,34 +56,40 @@
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifdef WIN16TTY
|
||||
#undef WIN16
|
||||
#undef _WINDOWS
|
||||
#include <graph.h>
|
||||
#endif
|
||||
|
||||
/* 06-Apr-92 Luke Brennan Support for VMS */
|
||||
#include "des_locl.h"
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef WIN32 /* Visual C++ 4.0 (Windows95/NT) */
|
||||
#include "passwd_dlg.h"
|
||||
#endif /* WIN32 */
|
||||
|
||||
/* There are 5 types of terminal interface supported,
|
||||
* TERMIO, TERMIOS, VMS, MSDOS and SGTTY
|
||||
*/
|
||||
|
||||
/* Now there are also support for Windows95/NT inteface
|
||||
* d93-jka 960530
|
||||
*/
|
||||
#if defined(sgi) || defined(__sgi)
|
||||
#if defined(__sgi) && !defined(TERMIOS)
|
||||
#define TERMIOS
|
||||
#undef TERMIO
|
||||
#undef SGTTY
|
||||
#endif
|
||||
|
||||
#if defined(linux) && !defined(TERMIO)
|
||||
#undef TERMIOS
|
||||
#define TERMIO
|
||||
#undef SGTTY
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
#define TERMIO
|
||||
#endif
|
||||
|
||||
#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) && !defined(WIN32)
|
||||
#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS)
|
||||
#define SGTTY
|
||||
#endif
|
||||
|
||||
@@ -100,7 +117,7 @@
|
||||
#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBC) && !defined(MSDOS) && !defined(WIN32)
|
||||
#if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS)
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
@@ -115,10 +132,10 @@
|
||||
#include <ttdef.h>
|
||||
#include <descrip.h>
|
||||
struct IOSB {
|
||||
short iosb$w_value;
|
||||
short iosb$w_count;
|
||||
long iosb$l_info;
|
||||
};
|
||||
short iosb$w_value;
|
||||
short iosb$w_count;
|
||||
long iosb$l_info;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef NX509_SIG
|
||||
@@ -131,7 +148,7 @@ 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);
|
||||
#ifdef MSDOS
|
||||
#if defined(MSDOS) && !defined(WIN16)
|
||||
static int noecho_fgets(char *buf, int size, FILE *tty);
|
||||
#endif
|
||||
#else
|
||||
@@ -140,257 +157,294 @@ static int read_pw();
|
||||
static void recsig();
|
||||
static void pushsig();
|
||||
static void popsig();
|
||||
#ifdef MSDOS
|
||||
#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])();
|
||||
#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];
|
||||
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);
|
||||
}
|
||||
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];
|
||||
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);
|
||||
}
|
||||
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;
|
||||
{
|
||||
char buff[BUFSIZ];
|
||||
int ret;
|
||||
char *buf;
|
||||
int length;
|
||||
char *prompt;
|
||||
int verify;
|
||||
{
|
||||
char buff[BUFSIZ];
|
||||
int ret;
|
||||
|
||||
ret=read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
|
||||
memset(buff,0,BUFSIZ);
|
||||
return(ret);
|
||||
}
|
||||
ret=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;
|
||||
{
|
||||
FILE *in;
|
||||
{
|
||||
#define SIZE 4
|
||||
char buf[SIZE+1];
|
||||
char buf[SIZE+1];
|
||||
|
||||
do {
|
||||
fgets(buf,SIZE,in);
|
||||
} while (strchr(buf,'\n') == NULL);
|
||||
}
|
||||
|
||||
do {
|
||||
fgets(buf,SIZE,in);
|
||||
} while (strchr(buf,'\n') == NULL);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
{
|
||||
#ifdef WIN32 /* Visual C++ 4.0 (Windows95/NT) */
|
||||
return pwd_dialog(buf, size);
|
||||
#else /* !WIN32 */
|
||||
char *buf;
|
||||
char *buff;
|
||||
int size;
|
||||
char *prompt;
|
||||
int verify;
|
||||
{
|
||||
#ifdef VMS
|
||||
struct IOSB iosb;
|
||||
$DESCRIPTOR(terminal,"TT");
|
||||
long tty_orig[3], tty_new[3];
|
||||
long status;
|
||||
unsigned short channel = 0;
|
||||
struct IOSB iosb;
|
||||
$DESCRIPTOR(terminal,"TT");
|
||||
long tty_orig[3], tty_new[3];
|
||||
long status;
|
||||
unsigned short channel = 0;
|
||||
#else
|
||||
#ifndef MSDOS
|
||||
TTY_STRUCT tty_orig,tty_new;
|
||||
TTY_STRUCT tty_orig,tty_new;
|
||||
#endif
|
||||
#endif
|
||||
int number=5;
|
||||
int ok=0;
|
||||
int ps=0;
|
||||
FILE *tty=NULL;
|
||||
char *p;
|
||||
int number=5;
|
||||
int ok=0;
|
||||
int ps=0;
|
||||
int is_a_tty=1;
|
||||
|
||||
FILE *tty=NULL;
|
||||
char *p;
|
||||
|
||||
#ifdef __CYGWIN32__
|
||||
tty = stdin;
|
||||
tty = stdin;
|
||||
#elif !defined(MSDOS)
|
||||
if ((tty=fopen("/dev/tty","r")) == NULL)
|
||||
tty=stdin;
|
||||
if ((tty=fopen("/dev/tty","r")) == NULL)
|
||||
tty=stdin;
|
||||
#else /* MSDOS */
|
||||
if ((tty=fopen("con","r")) == NULL)
|
||||
tty=stdin;
|
||||
if ((tty=fopen("con","r")) == NULL)
|
||||
tty=stdin;
|
||||
#endif /* MSDOS */
|
||||
|
||||
#if defined(TTY_get) && !defined(VMS)
|
||||
if (TTY_get(fileno(tty),&tty_orig) == -1)
|
||||
return(-1);
|
||||
memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
|
||||
if (TTY_get(fileno(tty),&tty_orig) == -1)
|
||||
{
|
||||
#ifdef ENOTTY
|
||||
if (errno == ENOTTY)
|
||||
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);
|
||||
if (status != SS$_NORMAL)
|
||||
return(-1);
|
||||
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);
|
||||
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);
|
||||
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
||||
return(-1);
|
||||
#endif
|
||||
|
||||
if (setjmp(save))
|
||||
{
|
||||
ok=0;
|
||||
goto error;
|
||||
}
|
||||
pushsig();
|
||||
ps=1;
|
||||
if (setjmp(save))
|
||||
{
|
||||
ok=0;
|
||||
goto error;
|
||||
}
|
||||
pushsig();
|
||||
ps=1;
|
||||
|
||||
#ifdef TTY_FLAGS
|
||||
tty_new.TTY_FLAGS &= ~ECHO;
|
||||
tty_new.TTY_FLAGS &= ~ECHO;
|
||||
#endif
|
||||
|
||||
#if defined(TTY_set) && !defined(VMS)
|
||||
if (TTY_set(fileno(tty),&tty_new) == -1)
|
||||
return(-1);
|
||||
if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1))
|
||||
return(-1);
|
||||
#endif
|
||||
#ifdef VMS
|
||||
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);
|
||||
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
||||
return(-1);
|
||||
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);
|
||||
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
||||
return(-1);
|
||||
#endif
|
||||
ps=2;
|
||||
ps=2;
|
||||
|
||||
while ((!ok) && (number--))
|
||||
{
|
||||
fputs(prompt,stderr);
|
||||
fflush(stderr);
|
||||
|
||||
buf[0]='\0';
|
||||
fgets(buf,size,tty);
|
||||
if (feof(tty)) goto error;
|
||||
if ((p=(char *)strchr(buf,'\n')) != NULL)
|
||||
*p='\0';
|
||||
else read_till_nl(tty);
|
||||
if (verify)
|
||||
while ((!ok) && (number--))
|
||||
{
|
||||
fprintf(stderr,"\nVerifying password %s",prompt);
|
||||
fflush(stderr);
|
||||
buff[0]='\0';
|
||||
fgets(buff,size,tty);
|
||||
if (feof(tty)) goto error;
|
||||
if ((p=(char *)strchr(buff,'\n')) != NULL)
|
||||
fputs(prompt,stderr);
|
||||
fflush(stderr);
|
||||
|
||||
buf[0]='\0';
|
||||
fgets(buf,size,tty);
|
||||
if (feof(tty)) goto error;
|
||||
if (ferror(tty)) goto error;
|
||||
if ((p=(char *)strchr(buf,'\n')) != NULL)
|
||||
*p='\0';
|
||||
else read_till_nl(tty);
|
||||
|
||||
if (strcmp(buf,buff) != 0)
|
||||
else read_till_nl(tty);
|
||||
if (verify)
|
||||
{
|
||||
fprintf(stderr,"\nVerify failure");
|
||||
fflush(stderr);
|
||||
break;
|
||||
/* continue; */
|
||||
fprintf(stderr,"\nVerifying password - %s",prompt);
|
||||
fflush(stderr);
|
||||
buff[0]='\0';
|
||||
fgets(buff,size,tty);
|
||||
if (feof(tty)) goto error;
|
||||
if ((p=(char *)strchr(buff,'\n')) != NULL)
|
||||
*p='\0';
|
||||
else read_till_nl(tty);
|
||||
|
||||
if (strcmp(buf,buff) != 0)
|
||||
{
|
||||
fprintf(stderr,"\nVerify failure");
|
||||
fflush(stderr);
|
||||
break;
|
||||
/* continue; */
|
||||
}
|
||||
}
|
||||
ok=1;
|
||||
}
|
||||
ok=1;
|
||||
}
|
||||
|
||||
error:
|
||||
fprintf(stderr,"\n");
|
||||
/* What can we do if there is an error? */
|
||||
fprintf(stderr,"\n");
|
||||
#ifdef DEBUG
|
||||
perror("fgets(tty)");
|
||||
#endif
|
||||
/* What can we do if there is an error? */
|
||||
#if defined(TTY_set) && !defined(VMS)
|
||||
if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
|
||||
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
|
||||
,tty_orig,12,0,0,0,0);
|
||||
if (ps >= 2)
|
||||
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);
|
||||
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;
|
||||
{
|
||||
memset(buf,0,size);
|
||||
memset(buff,0,size);
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
return(!ok);
|
||||
#endif /* !WIN32 */
|
||||
}
|
||||
|
||||
#ifndef WIN32 /* Visual C++ 4.0 (Windows95/NT) */
|
||||
static void pushsig()
|
||||
{
|
||||
int i;
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=1; i<NX509_SIG; i++)
|
||||
savsig[i]=signal(i,recsig);
|
||||
}
|
||||
for (i=1; i<NX509_SIG; i++)
|
||||
savsig[i]=signal(i,recsig);
|
||||
|
||||
#ifdef SIGWINCH
|
||||
signal(SIGWINCH,SIG_DFL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void popsig()
|
||||
{
|
||||
int i;
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=1; i<NX509_SIG; i++)
|
||||
signal(i,savsig[i]);
|
||||
}
|
||||
for (i=1; i<NX509_SIG; i++)
|
||||
signal(i,savsig[i]);
|
||||
}
|
||||
|
||||
static void recsig(i)
|
||||
int i;
|
||||
{
|
||||
longjmp(save,1);
|
||||
#ifdef LINT
|
||||
i=i;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !WIN32 */
|
||||
|
||||
#ifdef MSDOS
|
||||
static int noecho_fgets(buf,size,tty)
|
||||
char *buf;
|
||||
int size;
|
||||
FILE *tty;
|
||||
{
|
||||
int i,n;
|
||||
char *p;
|
||||
|
||||
p=buf;
|
||||
for (;;)
|
||||
int i;
|
||||
{
|
||||
if (size == 0)
|
||||
{
|
||||
*p='\0';
|
||||
break;
|
||||
}
|
||||
size--;
|
||||
i=getch();
|
||||
if (i == '\r') i='\n';
|
||||
*(p++)=i;
|
||||
if (i == '\n')
|
||||
{
|
||||
*p='\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(strlen(buf));
|
||||
}
|
||||
longjmp(save,1);
|
||||
#ifdef LINT
|
||||
i=i;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(MSDOS) && !defined(WIN16)
|
||||
static int noecho_fgets(buf,size,tty)
|
||||
char *buf;
|
||||
int size;
|
||||
FILE *tty;
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
p=buf;
|
||||
for (;;)
|
||||
{
|
||||
if (size == 0)
|
||||
{
|
||||
*p='\0';
|
||||
break;
|
||||
}
|
||||
size--;
|
||||
#ifdef WIN16TTY
|
||||
i=_inchar();
|
||||
#else
|
||||
i=getch();
|
||||
#endif
|
||||
if (i == '\r') i='\n';
|
||||
*(p++)=i;
|
||||
if (i == '\n')
|
||||
{
|
||||
*p='\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(strlen(buf));
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user