diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-06-28 01:43:59 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-06-28 01:43:59 +0000 |
commit | e2d200e3774a0c1ce22d5e27de2fe1d4156cbe9b (patch) | |
tree | e1df66246bd9acf841c4d55e1877c348b4080586 | |
parent | 1427daa5a1d54988b664f69c32ce70637c7aa534 (diff) |
Add RPP_STDIN flag which acts as the converse of RPP_REQUIRE_TTY.
Based on a patch from Brett Eldridge.
-rw-r--r-- | lib/libc/gen/readpassphrase.3 | 3 | ||||
-rw-r--r-- | lib/libc/gen/readpassphrase.c | 14 |
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/libc/gen/readpassphrase.3 b/lib/libc/gen/readpassphrase.3 index e5458c03cdd..1eb8f6ca34f 100644 --- a/lib/libc/gen/readpassphrase.3 +++ b/lib/libc/gen/readpassphrase.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: readpassphrase.3,v 1.8 2002/05/09 16:47:07 millert Exp $ +.\" $OpenBSD: readpassphrase.3,v 1.9 2002/06/28 01:43:58 millert Exp $ .\" .\" Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com> .\" All rights reserved. @@ -67,6 +67,7 @@ RPP_REQUIRE_TTY fail if there is no tty RPP_FORCELOWER force input to lower case RPP_FORCEUPPER force input to upper case RPP_SEVENBIT strip the high bit from input +RPP_STDIN force read of passphrase from stdin .Ed .Pp The calling process should zero the passphrase as soon as possible to diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c index cd0a2f27e8a..051bb1ca416 100644 --- a/lib/libc/gen/readpassphrase.c +++ b/lib/libc/gen/readpassphrase.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readpassphrase.c,v 1.13 2002/05/09 16:40:35 millert Exp $ */ +/* $OpenBSD: readpassphrase.c,v 1.14 2002/06/28 01:43:58 millert Exp $ */ /* * Copyright (c) 2000-2002 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.13 2002/05/09 16:40:35 millert Exp $"; +static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.14 2002/06/28 01:43:58 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <ctype.h> @@ -68,7 +68,8 @@ restart: * Read and write to /dev/tty if available. If not, read from * stdin and write to stderr unless a tty is required. */ - if ((input = output = open(_PATH_TTY, O_RDWR)) == -1) { + if ((flags & RPP_STDIN) || + (input = output = open(_PATH_TTY, O_RDWR)) == -1) { if (flags & RPP_REQUIRE_TTY) { errno = ENOTTY; return(NULL); @@ -96,7 +97,7 @@ restart: (void)sigaction(SIGTTOU, &sa, &savettou); /* Turn off echo if possible. */ - if (tcgetattr(input, &oterm) == 0) { + if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) { memcpy(&term, &oterm, sizeof(term)); if (!(flags & RPP_ECHO_ON)) term.c_lflag &= ~(ECHO | ECHONL); @@ -105,10 +106,13 @@ restart: (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); } else { memset(&term, 0, sizeof(term)); + term.c_lflag |= ECHO; memset(&oterm, 0, sizeof(oterm)); + oterm.c_lflag |= ECHO; } - (void)write(output, prompt, strlen(prompt)); + if (!(flags & RPP_STDIN)) + (void)write(output, prompt, strlen(prompt)); end = buf + bufsiz - 1; for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) { if (p < end) { |