From: Todd C. Miller Date: Tue, 9 Oct 2018 20:20:13 +0000 (-0600) Subject: Make EOF handling while reading the password prompt more like getpass(3). X-Git-Tag: SUDO_1_8_26^2~58 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e269e0acdc979ffcbf059e525923ce9366c4a69;p=sudo Make EOF handling while reading the password prompt more like getpass(3). We now return the password as long as at least one character has been read. Previously, EOF at the password prompt was treated as if nothing was entered. --- diff --git a/doc/sudo.cat b/doc/sudo.cat index 8fdeb0ae3..b026fd4c2 100644 --- a/doc/sudo.cat +++ b/doc/sudo.cat @@ -284,7 +284,6 @@ DDEESSCCRRIIPPTTIIOONN --SS, ----ssttddiinn Write the prompt to the standard error and read the password from the standard input instead of using the terminal device. - The password must be followed by a newline character. --ss, ----sshheellll Run the shell specified by the SHELL environment variable if @@ -659,4 +658,4 @@ DDIISSCCLLAAIIMMEERR file distributed with ssuuddoo or https://www.sudo.ws/license.html for complete details. -Sudo 1.8.26 October 7, 2018 Sudo 1.8.26 +Sudo 1.8.26 October 8, 2018 Sudo 1.8.26 diff --git a/doc/sudo.man.in b/doc/sudo.man.in index 360d02590..bd534e6ca 100644 --- a/doc/sudo.man.in +++ b/doc/sudo.man.in @@ -20,7 +20,7 @@ .\" Agency (DARPA) and Air Force Research Laboratory, Air Force .\" Materiel Command, USAF, under agreement number F39502-99-1-0512. .\" -.TH "SUDO" "8" "October 7, 2018" "Sudo @PACKAGE_VERSION@" "System Manager's Manual" +.TH "SUDO" "8" "October 8, 2018" "Sudo @PACKAGE_VERSION@" "System Manager's Manual" .nh .if n .ad l .SH "NAME" @@ -553,7 +553,6 @@ the specified \fB\-S\fR, \fB\--stdin\fR Write the prompt to the standard error and read the password from the standard input instead of using the terminal device. -The password must be followed by a newline character. .TP 12n \fB\-s\fR, \fB\--shell\fR Run the shell specified by the diff --git a/doc/sudo.mdoc.in b/doc/sudo.mdoc.in index 541e669ea..7fdc4ce3e 100644 --- a/doc/sudo.mdoc.in +++ b/doc/sudo.mdoc.in @@ -19,7 +19,7 @@ .\" Agency (DARPA) and Air Force Research Laboratory, Air Force .\" Materiel Command, USAF, under agreement number F39502-99-1-0512. .\" -.Dd October 7, 2018 +.Dd October 8, 2018 .Dt SUDO @mansectsu@ .Os Sudo @PACKAGE_VERSION@ .Sh NAME @@ -499,7 +499,6 @@ the specified .It Fl S , -stdin Write the prompt to the standard error and read the password from the standard input instead of using the terminal device. -The password must be followed by a newline character. .It Fl s , -shell Run the shell specified by the .Ev SHELL diff --git a/src/tgetpass.c b/src/tgetpass.c index 655e69f75..989f91eaa 100644 --- a/src/tgetpass.c +++ b/src/tgetpass.c @@ -396,21 +396,26 @@ getln(int fd, char *buf, size_t bufsiz, int feedback, } } - if (nr != 1) { - if (nr == 0) { - *errval = TGP_ERRVAL_NOPASSWORD; - } else if (nr == -1) { - if (errno == EINTR) { - if (signo[SIGALRM] == 1) - *errval = TGP_ERRVAL_TIMEOUT; - } else { - *errval = TGP_ERRVAL_READERROR; - } + switch (nr) { + case -1: + /* Read error */ + if (errno == EINTR) { + if (signo[SIGALRM] == 1) + *errval = TGP_ERRVAL_TIMEOUT; + } else { + *errval = TGP_ERRVAL_READERROR; } debug_return_str(NULL); + case 0: + /* EOF is only an error if no bytes were read. */ + if (left == bufsiz - 1) { + *errval = TGP_ERRVAL_NOPASSWORD; + debug_return_str(NULL); + } + /* FALLTHROUGH */ + default: + debug_return_str_masked(buf); } - - debug_return_str_masked(buf); } static void