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