summaryrefslogtreecommitdiff
path: root/readpass.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-01-22 19:47:21 +1100
committerDamien Miller <djm@mindrot.org>2000-01-22 19:47:21 +1100
commitf052aaf9f6ed50de9c91d3fbda72be77a9770624 (patch)
treeb9e219b31e4a6ad52d5182c15af3dd02d61cc081 /readpass.c
parent8dbbe6e546020e880cc01b5c6eb68484df766369 (diff)
- OpenBSD CVS updates:
- [packet.c] use getpeername() in packet_connection_is_on_socket(), fixes sshd -i; from Holger.Trapp@Informatik.TU-Chemnitz.DE - [sshd.c] log with level log() not fatal() if peer behaves badly. - [readpass.c] 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 'readpass.c')
-rw-r--r--readpass.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/readpass.c b/readpass.c
index 5ea3b22d..edeb2386 100644
--- a/readpass.c
+++ b/readpass.c
@@ -32,11 +32,19 @@
*/
#include "includes.h"
-RCSID("$Id: readpass.c,v 1.4 1999/12/08 23:31:37 damien Exp $");
+RCSID("$Id: readpass.c,v 1.5 2000/01/22 08:47:21 damien 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);