1 /* vi: set sw=4 ts=4: */
4 * I use a static buffer in this function. Plan accordingly.
6 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
17 #include <sys/ioctl.h>
20 #define PWD_BUFFER_SIZE 256
23 /* do nothing signal handler */
24 static void askpass_timeout(int ATTRIBUTE_UNUSED ignore)
28 char *bb_askpass(int timeout, const char * prompt)
33 struct termios old, new;
34 static char passwd[PWD_BUFFER_SIZE];
36 tcgetattr(STDIN_FILENO, &old);
37 tcflush(STDIN_FILENO, TCIFLUSH);
39 size = sizeof(passwd);
41 memset(passwd, 0, size);
43 fputs(prompt, stdout);
46 tcgetattr(STDIN_FILENO, &new);
47 new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
48 new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
49 tcsetattr(STDIN_FILENO, TCSANOW, &new);
53 sa.sa_handler = askpass_timeout;
54 sigaction(SIGALRM, &sa, NULL);
58 if (read(STDIN_FILENO, passwd, size-1) <= 0) {
61 for(i = 0; i < size && passwd[i]; i++) {
62 if (passwd[i]== '\r' || passwd[i] == '\n') {
73 tcsetattr(STDIN_FILENO, TCSANOW, &old);