
This patch fixes most of current reasons to generate compiler warnings. The changes consist of: - adding missing casts - hiding or unhiding function declarations - including headers where missing - add __UNCONST when assigning a const char * to a char * - adding missing return statements - changing some types from unsigned to signed, as the code seems to want signed ints - converting old-style function definitions to current style (i.e., void func(param1, param2) short param1, param2; {...} to void func (short param1, short param2) {...}) - making the compiler silent about signed vs unsigned comparisons. We have too many of those in the new libc to fix. A number of bugs in the test set were fixed. These bugs were never triggered with our old libc. Consequently, these tests are now forced to link with the new libc or they will generate errors (in particular tests 43 and 55). Most changes in NetBSD libc are limited to moving aroudn "#ifndef __minix" or stuff related to Minix-specific things (code in sys-minix or gen/minix).
75 lines
1.4 KiB
C
75 lines
1.4 KiB
C
/* getpass() - read a password Author: Kees J. Bot
|
|
* Feb 16 1993
|
|
*/
|
|
#include <sys/cdefs.h>
|
|
#include "namespace.h"
|
|
|
|
#include <sys/types.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
#include <termios.h>
|
|
#include <string.h>
|
|
|
|
#ifdef __weak_alias
|
|
__weak_alias(getpass, _getpass)
|
|
#endif
|
|
|
|
static int intr;
|
|
|
|
static void catch(int sig)
|
|
{
|
|
intr= 1;
|
|
}
|
|
|
|
char *getpass(const char *prompt)
|
|
{
|
|
struct sigaction osa, sa;
|
|
struct termios cooked, raw;
|
|
static char password[32+1];
|
|
int fd, n= 0;
|
|
|
|
/* Try to open the controlling terminal. */
|
|
if ((fd= open("/dev/tty", O_RDONLY)) < 0) return NULL;
|
|
|
|
/* Trap interrupts unless ignored. */
|
|
intr= 0;
|
|
sigaction(SIGINT, NULL, &osa);
|
|
if (osa.sa_handler != SIG_IGN) {
|
|
sigemptyset(&sa.sa_mask);
|
|
sa.sa_flags= 0;
|
|
sa.sa_handler= catch;
|
|
sigaction(SIGINT, &sa, &osa);
|
|
}
|
|
|
|
/* Set the terminal to non-echo mode. */
|
|
tcgetattr(fd, &cooked);
|
|
raw= cooked;
|
|
raw.c_iflag|= ICRNL;
|
|
raw.c_lflag&= ~ECHO;
|
|
raw.c_lflag|= ECHONL;
|
|
raw.c_oflag|= OPOST | ONLCR;
|
|
tcsetattr(fd, TCSANOW, &raw);
|
|
|
|
/* Print the prompt. (After setting non-echo!) */
|
|
write(2, prompt, strlen(prompt));
|
|
|
|
/* Read the password, 32 characters max. */
|
|
while (read(fd, password+n, 1) > 0) {
|
|
if (password[n] == '\n') break;
|
|
if (n < 32) n++;
|
|
}
|
|
password[n]= 0;
|
|
|
|
/* Terminal back to cooked mode. */
|
|
tcsetattr(fd, TCSANOW, &cooked);
|
|
|
|
close(fd);
|
|
|
|
/* Interrupt? */
|
|
sigaction(SIGINT, &osa, NULL);
|
|
if (intr) raise(SIGINT);
|
|
|
|
return password;
|
|
}
|