aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-04-13 13:04:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-04-13 13:04:05 +0200
commita3de0b3b86deb37c2adc993c6357c1a31b7ecb5b (patch)
tree19aa5e71448b03b2aea9aa2cad42a9a5d9066dc1
parent335681ca8e39144fa19814f7ba10d0fe760e4055 (diff)
downloadbusybox-w32-a3de0b3b86deb37c2adc993c6357c1a31b7ecb5b.tar.gz
busybox-w32-a3de0b3b86deb37c2adc993c6357c1a31b7ecb5b.tar.bz2
busybox-w32-a3de0b3b86deb37c2adc993c6357c1a31b7ecb5b.zip
libbb: make check_password() also return CHECKPASS_PW_HAS_EMPTY_PASSWORD
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h4
-rw-r--r--libbb/correct_password.c4
-rw-r--r--libbb/securetty.c6
-rw-r--r--loginutils/login.c2
-rw-r--r--loginutils/su.c2
5 files changed, 10 insertions, 8 deletions
diff --git a/include/libbb.h b/include/libbb.h
index b889dd7d7..9b72c97be 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1482,9 +1482,9 @@ extern void selinux_or_die(void) FAST_FUNC;
1482void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; 1482void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
1483void nuke_str(char *str) FAST_FUNC; 1483void nuke_str(char *str) FAST_FUNC;
1484#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM 1484#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
1485int check_securetty(const char *short_tty) FAST_FUNC; 1485int is_tty_secure(const char *short_tty) FAST_FUNC;
1486#else 1486#else
1487static ALWAYS_INLINE int check_securetty(const char *short_tty UNUSED_PARAM) { return 1; } 1487static ALWAYS_INLINE int is_tty_secure(const char *short_tty UNUSED_PARAM) { return 1; }
1488#endif 1488#endif
1489#define CHECKPASS_PW_HAS_EMPTY_PASSWORD 2 1489#define CHECKPASS_PW_HAS_EMPTY_PASSWORD 2
1490int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC; 1490int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC;
diff --git a/libbb/correct_password.c b/libbb/correct_password.c
index 3436edc30..f4635a5bc 100644
--- a/libbb/correct_password.c
+++ b/libbb/correct_password.c
@@ -63,7 +63,7 @@ static const char *get_passwd(const struct passwd *pw, char buffer[SHADOW_BUFSIZ
63} 63}
64 64
65/* 65/*
66 * Return 1 if PW has an empty password. 66 * Return CHECKPASS_PW_HAS_EMPTY_PASSWORD if PW has an empty password.
67 * Return 1 if the user gives the correct password for entry PW, 67 * Return 1 if the user gives the correct password for entry PW,
68 * 0 if not. 68 * 0 if not.
69 * NULL pw means "just fake it for login with bad username" 69 * NULL pw means "just fake it for login with bad username"
@@ -77,7 +77,7 @@ int FAST_FUNC check_password(const struct passwd *pw, const char *plaintext)
77 77
78 pw_pass = get_passwd(pw, buffer); 78 pw_pass = get_passwd(pw, buffer);
79 if (!pw_pass[0]) { /* empty password field? */ 79 if (!pw_pass[0]) { /* empty password field? */
80 return 1; 80 return CHECKPASS_PW_HAS_EMPTY_PASSWORD;
81 } 81 }
82 82
83 encrypted = pw_encrypt(plaintext, /*salt:*/ pw_pass, 1); 83 encrypted = pw_encrypt(plaintext, /*salt:*/ pw_pass, 1);
diff --git a/libbb/securetty.c b/libbb/securetty.c
index 176cee129..67a123689 100644
--- a/libbb/securetty.c
+++ b/libbb/securetty.c
@@ -6,7 +6,7 @@
6 */ 6 */
7#include "libbb.h" 7#include "libbb.h"
8 8
9int FAST_FUNC check_securetty(const char *short_tty) 9int FAST_FUNC is_tty_secure(const char *short_tty)
10{ 10{
11 char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */ 11 char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */
12 parser_t *parser = config_open2("/etc/securetty", fopen_for_read); 12 parser_t *parser = config_open2("/etc/securetty", fopen_for_read);
@@ -17,6 +17,8 @@ int FAST_FUNC check_securetty(const char *short_tty)
17 } 17 }
18 config_close(parser); 18 config_close(parser);
19 /* buf != NULL here if config file was not found, empty 19 /* buf != NULL here if config file was not found, empty
20 * or line was found which equals short_tty */ 20 * or line was found which equals short_tty.
21 * In all these cases, we report "this tty is secure".
22 */
21 return buf != NULL; 23 return buf != NULL;
22} 24}
diff --git a/loginutils/login.c b/loginutils/login.c
index 661a87448..be05def09 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -486,7 +486,7 @@ int login_main(int argc UNUSED_PARAM, char **argv)
486 if (opt & LOGIN_OPT_f) 486 if (opt & LOGIN_OPT_f)
487 break; /* -f USER: success without asking passwd */ 487 break; /* -f USER: success without asking passwd */
488 488
489 if (pw->pw_uid == 0 && !check_securetty(short_tty)) 489 if (pw->pw_uid == 0 && !is_tty_secure(short_tty))
490 goto auth_failed; 490 goto auth_failed;
491 491
492 /* Don't check the password if password entry is empty (!) */ 492 /* Don't check the password if password entry is empty (!) */
diff --git a/loginutils/su.c b/loginutils/su.c
index f2cd799ae..ef74aa77d 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -134,7 +134,7 @@ int su_main(int argc UNUSED_PARAM, char **argv)
134 if (r > 0) { 134 if (r > 0) {
135 if (ENABLE_FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY 135 if (ENABLE_FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY
136 && r == CHECKPASS_PW_HAS_EMPTY_PASSWORD 136 && r == CHECKPASS_PW_HAS_EMPTY_PASSWORD
137 && !check_securetty(tty) 137 && !is_tty_secure(tty)
138 ) { 138 ) {
139 goto fail; 139 goto fail;
140 } 140 }