Merged in libdes3.21-branch

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@473 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1996-05-04 04:44:52 +00:00
parent d2aa6baa26
commit 6961a4a341
63 changed files with 8297 additions and 3326 deletions

View File

@@ -1,35 +1,108 @@
/* read_pwd.c */
/* Copyright (C) 1993 Eric Young - see README for more details */
/* lib/des/read_pwd.c */
/* Copyright (C) 1995 Eric Young (eay@mincom.oz.au)
* All rights reserved.
*
* This file is part of 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.
*
* 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.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 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 SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* 06-Apr-92 Luke Brennan Support for VMS */
#include "des_locl.h"
#include <string.h>
#include <signal.h>
#include <string.h>
#include <setjmp.h>
/* Ick! */
#if defined(__svr4__) || defined(__sgi) || defined(__linux)
/* There are 5 types of terminal interface supported,
* TERMIO, TERMIOS, VMS, MSDOS and SGTTY
*/
#if defined(sgi) || defined(__sgi)
#define TERMIOS
#undef TERMIO
#undef SGTTY
#endif
#ifdef _LIBC
#define TERMIO
#endif
#ifndef VMS
#ifndef MSDOS
#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS)
#define SGTTY
#endif
#ifdef TERMIOS
#include <termios.h>
#define TTY_STRUCT struct termios
#define TTY_FLAGS c_lflag
#define TTY_get(tty,data) tcgetattr(tty,data)
#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
#endif
#ifdef TERMIO
#include <termio.h>
#define sgttyb termio
#define sg_flags c_lflag
/* Really redefine these ioctl's! */
#undef TIOCGETP
#define TIOCGETP TCGETA
#undef TIOCSETP
#define TIOCSETP TCSETA
#else /* !TERMIO */
#include <sgtty.h>
#define TTY_STRUCT struct termio
#define TTY_FLAGS c_lflag
#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
#endif
#ifdef SGTTY
#include <sgtty.h>
#define TTY_STRUCT struct sgttyb
#define TTY_FLAGS sg_flags
#define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
#endif
#ifndef _LIBC
#include <sys/ioctl.h>
#else /* MSDOS */
#endif
#ifdef MSDOS
#include <conio.h>
#define fgets(a,b,c) noecho_fgets(a,b,c)
#endif
#else /* VMS */
#ifdef VMS
#include <ssdef.h>
#include <iodef.h>
#include <ttdef.h>
@@ -40,69 +113,114 @@ struct IOSB {
long iosb$l_info;
};
#endif
#ifndef NSIG
#define NSIG 32
#ifndef NX509_SIG
#define NX509_SIG 32
#endif
#ifdef PROTO
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);
#ifdef MSDOS
static int noecho_fgets(char *buf, int size, FILE *tty);
#endif
#else
static void read_till_nl();
static int read_pw();
static void recsig();
static void pushsig();
static void popsig();
#ifdef MSDOS
static int noecho_fgets();
#endif
#endif
static void (*savsig[NSIG])();
static void (*savsig[NX509_SIG])();
static jmp_buf save;
static void recsig(int sig)
{
longjmp(save,1);
}
int des_read_password(key, prompt, verify)
des_cblock (*key);
char *prompt;
int verify;
{
int ok;
char buf[BUFSIZ],buff[BUFSIZ];
static void pushsig(void)
{
int i;
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);
}
for (i=0; i<NSIG; i++)
savsig[i]=signal(i,recsig);
}
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];
static void popsig(void)
{
int i;
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);
}
for (i=0; i<NSIG; i++)
signal(i,savsig[i]);
}
int des_read_pw_string(buf, length, prompt, verify)
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)
{
static void read_till_nl(in)
FILE *in;
{
#define SIZE 4
char buf[SIZE+1];
do {
fgets(buf,SIZE,in);
} while (strchr(buf,'\n') == NULL);
}
} while (strchr(buf,'\n') == NULL);
}
/* return 0 if ok, 1 (or -1) otherwise */
static int read_pw(char *buf, char *buff, int size, char *prompt,int verify)
{
#ifndef VMS
#ifndef MSDOS
struct sgttyb tty_orig,tty_new;
#endif /* !MSDOS */
#else
static int read_pw(buf, buff, size, prompt, verify)
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;
#else
#ifndef MSDOS
TTY_STRUCT tty_orig,tty_new;
#endif
#endif
int number=5;
int ok=0;
char *p;
int ps=0;
FILE *tty;
FILE *tty=NULL;
char *p;
#ifndef MSDOS
if ((tty=fopen("/dev/tty","r")) == NULL)
@@ -111,13 +229,13 @@ static int read_pw(char *buf, char *buff, int size, char *prompt,int verify)
if ((tty=fopen("con","r")) == NULL)
tty=stdin;
#endif /* MSDOS */
#ifndef VMS
#ifdef TIOCGETP
if (ioctl(fileno(tty),TIOCGETP,(char *)&tty_orig) == -1)
#if defined(TTY_get) && !defined(VMS)
if (TTY_get(fileno(tty),&tty_orig) == -1)
return(-1);
bcopy(&(tty_orig),&(tty_new),sizeof(tty_orig));
memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
#endif
#else /* VMS */
#ifdef VMS
status = SYS$ASSIGN(&terminal,&channel,0,0);
if (status != SS$_NORMAL)
return(-1);
@@ -133,25 +251,26 @@ static int read_pw(char *buf, char *buff, int size, char *prompt,int verify)
}
pushsig();
ps=1;
#ifndef VMS
#ifndef MSDOS
tty_new.sg_flags &= ~ECHO;
#endif /* !MSDOS */
#ifdef TIOCSETP
if (ioctl(fileno(tty),TIOCSETP,(char *)&tty_new) == -1)
#ifdef TTY_FLAGS
tty_new.TTY_FLAGS &= ~ECHO;
#endif
#if defined(TTY_set) && !defined(VMS)
if (TTY_set(fileno(tty),&tty_new) == -1)
return(-1);
#endif
#else /* VMS */
#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);
#endif /* VMS */
#endif
ps=2;
while (!ok)
while ((!ok) && (number--))
{
fputs(prompt,stderr);
fflush(stderr);
@@ -175,9 +294,10 @@ static int read_pw(char *buf, char *buff, int size, char *prompt,int verify)
if (strcmp(buf,buff) != 0)
{
fprintf(stderr,"\nVerify failure - try again\n");
fprintf(stderr,"\nVerify failure");
fflush(stderr);
continue;
break;
/* continue; */
}
}
ok=1;
@@ -186,15 +306,14 @@ static int read_pw(char *buf, char *buff, int size, char *prompt,int verify)
error:
fprintf(stderr,"\n");
/* What can we do if there is an error? */
#ifndef VMS
#ifdef TIOCSETP
if (ps >= 2) ioctl(fileno(tty),TIOCSETP,(char *)&tty_orig);
#if defined(TTY_set) && !defined(VMS)
if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
#endif
#else /* VMS */
#ifdef VMS
if (ps >= 2)
status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0
,tty_orig,12,0,0,0,0);
#endif /* VMS */
#endif
if (ps >= 1) popsig();
if (stdin != tty) fclose(tty);
@@ -204,59 +323,38 @@ error:
return(!ok);
}
int des_read_password(key,prompt,verify)
des_cblock *key;
char *prompt;
int verify;
static void pushsig()
{
int ok;
char buf[BUFSIZ],buff[BUFSIZ];
int i;
if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
des_string_to_key(buf,key);
bzero(buf,BUFSIZ);
bzero(buff,BUFSIZ);
return(ok);
for (i=1; i<NX509_SIG; i++)
savsig[i]=signal(i,recsig);
}
int des_read_2passwords(key1,key2,prompt,verify)
des_cblock *key1;
des_cblock *key2;
char *prompt;
int verify;
static void popsig()
{
int ok;
char buf[BUFSIZ],buff[BUFSIZ];
int i;
if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
des_string_to_2keys(buf,key1,key2);
bzero(buf,BUFSIZ);
bzero(buff,BUFSIZ);
return(ok);
for (i=1; i<NX509_SIG; i++)
signal(i,savsig[i]);
}
int des_read_pw_string(buf,length,prompt,verify)
char *buf;
int length;
char *prompt;
int verify;
static void recsig(i)
int i;
{
char buff[BUFSIZ];
int ret;
ret=read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
bzero(buff,BUFSIZ);
return(ret);
longjmp(save,1);
#ifdef LINT
i=i;
#endif
}
#ifdef MSDOS
static int noecho_fgets(buf,size,tty)
char *buf;
int size;
FILE *tty;
{
int i;
int i,n;
char *p;
p=buf;
@@ -277,5 +375,6 @@ FILE *tty;
break;
}
}
return(strlen(buf));
}
#endif