Updated from 3.01 to 3.06 version.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -6,32 +6,25 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
/* Ick! */
|
||||||
|
#if defined(__svr4__) || defined(_IRIX)
|
||||||
|
#define TERMIO
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef VMS
|
#ifndef VMS
|
||||||
#ifndef MSDOS
|
#ifndef MSDOS
|
||||||
#if !(defined(_IRIX) || defined(sgi))
|
#ifdef TERMIO
|
||||||
#ifdef CRAY
|
|
||||||
#include <termio.h>
|
#include <termio.h>
|
||||||
#define sgttyb termio
|
#define sgttyb termio
|
||||||
#define sg_flags c_lflag
|
#define sg_flags c_lflag
|
||||||
#else /* !CRAY */
|
#define TIOCGETP TCGETA
|
||||||
#ifndef USE_TERMIO
|
#define TIOCSETP TCSETA
|
||||||
|
#else /* !TERMIO */
|
||||||
#include <sgtty.h>
|
#include <sgtty.h>
|
||||||
#else
|
|
||||||
#include <termio.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#else /* _IRIX */
|
|
||||||
#define USE_TERMIO
|
|
||||||
#include <termio.h>
|
|
||||||
#define sgttyb termios
|
|
||||||
#define sg_flags c_lflag
|
|
||||||
#endif
|
|
||||||
#else /* MSDOS */
|
#else /* MSDOS */
|
||||||
#define fgets(a,b,c) noecho_fgets(a,b,c)
|
#define fgets(a,b,c) noecho_fgets(a,b,c)
|
||||||
#ifndef NSIG
|
|
||||||
#define NSIG 32
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
#else /* VMS */
|
#else /* VMS */
|
||||||
#include <ssdef.h>
|
#include <ssdef.h>
|
||||||
@@ -39,258 +32,253 @@
|
|||||||
#include <ttdef.h>
|
#include <ttdef.h>
|
||||||
#include <descrip.h>
|
#include <descrip.h>
|
||||||
struct IOSB {
|
struct IOSB {
|
||||||
short iosb$w_value;
|
short iosb$w_value;
|
||||||
short iosb$w_count;
|
short iosb$w_count;
|
||||||
long iosb$l_info;
|
long iosb$l_info;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#ifndef NSIG
|
||||||
|
#define NSIG 32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void read_till_nl(FILE *in);
|
static void read_till_nl();
|
||||||
static int read_pw(char *buf, char *buff, int size, char *prompt, int verify);
|
static int read_pw();
|
||||||
|
static void recsig();
|
||||||
|
static void pushsig();
|
||||||
|
static void popsig();
|
||||||
#ifdef MSDOS
|
#ifdef MSDOS
|
||||||
static int noecho_fgets();
|
static int noecho_fgets();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void (*savsig[NSIG])();
|
static void (*savsig[NSIG])();
|
||||||
static jmp_buf save;
|
static jmp_buf save;
|
||||||
|
|
||||||
static RETSIGTYPE
|
int des_read_password(key,prompt,verify)
|
||||||
recsig()
|
des_cblock *key;
|
||||||
{
|
char *prompt;
|
||||||
longjmp(save,1);
|
int verify;
|
||||||
}
|
{
|
||||||
|
int ok;
|
||||||
static RETSIGTYPE
|
char buf[BUFSIZ],buff[BUFSIZ];
|
||||||
pushsig()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0; i<NSIG; i++)
|
if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
|
||||||
savsig[i]=signal(i,recsig);
|
des_string_to_key(buf,key);
|
||||||
}
|
bzero(buf,BUFSIZ);
|
||||||
|
bzero(buff,BUFSIZ);
|
||||||
|
return(ok);
|
||||||
|
}
|
||||||
|
|
||||||
static RETSIGTYPE
|
int des_read_2passwords(key1,key2,prompt,verify)
|
||||||
popsig()
|
des_cblock *key1;
|
||||||
{
|
des_cblock *key2;
|
||||||
int i;
|
char *prompt;
|
||||||
|
int verify;
|
||||||
|
{
|
||||||
|
int ok;
|
||||||
|
char buf[BUFSIZ],buff[BUFSIZ];
|
||||||
|
|
||||||
for (i=0; i<NSIG; i++)
|
if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
|
||||||
signal(i,savsig[i]);
|
des_string_to_2keys(buf,key1,key2);
|
||||||
}
|
bzero(buf,BUFSIZ);
|
||||||
|
bzero(buff,BUFSIZ);
|
||||||
|
return(ok);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int des_read_pw_string(buf,length,prompt,verify)
|
||||||
des_read_password(des_cblock (*key), char *prompt, int verify)
|
char *buf;
|
||||||
{
|
int length;
|
||||||
int ok;
|
char *prompt;
|
||||||
char buf[BUFSIZ],buff[BUFSIZ];
|
int verify;
|
||||||
|
{
|
||||||
|
char buff[BUFSIZ];
|
||||||
|
int ret;
|
||||||
|
|
||||||
if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
|
ret=read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
|
||||||
des_string_to_key(buf,key);
|
bzero(buff,BUFSIZ);
|
||||||
memset(buf,0,BUFSIZ);
|
return(ret);
|
||||||
memset(buff,0,BUFSIZ);
|
}
|
||||||
return(ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
int des_read_2passwords(des_cblock (*key1), des_cblock (*key2), char *prompt, int verify)
|
static void read_till_nl(in)
|
||||||
{
|
FILE *in;
|
||||||
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(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void read_till_nl(FILE *in)
|
|
||||||
{
|
|
||||||
#define SIZE 4
|
#define SIZE 4
|
||||||
char buf[SIZE+1];
|
char buf[SIZE+1];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
fgets(buf,SIZE,in);
|
fgets(buf,SIZE,in);
|
||||||
} while (strchr(buf,'\n') == NULL);
|
} while (strchr(buf,'\n') == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return 0 if ok, 1 (or -1) otherwise */
|
/* return 0 if ok, 1 (or -1) otherwise */
|
||||||
static int
|
static int read_pw(buf,buff,size,prompt,verify)
|
||||||
read_pw(char *buf, char *buff, int size, char *prompt, int verify)
|
char *buf,*buff;
|
||||||
{
|
int size;
|
||||||
|
char *prompt;
|
||||||
|
int verify;
|
||||||
|
{
|
||||||
#ifndef VMS
|
#ifndef VMS
|
||||||
#ifndef MSDOS
|
#ifndef MSDOS
|
||||||
#ifndef USE_TERMIO
|
struct sgttyb tty_orig,tty_new;
|
||||||
struct sgttyb tty_orig,tty_new;
|
|
||||||
#else
|
|
||||||
struct termios tty_orig, tty_new;
|
|
||||||
#endif
|
|
||||||
#endif /* !MSDOS */
|
#endif /* !MSDOS */
|
||||||
#else
|
#else
|
||||||
struct IOSB iosb;
|
struct IOSB iosb;
|
||||||
$DESCRIPTOR(terminal,"TT");
|
$DESCRIPTOR(terminal,"TT");
|
||||||
long tty_orig[3], tty_new[3];
|
long tty_orig[3], tty_new[3];
|
||||||
long status;
|
long status;
|
||||||
unsigned short channel = 0;
|
unsigned short channel = 0;
|
||||||
#endif
|
#endif
|
||||||
volatile int ok=0;
|
int ok=0;
|
||||||
char *p;
|
char *p;
|
||||||
volatile int ps=0;
|
int ps=0;
|
||||||
FILE *tty;
|
FILE *tty;
|
||||||
|
|
||||||
#ifndef MSDOS
|
#ifndef MSDOS
|
||||||
if ((tty=fopen("/dev/tty","r")) == NULL)
|
if ((tty=fopen("/dev/tty","r")) == NULL)
|
||||||
tty=stdin;
|
tty=stdin;
|
||||||
#else /* MSDOS */
|
#else /* MSDOS */
|
||||||
if ((tty=fopen("con","r")) == NULL)
|
if ((tty=fopen("con","r")) == NULL)
|
||||||
tty=stdin;
|
tty=stdin;
|
||||||
#endif /* MSDOS */
|
#endif /* MSDOS */
|
||||||
#ifndef VMS
|
#ifndef VMS
|
||||||
#ifdef TIOCGETP
|
#ifdef TIOCGETP
|
||||||
#ifdef USE_TERMIO
|
if (ioctl(fileno(tty),TIOCGETP,(char *)&tty_orig) == -1)
|
||||||
if (tcgetattr(fileno(tty), &tty_orig) == -1)
|
return(-1);
|
||||||
return(-1);
|
bcopy(&(tty_orig),&(tty_new),sizeof(tty_orig));
|
||||||
#else
|
|
||||||
if (ioctl(fileno(tty),TIOCGETP,(char *)&tty_orig) == -1)
|
|
||||||
return(-1);
|
|
||||||
#endif
|
#endif
|
||||||
memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
|
#else /* VMS */
|
||||||
#endif
|
status = SYS$ASSIGN(&terminal,&channel,0,0);
|
||||||
#else /* VMS */
|
if (status != SS$_NORMAL)
|
||||||
status = SYS$ASSIGN(&terminal,&channel,0,0);
|
return(-1);
|
||||||
if (status != SS$_NORMAL)
|
status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
|
||||||
return(-1);
|
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
||||||
status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
|
return(-1);
|
||||||
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
|
||||||
return(-1);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (setjmp(save))
|
if (setjmp(save))
|
||||||
{
|
{
|
||||||
ok=0;
|
ok=0;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
pushsig();
|
pushsig();
|
||||||
ps=1;
|
ps=1;
|
||||||
#ifndef VMS
|
#ifndef VMS
|
||||||
#ifndef MSDOS
|
#ifndef MSDOS
|
||||||
#ifndef USE_TERMIO
|
tty_new.sg_flags &= ~ECHO;
|
||||||
tty_new.sg_flags &= ~ECHO;
|
|
||||||
#else
|
|
||||||
tty_new.c_lflag &= ~ECHO;
|
|
||||||
#endif
|
|
||||||
#endif /* !MSDOS */
|
#endif /* !MSDOS */
|
||||||
#ifdef TIOCSETP
|
#ifdef TIOCSETP
|
||||||
#ifdef USE_TERMIO
|
if (ioctl(fileno(tty),TIOCSETP,(char *)&tty_new) == -1)
|
||||||
if (tcsetattr(fileno(tty), TCSANOW, &tty_new) == -1)
|
return(-1);
|
||||||
return(-1);
|
|
||||||
#else
|
|
||||||
if (ioctl(fileno(tty),TIOCSETP,(char *)&tty_new) == -1)
|
|
||||||
return(-1);
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#else /* VMS */
|
||||||
#else /* VMS */
|
tty_new[0] = tty_orig[0];
|
||||||
tty_new[0] = tty_orig[0];
|
tty_new[1] = tty_orig[1] | TT$M_NOECHO;
|
||||||
tty_new[1] = tty_orig[1] | TT$M_NOECHO;
|
tty_new[2] = tty_orig[2];
|
||||||
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))
|
||||||
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
return(-1);
|
||||||
return(-1);
|
|
||||||
#endif /* VMS */
|
#endif /* VMS */
|
||||||
ps=2;
|
ps=2;
|
||||||
|
|
||||||
while (!ok)
|
while (!ok)
|
||||||
{
|
{
|
||||||
fputs(prompt,stderr);
|
fputs(prompt,stderr);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
||||||
buf[0]='\0';
|
buf[0]='\0';
|
||||||
fgets(buf,size,tty);
|
fgets(buf,size,tty);
|
||||||
if (feof(tty)) goto error;
|
if (feof(tty)) goto error;
|
||||||
if ((p=(char *)strchr(buf,'\n')) != NULL)
|
if ((p=(char *)strchr(buf,'\n')) != NULL)
|
||||||
*p='\0';
|
*p='\0';
|
||||||
else read_till_nl(tty);
|
else read_till_nl(tty);
|
||||||
if (verify)
|
if (verify)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"\nVerifying password %s",prompt);
|
fprintf(stderr,"\nVerifying password %s",prompt);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
buff[0]='\0';
|
buff[0]='\0';
|
||||||
fgets(buff,size,tty);
|
fgets(buff,size,tty);
|
||||||
if (feof(tty)) goto error;
|
if (feof(tty)) goto error;
|
||||||
if ((p=(char *)strchr(buff,'\n')) != NULL)
|
if ((p=(char *)strchr(buff,'\n')) != NULL)
|
||||||
*p='\0';
|
*p='\0';
|
||||||
else read_till_nl(tty);
|
else read_till_nl(tty);
|
||||||
|
|
||||||
if (strcmp(buf,buff) != 0)
|
if (strcmp(buf,buff) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"\nVerify failure - try again\n");
|
fprintf(stderr,"\nVerify failure - try again\n");
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ok=1;
|
ok=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
fprintf(stderr,"\n");
|
fprintf(stderr,"\n");
|
||||||
/* What can we do if there is an error? */
|
/* What can we do if there is an error? */
|
||||||
#ifndef VMS
|
#ifndef VMS
|
||||||
#ifdef TIOCSETP
|
#ifdef TIOCSETP
|
||||||
#ifdef USE_TERMIO
|
if (ps >= 2) ioctl(fileno(tty),TIOCSETP,(char *)&tty_orig);
|
||||||
if (ps >= 2) tcsetattr(fileno(tty), TCSANOW, &tty_orig);
|
|
||||||
#else
|
|
||||||
if (ps >= 2) ioctl(fileno(tty),TIOCSETP,(char *)&tty_orig);
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#else /* VMS */
|
||||||
#else /* VMS */
|
if (ps >= 2)
|
||||||
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);
|
||||||
,tty_orig,12,0,0,0,0);
|
|
||||||
#endif /* VMS */
|
#endif /* VMS */
|
||||||
|
|
||||||
if (ps >= 1) popsig();
|
if (ps >= 1) popsig();
|
||||||
if (stdin != tty) fclose(tty);
|
if (stdin != tty) fclose(tty);
|
||||||
#ifdef VMS
|
#ifdef VMS
|
||||||
status = SYS$DASSGN(channel);
|
status = SYS$DASSGN(channel);
|
||||||
#endif
|
#endif
|
||||||
return(!ok);
|
return(!ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void pushsig()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<NSIG; i++)
|
||||||
|
savsig[i]=signal(i,recsig);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void popsig()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<NSIG; i++)
|
||||||
|
signal(i,savsig[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void recsig()
|
||||||
|
{
|
||||||
|
longjmp(save,1);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef MSDOS
|
#ifdef MSDOS
|
||||||
static int noecho_fgets(buf,size,tty)
|
static int noecho_fgets(buf,size,tty)
|
||||||
char *buf;
|
char *buf;
|
||||||
int size;
|
int size;
|
||||||
FILE *tty;
|
FILE *tty;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
p=buf;
|
p=buf;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
*p='\0';
|
*p='\0';
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
size--;
|
||||||
|
i=getch();
|
||||||
|
if (i == '\r') i='\n';
|
||||||
|
*(p++)=i;
|
||||||
|
if (i == '\n')
|
||||||
|
{
|
||||||
|
*p='\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
size--;
|
|
||||||
i=getch();
|
|
||||||
if (i == '\r') i='\n';
|
|
||||||
*(p++)=i;
|
|
||||||
if (i == '\n')
|
|
||||||
{
|
|
||||||
*p='\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user