diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2000-01-21 21:16:01 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2000-01-21 21:16:01 +0000 |
commit | 1f9f686ee910d3329a35fdb8f3b1a0fd105a5cfe (patch) | |
tree | 8a53cf06ccfb28aea169c0cb4ebbb6c6d0af521f /usr.bin/ssh | |
parent | 4dcf61677bcb737a20720758723b6335c5ce01dc (diff) |
instead of blocking SIGINT, catch it ourselves, so that we can clean the
tty modes up and kill ourselves -- instead of our process group leader (scp,
cvs, ...) going away and leaving us in noecho mode. people with cbreak
shells never even noticed..
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r-- | usr.bin/ssh/readpass.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/usr.bin/ssh/readpass.c b/usr.bin/ssh/readpass.c index 6d1134e4c32..deb37cab634 100644 --- a/usr.bin/ssh/readpass.c +++ b/usr.bin/ssh/readpass.c @@ -32,11 +32,19 @@ */ #include "includes.h" -RCSID("$Id: readpass.c,v 1.8 1999/12/08 19:32:55 deraadt Exp $"); +RCSID("$Id: readpass.c,v 1.9 2000/01/21 21:16:00 deraadt Exp $"); #include "xmalloc.h" #include "ssh.h" +volatile int intr; + +void +intcatch() +{ + intr = 1; +} + /* * Reads a passphrase from /dev/tty with echo turned off. Returns the * passphrase (allocated with xmalloc), being very careful to ensure that @@ -48,6 +56,7 @@ read_passphrase(const char *prompt, int from_stdin) char buf[1024], *p, ch; struct termios tio, saved_tio; sigset_t oset, nset; + struct sigaction sa, osa; int input, output, echo = 0; if (from_stdin) { @@ -61,13 +70,17 @@ read_passphrase(const char *prompt, int from_stdin) /* block signals, get terminal modes and turn off echo */ sigemptyset(&nset); - sigaddset(&nset, SIGINT); sigaddset(&nset, SIGTSTP); (void) sigprocmask(SIG_BLOCK, &nset, &oset); + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = intcatch; + (void) sigaction(SIGINT, &sa, &osa); - if (tcgetattr(input, &tio) == 0 && (tio.c_lflag & ECHO)) { + intr = 0; + + if (tcgetattr(input, &saved_tio) == 0 && (saved_tio.c_lflag & ECHO)) { echo = 1; - saved_tio = tio; + tio = saved_tio; tio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); (void) tcsetattr(input, TCSANOW, &tio); } @@ -75,16 +88,28 @@ read_passphrase(const char *prompt, int from_stdin) fflush(stdout); (void)write(output, prompt, strlen(prompt)); - for (p = buf; read(input, &ch, 1) == 1 && ch != '\n';) + for (p = buf; read(input, &ch, 1) == 1 && ch != '\n';) { + if (intr) + break; if (p < buf + sizeof(buf) - 1) *p++ = ch; + } *p = '\0'; - (void)write(output, "\n", 1); + if (!intr) + (void)write(output, "\n", 1); /* restore terminal modes and allow signals */ if (echo) tcsetattr(input, TCSANOW, &saved_tio); (void) sigprocmask(SIG_SETMASK, &oset, NULL); + (void) sigaction(SIGINT, &osa, NULL); + + if (intr) { + kill(getpid(), SIGINT); + sigemptyset(&nset); + /* XXX tty has not neccessarily drained by now? */ + sigsuspend(&nset); + } if (!from_stdin) (void)close(input); |