summaryrefslogtreecommitdiff
path: root/openbsd-compat/readpassphrase.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-13 18:32:59 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-01-13 18:32:59 +1100
commit1035cb4729857ec00d1a976476b840bfe0351312 (patch)
treec7845bcff644fcbcb70d12cf4f59f15b63216dce /openbsd-compat/readpassphrase.c
parentab3c2cab18a6c5ae9dd93cacb1a179e48d245228 (diff)
- (dtucker) [openbsd-compat/readpassphrase.c] Update to OpenBSD's r1.21.
Diffstat (limited to 'openbsd-compat/readpassphrase.c')
-rw-r--r--openbsd-compat/readpassphrase.c47
1 files changed, 27 insertions, 20 deletions
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