diff options
author | Jonathan Liu <net147@gmail.com> | 2013-05-21 17:01:55 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-05-21 17:01:55 +0200 |
commit | b6dc13c2d3754704b1bf5af4e6b957b48585102f (patch) | |
tree | fd04dfd6847a6e194fa92676fd2fec8574567dba | |
parent | 9cb1e2f86b08da469bb4680cf68e927534b5a2ab (diff) | |
download | busybox-w32-b6dc13c2d3754704b1bf5af4e6b957b48585102f.tar.gz busybox-w32-b6dc13c2d3754704b1bf5af4e6b957b48585102f.tar.bz2 busybox-w32-b6dc13c2d3754704b1bf5af4e6b957b48585102f.zip |
sulogin: allow system maintenance login if root password is empty
The current password checking is unable to distinguish between the user
entering an empty password or pressing Control-D. As a result, an empty
password always results in normal startup.
We modify bb_ask to return NULL if Control-D is pressed without entering
a password. The sulogin applet is then modified to only proceed to
normal startup if bb_ask returns NULL. This covers EOF with no password,
interrupt by timeout and ^C.
Signed-off-by: Jonathan Liu <net147@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/bb_askpass.c | 4 | ||||
-rw-r--r-- | loginutils/sulogin.c | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c index fe2b50677..77c1bcd95 100644 --- a/libbb/bb_askpass.c +++ b/libbb/bb_askpass.c | |||
@@ -65,7 +65,9 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) | |||
65 | i = 0; | 65 | i = 0; |
66 | while (1) { | 66 | while (1) { |
67 | int r = read(fd, &ret[i], 1); | 67 | int r = read(fd, &ret[i], 1); |
68 | if (r < 0) { | 68 | if ((i == 0 && r == 0) /* EOF (^D) with no password */ |
69 | || r < 0 | ||
70 | ) { | ||
69 | /* read is interrupted by timeout or ^C */ | 71 | /* read is interrupted by timeout or ^C */ |
70 | ret = NULL; | 72 | ret = NULL; |
71 | break; | 73 | break; |
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index f79802a4d..65e638489 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c | |||
@@ -83,8 +83,8 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) | |||
83 | cp = bb_ask(STDIN_FILENO, timeout, | 83 | cp = bb_ask(STDIN_FILENO, timeout, |
84 | "Give root password for system maintenance\n" | 84 | "Give root password for system maintenance\n" |
85 | "(or type Control-D for normal startup):"); | 85 | "(or type Control-D for normal startup):"); |
86 | 86 | if (!cp) { | |
87 | if (!cp || !*cp) { | 87 | /* ^D, ^C, timeout, or read error */ |
88 | bb_info_msg("Normal startup"); | 88 | bb_info_msg("Normal startup"); |
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |