summaryrefslogtreecommitdiff
path: root/kerberosIV/des/read_pwd.c
diff options
context:
space:
mode:
authorThorsten Lockert <tholo@cvs.openbsd.org>1996-02-10 21:04:46 +0000
committerThorsten Lockert <tholo@cvs.openbsd.org>1996-02-10 21:04:46 +0000
commit228be9f3e4c1b20930547002be7e3b28a016a247 (patch)
tree13ffb9427cdb71e37ad08161c4e3d78cbd865981 /kerberosIV/des/read_pwd.c
parent0623796c1eaece48da727e5c8819608142140d63 (diff)
Upgraded to latest version of DES library
Diffstat (limited to 'kerberosIV/des/read_pwd.c')
-rw-r--r--kerberosIV/des/read_pwd.c219
1 files changed, 157 insertions, 62 deletions
diff --git a/kerberosIV/des/read_pwd.c b/kerberosIV/des/read_pwd.c
index a3232643214..ff33870b551 100644
--- a/kerberosIV/des/read_pwd.c
+++ b/kerberosIV/des/read_pwd.c
@@ -1,33 +1,108 @@
-/* $Id: read_pwd.c,v 1.1 1995/12/14 06:52:43 tholo Exp $ */
+/* 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.]
+ */
-/* Copyright (C) 1993 Eric Young - see README for more details */
/* 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) || defined(__NetBSD__) || defined(__OpenBSD__)
+#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
-#define TIOCGETP TCGETA
-#define TIOCSETP TCSETA
-#else /* !TERMIO */
+#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>
@@ -38,10 +113,21 @@ 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();
@@ -50,12 +136,13 @@ static void popsig();
#ifdef MSDOS
static int noecho_fgets();
#endif
+#endif
-static void (*savsig[NSIG])();
+static void (*savsig[NX509_SIG])();
static jmp_buf save;
-int des_read_password(key,prompt,verify)
-des_cblock *key;
+int des_read_password(key, prompt, verify)
+des_cblock (*key);
char *prompt;
int verify;
{
@@ -64,14 +151,14 @@ int verify;
if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
des_string_to_key(buf,key);
- bzero(buf,BUFSIZ);
- bzero(buff,BUFSIZ);
+ memset(buf,0,BUFSIZ);
+ memset(buff,0,BUFSIZ);
return(ok);
}
-int des_read_2passwords(key1,key2,prompt,verify)
-des_cblock *key1;
-des_cblock *key2;
+int des_read_2passwords(key1, key2, prompt, verify)
+des_cblock (*key1);
+des_cblock (*key2);
char *prompt;
int verify;
{
@@ -80,12 +167,12 @@ int verify;
if ((ok=read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
des_string_to_2keys(buf,key1,key2);
- bzero(buf,BUFSIZ);
- bzero(buff,BUFSIZ);
+ memset(buf,0,BUFSIZ);
+ memset(buff,0,BUFSIZ);
return(ok);
}
-int des_read_pw_string(buf,length,prompt,verify)
+int des_read_pw_string(buf, length, prompt, verify)
char *buf;
int length;
char *prompt;
@@ -95,7 +182,7 @@ int verify;
int ret;
ret=read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
- bzero(buff,BUFSIZ);
+ memset(buff,0,BUFSIZ);
return(ret);
}
@@ -111,27 +198,29 @@ FILE *in;
}
/* return 0 if ok, 1 (or -1) otherwise */
-static int read_pw(buf,buff,size,prompt,verify)
-char *buf,*buff;
+static int read_pw(buf, buff, size, prompt, verify)
+char *buf;
+char *buff;
int size;
char *prompt;
int verify;
{
-#ifndef VMS
-#ifndef MSDOS
- struct sgttyb tty_orig,tty_new;
-#endif /* !MSDOS */
-#else
+#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)
@@ -140,13 +229,13 @@ 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);
@@ -162,25 +251,26 @@ 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);
@@ -204,9 +294,10 @@ 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;
@@ -215,15 +306,14 @@ 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);
@@ -237,7 +327,7 @@ static void pushsig()
{
int i;
- for (i=0; i<NSIG; i++)
+ for (i=1; i<NX509_SIG; i++)
savsig[i]=signal(i,recsig);
}
@@ -245,13 +335,17 @@ static void popsig()
{
int i;
- for (i=0; i<NSIG; i++)
+ for (i=1; i<NX509_SIG; i++)
signal(i,savsig[i]);
}
-static void recsig()
+static void recsig(i)
+int i;
{
longjmp(save,1);
+#ifdef LINT
+ i=i;
+#endif
}
#ifdef MSDOS
@@ -260,7 +354,7 @@ char *buf;
int size;
FILE *tty;
{
- int i;
+ int i,n;
char *p;
p=buf;
@@ -281,5 +375,6 @@ FILE *tty;
break;
}
}
+ return(strlen(buf));
}
#endif