diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | openbsd-compat/readpassphrase.c | 32 |
2 files changed, 22 insertions, 13 deletions
@@ -3,6 +3,9 @@ | |||
3 | - (dtucker) [openbsd-compat/readpassphrase.c] Resync against OpenBSD's r1.18: | 3 | - (dtucker) [openbsd-compat/readpassphrase.c] Resync against OpenBSD's r1.18: |
4 | missing restore of SIGTTOU and some whitespace. | 4 | missing restore of SIGTTOU and some whitespace. |
5 | - (dtucker) [openbsd-compat/readpassphrase.c] Update to OpenBSD's r1.21. | 5 | - (dtucker) [openbsd-compat/readpassphrase.c] Update to OpenBSD's r1.21. |
6 | - (dtucker) [openbsd-compat/readpassphrase.c] Update to OpenBSD's r1.22. | ||
7 | Fixes bz #1590, where sometimes you could not interrupt a connection while | ||
8 | ssh was prompting for a passphrase or password. | ||
6 | 9 | ||
7 | 20100112 | 10 | 20100112 |
8 | - (dtucker) OpenBSD CVS Sync | 11 | - (dtucker) OpenBSD CVS Sync |
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 | ||
49 | static volatile sig_atomic_t signo; | 49 | static volatile sig_atomic_t signo[_NSIG]; |
50 | 50 | ||
51 | static void handler(int); | 51 | static void handler(int); |
52 | 52 | ||
@@ -54,7 +54,7 @@ char * | |||
54 | readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) | 54 | readpassphrase(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 | ||
69 | restart: | 69 | restart: |
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) | |||
194 | static void handler(int s) | 200 | static 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 */ |