[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: passwd - no stty echo after Ctrl-C
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2007-10-20 19:02:22
Message-ID: 200710202002.22576.vda.linux () googlemail ! com
[Download RAW message or body]
On Thursday 18 October 2007 04:56, Alexander Kriegisch wrote:
> Platform: mipsel
> BB version: 1.7.2 or i386
>
> When issuing Ctrl-C during password entry, I still have invisible
> characters at the ash prompt. The output is okay, though. As soon as I
> call "stty echo" manually, the shell prompt is okay again.
>
> Reproduce like this on i386:
> bash $ ./busybox ash
> ash $ ./busybox passwd
> Changing password for root
> New password: [Ctrl-C]
> ash $ <now type something>
> ash $ stty echo # repair
>
> Can this be fixed?
Try attached patches.
--
vda
["8.patch" (text/x-diff)]
diff -d -urpN busybox.7/libbb/bb_askpass.c busybox.8/libbb/bb_askpass.c
--- busybox.7/libbb/bb_askpass.c 2007-10-20 02:55:58.000000000 +0100
+++ busybox.8/libbb/bb_askpass.c 2007-10-20 19:59:35.000000000 +0100
@@ -17,7 +17,7 @@ static void askpass_timeout(int ATTRIBUT
{
}
-char *bb_askpass(int timeout, const char * prompt)
+char *bb_askpass(int timeout, const char *prompt)
{
/* Was static char[BIGNUM] */
enum { sizeof_passwd = 128 };
@@ -25,35 +25,36 @@ char *bb_askpass(int timeout, const char
char *ret;
int i;
- struct sigaction sa;
- struct termios old, new;
+ struct sigaction sa, oldsa;
+ struct termios tio, oldtio;
if (!passwd)
passwd = xmalloc(sizeof_passwd);
memset(passwd, 0, sizeof_passwd);
- tcgetattr(STDIN_FILENO, &old);
+ tcgetattr(STDIN_FILENO, &oldtio);
tcflush(STDIN_FILENO, TCIFLUSH);
+ tio = oldtio;
+ tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
+ tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
+ tcsetattr(STDIN_FILENO, TCSANOW, &tio);
- fputs(prompt, stdout);
- fflush(stdout);
-
- tcgetattr(STDIN_FILENO, &new);
- new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
- new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
- tcsetattr(STDIN_FILENO, TCSANOW, &new);
-
+ memset(&sa, 0, sizeof(sa));
+ /* sa.sa_flags = 0; - no SA_RESTART! */
+ /* SIGINT and SIGALRM will interrupt read below */
+ sa.sa_handler = askpass_timeout;
+ sigaction(SIGINT, &sa, &oldsa);
if (timeout) {
- sa.sa_flags = 0;
- sa.sa_handler = askpass_timeout;
sigaction(SIGALRM, &sa, NULL);
alarm(timeout);
}
+ fputs(prompt, stdout);
+ fflush(stdout);
ret = NULL;
- /* On timeout, read will hopefully be interrupted by SIGALRM,
+ /* On timeout or Ctrl-C, read will hopefully be interrupted,
* and we return NULL */
- if (read(STDIN_FILENO, passwd, sizeof_passwd-1) > 0) {
+ if (read(STDIN_FILENO, passwd, sizeof_passwd - 1) > 0) {
ret = passwd;
i = 0;
/* Last byte is guaranteed to be 0
@@ -67,8 +68,9 @@ char *bb_askpass(int timeout, const char
if (timeout) {
alarm(0);
}
+ sigaction(SIGINT, &oldsa, NULL);
- tcsetattr(STDIN_FILENO, TCSANOW, &old);
+ tcsetattr(STDIN_FILENO, TCSANOW, &oldtio);
bb_putchar('\n');
fflush(stdout);
return ret;
["7.patch" (text/x-diff)]
diff -d -urpN busybox.6/libbb/lineedit.c busybox.7/libbb/lineedit.c
--- busybox.6/libbb/lineedit.c 2007-10-20 02:55:58.000000000 +0100
+++ busybox.7/libbb/lineedit.c 2007-10-20 19:19:41.000000000 +0100
@@ -1270,6 +1270,15 @@ int read_line_input(const char* prompt,
smalluint prevc;
#endif
+ getTermSettings(0, (void *) &initial_settings);
+ /* Happens when e.g. stty -echo was run before */
+ if (!(initial_settings.c_lflag & ECHO)) {
+ parse_prompt(prompt);
+ fflush(stdout);
+ fgets(command, maxsize, stdin);
+ return strlen(command);
+ }
+
// FIXME: audit & improve this
if (maxsize > MAX_LINELEN)
maxsize = MAX_LINELEN;
@@ -1287,7 +1296,6 @@ int read_line_input(const char* prompt,
command_ps = command;
command[0] = '\0';
- getTermSettings(0, (void *) &initial_settings);
memcpy(&new_settings, &initial_settings, sizeof(new_settings));
new_settings.c_lflag &= ~ICANON; /* unbuffered input */
/* Turn off echoing and CTRL-C, so we can trap it */
_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic