summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--openbsd-compat/readpassphrase.c47
2 files changed, 28 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 87c236e66..7c4fad33d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
2 - (dtucker) [monitor_fdpass.c] Wrap poll.h include in ifdefs. 2 - (dtucker) [monitor_fdpass.c] Wrap poll.h include in ifdefs.
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 6
620100112 720100112
7 - (dtucker) OpenBSD CVS Sync 8 - (dtucker) OpenBSD CVS Sync
diff --git a/openbsd-compat/readpassphrase.c b/openbsd-compat/readpassphrase.c
index 16e07e816..8b9486357 100644
--- a/openbsd-compat/readpassphrase.c
+++ b/openbsd-compat/readpassphrase.c
@@ -1,7 +1,7 @@
1/* $OpenBSD: readpassphrase.c,v 1.18 2005/08/08 08:05:34 espie Exp $ */ 1/* $OpenBSD: readpassphrase.c,v 1.21 2008/01/17 16:27:07 millert Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000-2002 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com>
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
@@ -68,6 +68,8 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
68 68
69restart: 69restart:
70 signo = 0; 70 signo = 0;
71 nr = -1;
72 save_errno = 0;
71 /* 73 /*
72 * Read and write to /dev/tty if available. If not, read from 74 * Read and write to /dev/tty if available. If not, read from
73 * stdin and write to stderr unless a tty is required. 75 * stdin and write to stderr unless a tty is required.
@@ -117,26 +119,30 @@ restart:
117 oterm.c_lflag |= ECHO; 119 oterm.c_lflag |= ECHO;
118 } 120 }
119 121
120 if (!(flags & RPP_STDIN)) 122 /* No I/O if we are already backgrounded. */
121 (void)write(output, prompt, strlen(prompt)); 123 if (signo != SIGTTOU && signo != SIGTTIN) {
122 end = buf + bufsiz - 1; 124 if (!(flags & RPP_STDIN))
123 for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) { 125 (void)write(output, prompt, strlen(prompt));
124 if (p < end) { 126 end = buf + bufsiz - 1;
125 if ((flags & RPP_SEVENBIT)) 127 p = buf;
126 ch &= 0x7f; 128 while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
127 if (isalpha(ch)) { 129 if (p < end) {
128 if ((flags & RPP_FORCELOWER)) 130 if ((flags & RPP_SEVENBIT))
129 ch = tolower(ch); 131 ch &= 0x7f;
130 if ((flags & RPP_FORCEUPPER)) 132 if (isalpha(ch)) {
131 ch = toupper(ch); 133 if ((flags & RPP_FORCELOWER))
134 ch = (char)tolower(ch);
135 if ((flags & RPP_FORCEUPPER))
136 ch = (char)toupper(ch);
137 }
138 *p++ = ch;
132 } 139 }
133 *p++ = ch;
134 } 140 }
141 *p = '\0';
142 save_errno = errno;
143 if (!(term.c_lflag & ECHO))
144 (void)write(output, "\n", 1);
135 } 145 }
136 *p = '\0';
137 save_errno = errno;
138 if (!(term.c_lflag & ECHO))
139 (void)write(output, "\n", 1);
140 146
141 /* Restore old terminal settings and signals. */ 147 /* Restore old terminal settings and signals. */
142 if (memcmp(&term, &oterm, sizeof(term)) != 0) { 148 if (memcmp(&term, &oterm, sizeof(term)) != 0) {
@@ -170,7 +176,8 @@ restart:
170 } 176 }
171 } 177 }
172 178
173 errno = save_errno; 179 if (save_errno)
180 errno = save_errno;
174 return(nr == -1 ? NULL : buf); 181 return(nr == -1 ? NULL : buf);
175} 182}
176 183