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 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/ioctl.h>
30 #define PWD_BUFFER_SIZE 256
33 /* do nothing signal handler */
34 static void askpass_timeout(int ignore)
38 char *bb_askpass(int timeout, const char * prompt)
43 struct termios old, new;
44 static char passwd[PWD_BUFFER_SIZE];
46 tcgetattr(STDIN_FILENO, &old);
47 tcflush(STDIN_FILENO, TCIFLUSH);
49 size = sizeof(passwd);
51 memset(passwd, 0, size);
53 fputs(prompt, stdout);
56 tcgetattr(STDIN_FILENO, &new);
57 new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
58 new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
59 tcsetattr(STDIN_FILENO, TCSANOW, &new);
63 sa.sa_handler = askpass_timeout;
64 sigaction(SIGALRM, &sa, NULL);
68 if (read(STDIN_FILENO, passwd, size-1) <= 0) {
71 for(i = 0; i < size && passwd[i]; i++) {
72 if (passwd[i]== '\r' || passwd[i] == '\n') {
83 tcsetattr(STDIN_FILENO, TCSANOW, &old);