summaryrefslogtreecommitdiff
path: root/openbsd-compat/readpassphrase.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-13 21:32:44 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-01-13 21:32:44 +1100
commitd59487a33bfaadc3ced41a1c604ec603d716df42 (patch)
tree831ce1b4fe1ac4bb1ef020d324a16899e5d62a7a /openbsd-compat/readpassphrase.c
parent1035cb4729857ec00d1a976476b840bfe0351312 (diff)
- (dtucker) [openbsd-compat/readpassphrase.c] Update to OpenBSD's r1.22.
Fixes bz #1590, where sometimes you could not interrupt a connection while ssh was prompting for a passphrase or password.
Diffstat (limited to 'openbsd-compat/readpassphrase.c')
-rw-r--r--openbsd-compat/readpassphrase.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/openbsd-compat/readpassphrase.c b/openbsd-compat/readpassphrase.c
index 8b9486357..62b6d0d84 100644
--- a/openbsd-compat/readpassphrase.c
+++ b/openbsd-compat/readpassphrase.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: readpassphrase.c,v 1.21 2008/01/17 16:27:07 millert Exp $ */ 1/* $OpenBSD: readpassphrase.c,v 1.22 2010/01/13 10:20:54 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -46,7 +46,7 @@
46# define _POSIX_VDISABLE VDISABLE 46# define _POSIX_VDISABLE VDISABLE
47#endif 47#endif
48 48
49static volatile sig_atomic_t signo; 49static volatile sig_atomic_t signo[_NSIG];
50 50
51static void handler(int); 51static void handler(int);
52 52
@@ -54,7 +54,7 @@ char *
54readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) 54readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
55{ 55{
56 ssize_t nr; 56 ssize_t nr;
57 int input, output, save_errno; 57 int input, output, save_errno, i, need_restart;
58 char ch, *p, *end; 58 char ch, *p, *end;
59 struct termios term, oterm; 59 struct termios term, oterm;
60 struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm; 60 struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
@@ -67,9 +67,11 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
67 } 67 }
68 68
69restart: 69restart:
70 signo = 0; 70 for (i = 0; i < _NSIG; i++)
71 signo[i] = 0;
71 nr = -1; 72 nr = -1;
72 save_errno = 0; 73 save_errno = 0;
74 need_restart = 0;
73 /* 75 /*
74 * Read and write to /dev/tty if available. If not, read from 76 * Read and write to /dev/tty if available. If not, read from
75 * stdin and write to stderr unless a tty is required. 77 * stdin and write to stderr unless a tty is required.
@@ -120,7 +122,7 @@ restart:
120 } 122 }
121 123
122 /* No I/O if we are already backgrounded. */ 124 /* No I/O if we are already backgrounded. */
123 if (signo != SIGTTOU && signo != SIGTTIN) { 125 if (signo[SIGTTOU] != 1 && signo[SIGTTIN] != 1) {
124 if (!(flags & RPP_STDIN)) 126 if (!(flags & RPP_STDIN))
125 (void)write(output, prompt, strlen(prompt)); 127 (void)write(output, prompt, strlen(prompt));
126 end = buf + bufsiz - 1; 128 end = buf + bufsiz - 1;
@@ -166,15 +168,19 @@ restart:
166 * If we were interrupted by a signal, resend it to ourselves 168 * If we were interrupted by a signal, resend it to ourselves
167 * now that we have restored the signal handlers. 169 * now that we have restored the signal handlers.
168 */ 170 */
169 if (signo) { 171 for (i = 0; i < _NSIG; i++) {
170 kill(getpid(), signo); 172 if (signo[i]) {
171 switch (signo) { 173 kill(getpid(), i);
172 case SIGTSTP: 174 switch (i) {
173 case SIGTTIN: 175 case SIGTSTP:
174 case SIGTTOU: 176 case SIGTTIN:
175 goto restart; 177 case SIGTTOU:
178 need_restart = 1;
179 }
176 } 180 }
177 } 181 }
182 if (need_restart)
183 goto restart;
178 184
179 if (save_errno) 185 if (save_errno)
180 errno = save_errno; 186 errno = save_errno;
@@ -194,6 +200,6 @@ getpass(const char *prompt)
194static void handler(int s) 200static void handler(int s)
195{ 201{
196 202
197 signo = s; 203 signo[s] = 1;
198} 204}
199#endif /* HAVE_READPASSPHRASE */ 205#endif /* HAVE_READPASSPHRASE */