1*ebfedea0SLionel Sambuc /* crypto/des/read_pwd.c */
2*ebfedea0SLionel Sambuc /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3*ebfedea0SLionel Sambuc * All rights reserved.
4*ebfedea0SLionel Sambuc *
5*ebfedea0SLionel Sambuc * This package is an SSL implementation written
6*ebfedea0SLionel Sambuc * by Eric Young (eay@cryptsoft.com).
7*ebfedea0SLionel Sambuc * The implementation was written so as to conform with Netscapes SSL.
8*ebfedea0SLionel Sambuc *
9*ebfedea0SLionel Sambuc * This library is free for commercial and non-commercial use as long as
10*ebfedea0SLionel Sambuc * the following conditions are aheared to. The following conditions
11*ebfedea0SLionel Sambuc * apply to all code found in this distribution, be it the RC4, RSA,
12*ebfedea0SLionel Sambuc * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13*ebfedea0SLionel Sambuc * included with this distribution is covered by the same copyright terms
14*ebfedea0SLionel Sambuc * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15*ebfedea0SLionel Sambuc *
16*ebfedea0SLionel Sambuc * Copyright remains Eric Young's, and as such any Copyright notices in
17*ebfedea0SLionel Sambuc * the code are not to be removed.
18*ebfedea0SLionel Sambuc * If this package is used in a product, Eric Young should be given attribution
19*ebfedea0SLionel Sambuc * as the author of the parts of the library used.
20*ebfedea0SLionel Sambuc * This can be in the form of a textual message at program startup or
21*ebfedea0SLionel Sambuc * in documentation (online or textual) provided with the package.
22*ebfedea0SLionel Sambuc *
23*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
24*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
25*ebfedea0SLionel Sambuc * are met:
26*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the copyright
27*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
28*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
29*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
30*ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
31*ebfedea0SLionel Sambuc * 3. All advertising materials mentioning features or use of this software
32*ebfedea0SLionel Sambuc * must display the following acknowledgement:
33*ebfedea0SLionel Sambuc * "This product includes cryptographic software written by
34*ebfedea0SLionel Sambuc * Eric Young (eay@cryptsoft.com)"
35*ebfedea0SLionel Sambuc * The word 'cryptographic' can be left out if the rouines from the library
36*ebfedea0SLionel Sambuc * being used are not cryptographic related :-).
37*ebfedea0SLionel Sambuc * 4. If you include any Windows specific code (or a derivative thereof) from
38*ebfedea0SLionel Sambuc * the apps directory (application code) you must include an acknowledgement:
39*ebfedea0SLionel Sambuc * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40*ebfedea0SLionel Sambuc *
41*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42*ebfedea0SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43*ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44*ebfedea0SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45*ebfedea0SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46*ebfedea0SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47*ebfedea0SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48*ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49*ebfedea0SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50*ebfedea0SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51*ebfedea0SLionel Sambuc * SUCH DAMAGE.
52*ebfedea0SLionel Sambuc *
53*ebfedea0SLionel Sambuc * The licence and distribution terms for any publically available version or
54*ebfedea0SLionel Sambuc * derivative of this code cannot be changed. i.e. this code cannot simply be
55*ebfedea0SLionel Sambuc * copied and put under another distribution licence
56*ebfedea0SLionel Sambuc * [including the GNU Public Licence.]
57*ebfedea0SLionel Sambuc */
58*ebfedea0SLionel Sambuc
59*ebfedea0SLionel Sambuc #include <unistd.h>
60*ebfedea0SLionel Sambuc /* If unistd.h defines _POSIX_VERSION, we conclude that we
61*ebfedea0SLionel Sambuc * are on a POSIX system and have sigaction and termios. */
62*ebfedea0SLionel Sambuc #if defined(_POSIX_VERSION)
63*ebfedea0SLionel Sambuc
64*ebfedea0SLionel Sambuc # define SIGACTION
65*ebfedea0SLionel Sambuc # if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
66*ebfedea0SLionel Sambuc # define TERMIOS
67*ebfedea0SLionel Sambuc # endif
68*ebfedea0SLionel Sambuc
69*ebfedea0SLionel Sambuc #endif
70*ebfedea0SLionel Sambuc
71*ebfedea0SLionel Sambuc /* #define SIGACTION */ /* Define this if you have sigaction() */
72*ebfedea0SLionel Sambuc
73*ebfedea0SLionel Sambuc #ifdef WIN16TTY
74*ebfedea0SLionel Sambuc #undef WIN16
75*ebfedea0SLionel Sambuc #undef _WINDOWS
76*ebfedea0SLionel Sambuc #include <graph.h>
77*ebfedea0SLionel Sambuc #endif
78*ebfedea0SLionel Sambuc
79*ebfedea0SLionel Sambuc /* 06-Apr-92 Luke Brennan Support for VMS */
80*ebfedea0SLionel Sambuc #include "des_locl.h"
81*ebfedea0SLionel Sambuc #include <signal.h>
82*ebfedea0SLionel Sambuc #include <stdio.h>
83*ebfedea0SLionel Sambuc #include <string.h>
84*ebfedea0SLionel Sambuc #include <setjmp.h>
85*ebfedea0SLionel Sambuc #include <errno.h>
86*ebfedea0SLionel Sambuc
87*ebfedea0SLionel Sambuc #ifdef VMS /* prototypes for sys$whatever */
88*ebfedea0SLionel Sambuc #include <starlet.h>
89*ebfedea0SLionel Sambuc #ifdef __DECC
90*ebfedea0SLionel Sambuc #pragma message disable DOLLARID
91*ebfedea0SLionel Sambuc #endif
92*ebfedea0SLionel Sambuc #endif
93*ebfedea0SLionel Sambuc
94*ebfedea0SLionel Sambuc #ifdef WIN_CONSOLE_BUG
95*ebfedea0SLionel Sambuc #include <windows.h>
96*ebfedea0SLionel Sambuc #include <wincon.h>
97*ebfedea0SLionel Sambuc #endif
98*ebfedea0SLionel Sambuc
99*ebfedea0SLionel Sambuc
100*ebfedea0SLionel Sambuc /* There are 5 types of terminal interface supported,
101*ebfedea0SLionel Sambuc * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
102*ebfedea0SLionel Sambuc */
103*ebfedea0SLionel Sambuc
104*ebfedea0SLionel Sambuc #if defined(__sgi) && !defined(TERMIOS)
105*ebfedea0SLionel Sambuc #define TERMIOS
106*ebfedea0SLionel Sambuc #undef TERMIO
107*ebfedea0SLionel Sambuc #undef SGTTY
108*ebfedea0SLionel Sambuc #endif
109*ebfedea0SLionel Sambuc
110*ebfedea0SLionel Sambuc #if defined(linux) && !defined(TERMIO)
111*ebfedea0SLionel Sambuc #undef TERMIOS
112*ebfedea0SLionel Sambuc #define TERMIO
113*ebfedea0SLionel Sambuc #undef SGTTY
114*ebfedea0SLionel Sambuc #endif
115*ebfedea0SLionel Sambuc
116*ebfedea0SLionel Sambuc #ifdef _LIBC
117*ebfedea0SLionel Sambuc #undef TERMIOS
118*ebfedea0SLionel Sambuc #define TERMIO
119*ebfedea0SLionel Sambuc #undef SGTTY
120*ebfedea0SLionel Sambuc #endif
121*ebfedea0SLionel Sambuc
122*ebfedea0SLionel Sambuc #if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) && !defined(MAC_OS_pre_X) && !defined(MAC_OS_GUSI_SOURCE)
123*ebfedea0SLionel Sambuc #undef TERMIOS
124*ebfedea0SLionel Sambuc #undef TERMIO
125*ebfedea0SLionel Sambuc #define SGTTY
126*ebfedea0SLionel Sambuc #endif
127*ebfedea0SLionel Sambuc
128*ebfedea0SLionel Sambuc #if defined(VXWORKS)
129*ebfedea0SLionel Sambuc #undef TERMIOS
130*ebfedea0SLionel Sambuc #undef TERMIO
131*ebfedea0SLionel Sambuc #undef SGTTY
132*ebfedea0SLionel Sambuc #endif
133*ebfedea0SLionel Sambuc
134*ebfedea0SLionel Sambuc #ifdef TERMIOS
135*ebfedea0SLionel Sambuc #include <termios.h>
136*ebfedea0SLionel Sambuc #define TTY_STRUCT struct termios
137*ebfedea0SLionel Sambuc #define TTY_FLAGS c_lflag
138*ebfedea0SLionel Sambuc #define TTY_get(tty,data) tcgetattr(tty,data)
139*ebfedea0SLionel Sambuc #define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
140*ebfedea0SLionel Sambuc #endif
141*ebfedea0SLionel Sambuc
142*ebfedea0SLionel Sambuc #ifdef TERMIO
143*ebfedea0SLionel Sambuc #include <termio.h>
144*ebfedea0SLionel Sambuc #define TTY_STRUCT struct termio
145*ebfedea0SLionel Sambuc #define TTY_FLAGS c_lflag
146*ebfedea0SLionel Sambuc #define TTY_get(tty,data) ioctl(tty,TCGETA,data)
147*ebfedea0SLionel Sambuc #define TTY_set(tty,data) ioctl(tty,TCSETA,data)
148*ebfedea0SLionel Sambuc #endif
149*ebfedea0SLionel Sambuc
150*ebfedea0SLionel Sambuc #ifdef SGTTY
151*ebfedea0SLionel Sambuc #include <sgtty.h>
152*ebfedea0SLionel Sambuc #define TTY_STRUCT struct sgttyb
153*ebfedea0SLionel Sambuc #define TTY_FLAGS sg_flags
154*ebfedea0SLionel Sambuc #define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
155*ebfedea0SLionel Sambuc #define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
156*ebfedea0SLionel Sambuc #endif
157*ebfedea0SLionel Sambuc
158*ebfedea0SLionel Sambuc #if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS) && !defined(MAC_OS_pre_X)
159*ebfedea0SLionel Sambuc #include <sys/ioctl.h>
160*ebfedea0SLionel Sambuc #endif
161*ebfedea0SLionel Sambuc
162*ebfedea0SLionel Sambuc #if defined(MSDOS) && !defined(__CYGWIN32__)
163*ebfedea0SLionel Sambuc #include <conio.h>
164*ebfedea0SLionel Sambuc #define fgets(a,b,c) noecho_fgets(a,b,c)
165*ebfedea0SLionel Sambuc #endif
166*ebfedea0SLionel Sambuc
167*ebfedea0SLionel Sambuc #ifdef VMS
168*ebfedea0SLionel Sambuc #include <ssdef.h>
169*ebfedea0SLionel Sambuc #include <iodef.h>
170*ebfedea0SLionel Sambuc #include <ttdef.h>
171*ebfedea0SLionel Sambuc #include <descrip.h>
172*ebfedea0SLionel Sambuc struct IOSB {
173*ebfedea0SLionel Sambuc short iosb$w_value;
174*ebfedea0SLionel Sambuc short iosb$w_count;
175*ebfedea0SLionel Sambuc long iosb$l_info;
176*ebfedea0SLionel Sambuc };
177*ebfedea0SLionel Sambuc #endif
178*ebfedea0SLionel Sambuc
179*ebfedea0SLionel Sambuc #if defined(MAC_OS_pre_X) || defined(MAC_OS_GUSI_SOURCE)
180*ebfedea0SLionel Sambuc /*
181*ebfedea0SLionel Sambuc * This one needs work. As a matter of fact the code is unoperational
182*ebfedea0SLionel Sambuc * and this is only a trick to get it compiled.
183*ebfedea0SLionel Sambuc * <appro@fy.chalmers.se>
184*ebfedea0SLionel Sambuc */
185*ebfedea0SLionel Sambuc #define TTY_STRUCT int
186*ebfedea0SLionel Sambuc #endif
187*ebfedea0SLionel Sambuc
188*ebfedea0SLionel Sambuc #ifndef NX509_SIG
189*ebfedea0SLionel Sambuc #define NX509_SIG 32
190*ebfedea0SLionel Sambuc #endif
191*ebfedea0SLionel Sambuc
192*ebfedea0SLionel Sambuc static void read_till_nl(FILE *);
193*ebfedea0SLionel Sambuc static void recsig(int);
194*ebfedea0SLionel Sambuc static void pushsig(void);
195*ebfedea0SLionel Sambuc static void popsig(void);
196*ebfedea0SLionel Sambuc #if defined(MSDOS) && !defined(WIN16)
197*ebfedea0SLionel Sambuc static int noecho_fgets(char *buf, int size, FILE *tty);
198*ebfedea0SLionel Sambuc #endif
199*ebfedea0SLionel Sambuc #ifdef SIGACTION
200*ebfedea0SLionel Sambuc static struct sigaction savsig[NX509_SIG];
201*ebfedea0SLionel Sambuc #else
202*ebfedea0SLionel Sambuc static void (*savsig[NX509_SIG])(int );
203*ebfedea0SLionel Sambuc #endif
204*ebfedea0SLionel Sambuc static jmp_buf save;
205*ebfedea0SLionel Sambuc
des_read_pw_string(char * buf,int length,const char * prompt,int verify)206*ebfedea0SLionel Sambuc int des_read_pw_string(char *buf, int length, const char *prompt,
207*ebfedea0SLionel Sambuc int verify)
208*ebfedea0SLionel Sambuc {
209*ebfedea0SLionel Sambuc char buff[BUFSIZ];
210*ebfedea0SLionel Sambuc int ret;
211*ebfedea0SLionel Sambuc
212*ebfedea0SLionel Sambuc ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
213*ebfedea0SLionel Sambuc OPENSSL_cleanse(buff,BUFSIZ);
214*ebfedea0SLionel Sambuc return(ret);
215*ebfedea0SLionel Sambuc }
216*ebfedea0SLionel Sambuc
217*ebfedea0SLionel Sambuc #ifndef WIN16
218*ebfedea0SLionel Sambuc
read_till_nl(FILE * in)219*ebfedea0SLionel Sambuc static void read_till_nl(FILE *in)
220*ebfedea0SLionel Sambuc {
221*ebfedea0SLionel Sambuc #define SIZE 4
222*ebfedea0SLionel Sambuc char buf[SIZE+1];
223*ebfedea0SLionel Sambuc
224*ebfedea0SLionel Sambuc do {
225*ebfedea0SLionel Sambuc fgets(buf,SIZE,in);
226*ebfedea0SLionel Sambuc } while (strchr(buf,'\n') == NULL);
227*ebfedea0SLionel Sambuc }
228*ebfedea0SLionel Sambuc
229*ebfedea0SLionel Sambuc
230*ebfedea0SLionel Sambuc /* return 0 if ok, 1 (or -1) otherwise */
des_read_pw(char * buf,char * buff,int size,const char * prompt,int verify)231*ebfedea0SLionel Sambuc int des_read_pw(char *buf, char *buff, int size, const char *prompt,
232*ebfedea0SLionel Sambuc int verify)
233*ebfedea0SLionel Sambuc {
234*ebfedea0SLionel Sambuc #ifdef VMS
235*ebfedea0SLionel Sambuc struct IOSB iosb;
236*ebfedea0SLionel Sambuc $DESCRIPTOR(terminal,"TT");
237*ebfedea0SLionel Sambuc long tty_orig[3], tty_new[3];
238*ebfedea0SLionel Sambuc long status;
239*ebfedea0SLionel Sambuc unsigned short channel = 0;
240*ebfedea0SLionel Sambuc #else
241*ebfedea0SLionel Sambuc #if !defined(MSDOS) && !defined(VXWORKS)
242*ebfedea0SLionel Sambuc TTY_STRUCT tty_orig,tty_new;
243*ebfedea0SLionel Sambuc #endif
244*ebfedea0SLionel Sambuc #endif
245*ebfedea0SLionel Sambuc int number;
246*ebfedea0SLionel Sambuc int ok;
247*ebfedea0SLionel Sambuc /* statics are simply to avoid warnings about longjmp clobbering
248*ebfedea0SLionel Sambuc things */
249*ebfedea0SLionel Sambuc static int ps;
250*ebfedea0SLionel Sambuc int is_a_tty;
251*ebfedea0SLionel Sambuc static FILE *tty;
252*ebfedea0SLionel Sambuc char *p;
253*ebfedea0SLionel Sambuc
254*ebfedea0SLionel Sambuc if (setjmp(save))
255*ebfedea0SLionel Sambuc {
256*ebfedea0SLionel Sambuc ok=0;
257*ebfedea0SLionel Sambuc goto error;
258*ebfedea0SLionel Sambuc }
259*ebfedea0SLionel Sambuc
260*ebfedea0SLionel Sambuc number=5;
261*ebfedea0SLionel Sambuc ok=0;
262*ebfedea0SLionel Sambuc ps=0;
263*ebfedea0SLionel Sambuc is_a_tty=1;
264*ebfedea0SLionel Sambuc tty=NULL;
265*ebfedea0SLionel Sambuc
266*ebfedea0SLionel Sambuc #ifdef MSDOS
267*ebfedea0SLionel Sambuc if ((tty=fopen("con","r")) == NULL)
268*ebfedea0SLionel Sambuc tty=stdin;
269*ebfedea0SLionel Sambuc #elif defined(MAC_OS_pre_X) || defined(VXWORKS)
270*ebfedea0SLionel Sambuc tty=stdin;
271*ebfedea0SLionel Sambuc #else
272*ebfedea0SLionel Sambuc #ifndef MPE
273*ebfedea0SLionel Sambuc if ((tty=fopen("/dev/tty","r")) == NULL)
274*ebfedea0SLionel Sambuc #endif
275*ebfedea0SLionel Sambuc tty=stdin;
276*ebfedea0SLionel Sambuc #endif
277*ebfedea0SLionel Sambuc
278*ebfedea0SLionel Sambuc #if defined(TTY_get) && !defined(VMS)
279*ebfedea0SLionel Sambuc if (TTY_get(fileno(tty),&tty_orig) == -1)
280*ebfedea0SLionel Sambuc {
281*ebfedea0SLionel Sambuc #ifdef ENOTTY
282*ebfedea0SLionel Sambuc if (errno == ENOTTY)
283*ebfedea0SLionel Sambuc is_a_tty=0;
284*ebfedea0SLionel Sambuc else
285*ebfedea0SLionel Sambuc #endif
286*ebfedea0SLionel Sambuc #ifdef EINVAL
287*ebfedea0SLionel Sambuc /* Ariel Glenn ariel@columbia.edu reports that solaris
288*ebfedea0SLionel Sambuc * can return EINVAL instead. This should be ok */
289*ebfedea0SLionel Sambuc if (errno == EINVAL)
290*ebfedea0SLionel Sambuc is_a_tty=0;
291*ebfedea0SLionel Sambuc else
292*ebfedea0SLionel Sambuc #endif
293*ebfedea0SLionel Sambuc return(-1);
294*ebfedea0SLionel Sambuc }
295*ebfedea0SLionel Sambuc memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
296*ebfedea0SLionel Sambuc #endif
297*ebfedea0SLionel Sambuc #ifdef VMS
298*ebfedea0SLionel Sambuc status = sys$assign(&terminal,&channel,0,0);
299*ebfedea0SLionel Sambuc if (status != SS$_NORMAL)
300*ebfedea0SLionel Sambuc return(-1);
301*ebfedea0SLionel Sambuc status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
302*ebfedea0SLionel Sambuc if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
303*ebfedea0SLionel Sambuc return(-1);
304*ebfedea0SLionel Sambuc #endif
305*ebfedea0SLionel Sambuc
306*ebfedea0SLionel Sambuc pushsig();
307*ebfedea0SLionel Sambuc ps=1;
308*ebfedea0SLionel Sambuc
309*ebfedea0SLionel Sambuc #ifdef TTY_FLAGS
310*ebfedea0SLionel Sambuc tty_new.TTY_FLAGS &= ~ECHO;
311*ebfedea0SLionel Sambuc #endif
312*ebfedea0SLionel Sambuc
313*ebfedea0SLionel Sambuc #if defined(TTY_set) && !defined(VMS)
314*ebfedea0SLionel Sambuc if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1))
315*ebfedea0SLionel Sambuc #ifdef MPE
316*ebfedea0SLionel Sambuc ; /* MPE lies -- echo really has been disabled */
317*ebfedea0SLionel Sambuc #else
318*ebfedea0SLionel Sambuc return(-1);
319*ebfedea0SLionel Sambuc #endif
320*ebfedea0SLionel Sambuc #endif
321*ebfedea0SLionel Sambuc #ifdef VMS
322*ebfedea0SLionel Sambuc tty_new[0] = tty_orig[0];
323*ebfedea0SLionel Sambuc tty_new[1] = tty_orig[1] | TT$M_NOECHO;
324*ebfedea0SLionel Sambuc tty_new[2] = tty_orig[2];
325*ebfedea0SLionel Sambuc status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
326*ebfedea0SLionel Sambuc if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
327*ebfedea0SLionel Sambuc return(-1);
328*ebfedea0SLionel Sambuc #endif
329*ebfedea0SLionel Sambuc ps=2;
330*ebfedea0SLionel Sambuc
331*ebfedea0SLionel Sambuc while ((!ok) && (number--))
332*ebfedea0SLionel Sambuc {
333*ebfedea0SLionel Sambuc fputs(prompt,stderr);
334*ebfedea0SLionel Sambuc fflush(stderr);
335*ebfedea0SLionel Sambuc
336*ebfedea0SLionel Sambuc buf[0]='\0';
337*ebfedea0SLionel Sambuc fgets(buf,size,tty);
338*ebfedea0SLionel Sambuc if (feof(tty)) goto error;
339*ebfedea0SLionel Sambuc if (ferror(tty)) goto error;
340*ebfedea0SLionel Sambuc if ((p=(char *)strchr(buf,'\n')) != NULL)
341*ebfedea0SLionel Sambuc *p='\0';
342*ebfedea0SLionel Sambuc else read_till_nl(tty);
343*ebfedea0SLionel Sambuc if (verify)
344*ebfedea0SLionel Sambuc {
345*ebfedea0SLionel Sambuc fprintf(stderr,"\nVerifying password - %s",prompt);
346*ebfedea0SLionel Sambuc fflush(stderr);
347*ebfedea0SLionel Sambuc buff[0]='\0';
348*ebfedea0SLionel Sambuc fgets(buff,size,tty);
349*ebfedea0SLionel Sambuc if (feof(tty)) goto error;
350*ebfedea0SLionel Sambuc if ((p=(char *)strchr(buff,'\n')) != NULL)
351*ebfedea0SLionel Sambuc *p='\0';
352*ebfedea0SLionel Sambuc else read_till_nl(tty);
353*ebfedea0SLionel Sambuc
354*ebfedea0SLionel Sambuc if (strcmp(buf,buff) != 0)
355*ebfedea0SLionel Sambuc {
356*ebfedea0SLionel Sambuc fprintf(stderr,"\nVerify failure");
357*ebfedea0SLionel Sambuc fflush(stderr);
358*ebfedea0SLionel Sambuc break;
359*ebfedea0SLionel Sambuc /* continue; */
360*ebfedea0SLionel Sambuc }
361*ebfedea0SLionel Sambuc }
362*ebfedea0SLionel Sambuc ok=1;
363*ebfedea0SLionel Sambuc }
364*ebfedea0SLionel Sambuc
365*ebfedea0SLionel Sambuc error:
366*ebfedea0SLionel Sambuc fprintf(stderr,"\n");
367*ebfedea0SLionel Sambuc #if 0
368*ebfedea0SLionel Sambuc perror("fgets(tty)");
369*ebfedea0SLionel Sambuc #endif
370*ebfedea0SLionel Sambuc /* What can we do if there is an error? */
371*ebfedea0SLionel Sambuc #if defined(TTY_set) && !defined(VMS)
372*ebfedea0SLionel Sambuc if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
373*ebfedea0SLionel Sambuc #endif
374*ebfedea0SLionel Sambuc #ifdef VMS
375*ebfedea0SLionel Sambuc if (ps >= 2)
376*ebfedea0SLionel Sambuc status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0
377*ebfedea0SLionel Sambuc ,tty_orig,12,0,0,0,0);
378*ebfedea0SLionel Sambuc #endif
379*ebfedea0SLionel Sambuc
380*ebfedea0SLionel Sambuc if (ps >= 1) popsig();
381*ebfedea0SLionel Sambuc if (stdin != tty) fclose(tty);
382*ebfedea0SLionel Sambuc #ifdef VMS
383*ebfedea0SLionel Sambuc status = sys$dassgn(channel);
384*ebfedea0SLionel Sambuc #endif
385*ebfedea0SLionel Sambuc return(!ok);
386*ebfedea0SLionel Sambuc }
387*ebfedea0SLionel Sambuc
388*ebfedea0SLionel Sambuc #else /* WIN16 */
389*ebfedea0SLionel Sambuc
des_read_pw(char * buf,char * buff,int size,char * prompt,int verify)390*ebfedea0SLionel Sambuc int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
391*ebfedea0SLionel Sambuc {
392*ebfedea0SLionel Sambuc memset(buf,0,size);
393*ebfedea0SLionel Sambuc memset(buff,0,size);
394*ebfedea0SLionel Sambuc return(0);
395*ebfedea0SLionel Sambuc }
396*ebfedea0SLionel Sambuc
397*ebfedea0SLionel Sambuc #endif
398*ebfedea0SLionel Sambuc
pushsig(void)399*ebfedea0SLionel Sambuc static void pushsig(void)
400*ebfedea0SLionel Sambuc {
401*ebfedea0SLionel Sambuc int i;
402*ebfedea0SLionel Sambuc #ifdef SIGACTION
403*ebfedea0SLionel Sambuc struct sigaction sa;
404*ebfedea0SLionel Sambuc
405*ebfedea0SLionel Sambuc memset(&sa,0,sizeof sa);
406*ebfedea0SLionel Sambuc sa.sa_handler=recsig;
407*ebfedea0SLionel Sambuc #endif
408*ebfedea0SLionel Sambuc
409*ebfedea0SLionel Sambuc for (i=1; i<NX509_SIG; i++)
410*ebfedea0SLionel Sambuc {
411*ebfedea0SLionel Sambuc #ifdef SIGUSR1
412*ebfedea0SLionel Sambuc if (i == SIGUSR1)
413*ebfedea0SLionel Sambuc continue;
414*ebfedea0SLionel Sambuc #endif
415*ebfedea0SLionel Sambuc #ifdef SIGUSR2
416*ebfedea0SLionel Sambuc if (i == SIGUSR2)
417*ebfedea0SLionel Sambuc continue;
418*ebfedea0SLionel Sambuc #endif
419*ebfedea0SLionel Sambuc #ifdef SIGACTION
420*ebfedea0SLionel Sambuc sigaction(i,&sa,&savsig[i]);
421*ebfedea0SLionel Sambuc #else
422*ebfedea0SLionel Sambuc savsig[i]=signal(i,recsig);
423*ebfedea0SLionel Sambuc #endif
424*ebfedea0SLionel Sambuc }
425*ebfedea0SLionel Sambuc
426*ebfedea0SLionel Sambuc #ifdef SIGWINCH
427*ebfedea0SLionel Sambuc signal(SIGWINCH,SIG_DFL);
428*ebfedea0SLionel Sambuc #endif
429*ebfedea0SLionel Sambuc }
430*ebfedea0SLionel Sambuc
popsig(void)431*ebfedea0SLionel Sambuc static void popsig(void)
432*ebfedea0SLionel Sambuc {
433*ebfedea0SLionel Sambuc int i;
434*ebfedea0SLionel Sambuc
435*ebfedea0SLionel Sambuc for (i=1; i<NX509_SIG; i++)
436*ebfedea0SLionel Sambuc {
437*ebfedea0SLionel Sambuc #ifdef SIGUSR1
438*ebfedea0SLionel Sambuc if (i == SIGUSR1)
439*ebfedea0SLionel Sambuc continue;
440*ebfedea0SLionel Sambuc #endif
441*ebfedea0SLionel Sambuc #ifdef SIGUSR2
442*ebfedea0SLionel Sambuc if (i == SIGUSR2)
443*ebfedea0SLionel Sambuc continue;
444*ebfedea0SLionel Sambuc #endif
445*ebfedea0SLionel Sambuc #ifdef SIGACTION
446*ebfedea0SLionel Sambuc sigaction(i,&savsig[i],NULL);
447*ebfedea0SLionel Sambuc #else
448*ebfedea0SLionel Sambuc signal(i,savsig[i]);
449*ebfedea0SLionel Sambuc #endif
450*ebfedea0SLionel Sambuc }
451*ebfedea0SLionel Sambuc }
452*ebfedea0SLionel Sambuc
recsig(int i)453*ebfedea0SLionel Sambuc static void recsig(int i)
454*ebfedea0SLionel Sambuc {
455*ebfedea0SLionel Sambuc longjmp(save,1);
456*ebfedea0SLionel Sambuc #ifdef LINT
457*ebfedea0SLionel Sambuc i=i;
458*ebfedea0SLionel Sambuc #endif
459*ebfedea0SLionel Sambuc }
460*ebfedea0SLionel Sambuc
461*ebfedea0SLionel Sambuc #if defined(MSDOS) && !defined(WIN16)
noecho_fgets(char * buf,int size,FILE * tty)462*ebfedea0SLionel Sambuc static int noecho_fgets(char *buf, int size, FILE *tty)
463*ebfedea0SLionel Sambuc {
464*ebfedea0SLionel Sambuc int i;
465*ebfedea0SLionel Sambuc char *p;
466*ebfedea0SLionel Sambuc
467*ebfedea0SLionel Sambuc p=buf;
468*ebfedea0SLionel Sambuc for (;;)
469*ebfedea0SLionel Sambuc {
470*ebfedea0SLionel Sambuc if (size == 0)
471*ebfedea0SLionel Sambuc {
472*ebfedea0SLionel Sambuc *p='\0';
473*ebfedea0SLionel Sambuc break;
474*ebfedea0SLionel Sambuc }
475*ebfedea0SLionel Sambuc size--;
476*ebfedea0SLionel Sambuc #ifdef WIN16TTY
477*ebfedea0SLionel Sambuc i=_inchar();
478*ebfedea0SLionel Sambuc #else
479*ebfedea0SLionel Sambuc i=getch();
480*ebfedea0SLionel Sambuc #endif
481*ebfedea0SLionel Sambuc if (i == '\r') i='\n';
482*ebfedea0SLionel Sambuc *(p++)=i;
483*ebfedea0SLionel Sambuc if (i == '\n')
484*ebfedea0SLionel Sambuc {
485*ebfedea0SLionel Sambuc *p='\0';
486*ebfedea0SLionel Sambuc break;
487*ebfedea0SLionel Sambuc }
488*ebfedea0SLionel Sambuc }
489*ebfedea0SLionel Sambuc #ifdef WIN_CONSOLE_BUG
490*ebfedea0SLionel Sambuc /* Win95 has several evil console bugs: one of these is that the
491*ebfedea0SLionel Sambuc * last character read using getch() is passed to the next read: this is
492*ebfedea0SLionel Sambuc * usually a CR so this can be trouble. No STDIO fix seems to work but
493*ebfedea0SLionel Sambuc * flushing the console appears to do the trick.
494*ebfedea0SLionel Sambuc */
495*ebfedea0SLionel Sambuc {
496*ebfedea0SLionel Sambuc HANDLE inh;
497*ebfedea0SLionel Sambuc inh = GetStdHandle(STD_INPUT_HANDLE);
498*ebfedea0SLionel Sambuc FlushConsoleInputBuffer(inh);
499*ebfedea0SLionel Sambuc }
500*ebfedea0SLionel Sambuc #endif
501*ebfedea0SLionel Sambuc return(strlen(buf));
502*ebfedea0SLionel Sambuc }
503*ebfedea0SLionel Sambuc #endif
504