diff options
author | 2001-12-07 23:55:35 +0000 | |
---|---|---|
committer | 2001-12-07 23:55:35 +0000 | |
commit | 3ae5daf0792e21cfee7d1d86270180c4ea88b819 (patch) | |
tree | 6b2b6638e7929dd0a4a4af74c48779976fee4457 | |
parent | From XPG4.2: read(2) can return EIO if the process is a member of (diff) | |
download | wireguard-openbsd-3ae5daf0792e21cfee7d1d86270180c4ea88b819.tar.xz wireguard-openbsd-3ae5daf0792e21cfee7d1d86270180c4ea88b819.zip |
o Turn off ECHONL in addition to ECHO
o Return NULL of read(2) returns -1
o Add ERRORS and STANDARDS sections
-rw-r--r-- | lib/libc/gen/readpassphrase.3 | 42 | ||||
-rw-r--r-- | lib/libc/gen/readpassphrase.c | 18 |
2 files changed, 43 insertions, 17 deletions
diff --git a/lib/libc/gen/readpassphrase.3 b/lib/libc/gen/readpassphrase.3 index 7ec89898352..fba5f5b1ee1 100644 --- a/lib/libc/gen/readpassphrase.3 +++ b/lib/libc/gen/readpassphrase.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: readpassphrase.3,v 1.5 2001/12/07 22:16:48 millert Exp $ +.\" $OpenBSD: readpassphrase.3,v 1.6 2001/12/07 23:55:35 millert Exp $ .\" .\" Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com> .\" All rights reserved. @@ -25,7 +25,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 20, 2000 +.Dd December 7, 2001 .Dt READPASSPHRASE 3 .Os .Sh NAME @@ -73,16 +73,34 @@ The calling process should zero the passphrase as soon as possible to avoid leaving the cleartext passphrase visible in the process's address space. .Sh RETURN VALUES -On success, +Upon successful completion, .Fn readpassphrase returns a pointer to the null-terminated passphrase. -If the -.Dv RPP_REQUIRE_TTY -flag is set and -.Pa /dev/tty -is inaccessible, +If an error is encountered, the terminal state is restored and +a null pointer is returned. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINTR +The .Fn readpassphrase -returns a null pointer. +function was interrupted by a signal. +.It Bq Er EINVAL +The +.Ar bufsiz +argument was zero. +.It Bq Er EIO +The process is a member of a background process attempting to read +from its controlling terminal, the process is ignoring or blocking +the SIGTTIN signal or the process group is orphaned. +.It Bq Er EMFILE +The process has already reached its limit for open file descriptors. +.It Bq Er ENFILE +The system file table is full. +.It Bq Er ENOTTY +There is no controlling terminal and the +.Dv RPP_REQUIRE_TTY +flag was specified. +.El .Sh EXAMPLES The following code fragment will read a passphrase from .Pa /dev/tty @@ -138,6 +156,12 @@ will reprint the prompt and the user may then enter a passphrase. .Sh SEE ALSO .Xr sigaction 2 , .Xr getpass 3 +.Sh STANDARDS +The +.Fn readpassphrase +function is an +.Ox +extension and should not be used if portability is desired. .Sh HISTORY The .Fn readpassphrase diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c index 197e0003617..e48cc9e1a5d 100644 --- a/lib/libc/gen/readpassphrase.c +++ b/lib/libc/gen/readpassphrase.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readpassphrase.c,v 1.10 2001/12/07 22:16:48 millert Exp $ */ +/* $OpenBSD: readpassphrase.c,v 1.11 2001/12/07 23:55:35 millert Exp $ */ /* * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.10 2001/12/07 22:16:48 millert Exp $"; +static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.11 2001/12/07 23:55:35 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <ctype.h> @@ -49,7 +49,8 @@ static void handler(int); char * readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) { - int input, output; + ssize_t nr; + int input, output, save_errno; char ch, *p, *end; struct termios term, oterm; struct sigaction sa, saveint, savehup, savequit, saveterm, savetstp; @@ -91,8 +92,8 @@ restart: /* Turn off echo if possible. */ if (tcgetattr(input, &oterm) == 0) { memcpy(&term, &oterm, sizeof(term)); - if (!(flags & RPP_ECHO_ON) && (term.c_lflag & ECHO)) - term.c_lflag &= ~ECHO; + if (!(flags & RPP_ECHO_ON)) + term.c_lflag &= ~(ECHO | ECHONL); if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) term.c_cc[VSTATUS] = _POSIX_VDISABLE; (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); @@ -103,7 +104,7 @@ restart: (void)write(output, prompt, strlen(prompt)); end = buf + bufsiz - 1; - for (p = buf; read(input, &ch, 1) == 1 && ch != '\n' && ch != '\r';) { + for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) { if (p < end) { if ((flags & RPP_SEVENBIT)) ch &= 0x7f; @@ -117,6 +118,7 @@ restart: } } *p = '\0'; + save_errno = errno; if (!(term.c_lflag & ECHO)) (void)write(output, "\n", 1); @@ -141,10 +143,10 @@ restart: signo = 0; goto restart; } - } - return(buf); + errno = save_errno; + return(nr == -1 ? NULL : buf); } char * |