home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
shadow-2.pt3
/
password.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-03
|
978b
|
53 lines
#include <stdio.h>
#include <string.h>
#include <termio.h>
#include <fcntl.h>
/*
* password - prompt for password and return entry
*
* Need to fake up getpass(). Returns TRUE if a password
* was successfully input, and FALSE otherwise, including
* EOF on input or ioctl() failure. pass is not modified
* on failure.
*/
int password (prompt, pass)
char *prompt;
char *pass;
{
char buf[BUFSIZ];
int eof;
int ttyopened = 0;
struct termio termio;
struct termio save;
FILE *fp;
if ((fp = fopen ("/dev/tty", "r")) == (FILE *) 0)
fp = stdin;
else
ttyopened = 1;
if (ioctl (fileno (fp), TCGETA, &termio))
return (0);
save = termio;
termio.c_lflag &= ~ECHO;
ioctl (fileno (fp), TCSETAF, &termio);
fputs (prompt, stdout);
eof = gets (buf) == (char *) 0 || feof (fp) || ferror (fp);
putchar ('\n');
ioctl (fileno (fp), TCSETAF, &save);
if (! eof) {
buf[8] = '\0';
(void) strcpy (pass, buf);
}
if (ttyopened)
fclose (fp);
return (! eof);
}