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