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.
12 //#include <sys/ioctl.h>
16 /* do nothing signal handler */
17 static void askpass_timeout(int ATTRIBUTE_UNUSED ignore)
21 char *bb_askpass(int timeout, const char * prompt)
23 static char passwd[64];
28 struct termios old, new;
30 tcgetattr(STDIN_FILENO, &old);
31 tcflush(STDIN_FILENO, TCIFLUSH);
33 memset(passwd, 0, sizeof(passwd));
35 fputs(prompt, stdout);
38 tcgetattr(STDIN_FILENO, &new);
39 new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
40 new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
41 tcsetattr(STDIN_FILENO, TCSANOW, &new);
45 sa.sa_handler = askpass_timeout;
46 sigaction(SIGALRM, &sa, NULL);
51 if (read(STDIN_FILENO, passwd, sizeof(passwd)-1) > 0) {
54 /* Last byte is guaranteed to be 0
55 (read did not overwrite it) */
57 if (passwd[i] == '\r' || passwd[i] == '\n')
59 } while (passwd[i++]);
66 tcsetattr(STDIN_FILENO, TCSANOW, &old);