diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2016-01-02 00:20:39 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-13 12:39:03 +0200 |
commit | 517a82c5b6b5e279f3e96a6774445a2952ca312b (patch) | |
tree | 5eff7ec6bb69bceedcea35fce37cf0e4380fea82 | |
parent | c054822027a4a6895bc95979c6c10ff5763c7c7e (diff) | |
download | busybox-w32-517a82c5b6b5e279f3e96a6774445a2952ca312b.tar.gz busybox-w32-517a82c5b6b5e279f3e96a6774445a2952ca312b.tar.bz2 busybox-w32-517a82c5b6b5e279f3e96a6774445a2952ca312b.zip |
login: move check_securetty to libbb
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | libbb/Kbuild.src | 1 | ||||
-rw-r--r-- | libbb/securetty.c | 22 | ||||
-rw-r--r-- | loginutils/login.c | 19 |
4 files changed, 28 insertions, 19 deletions
diff --git a/include/libbb.h b/include/libbb.h index 777a4a884..6b33ffad6 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1481,6 +1481,11 @@ extern void selinux_or_die(void) FAST_FUNC; | |||
1481 | #define SETUP_ENV_NO_CHDIR (1 << 4) | 1481 | #define SETUP_ENV_NO_CHDIR (1 << 4) |
1482 | void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; | 1482 | void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; |
1483 | void nuke_str(char *str) FAST_FUNC; | 1483 | void nuke_str(char *str) FAST_FUNC; |
1484 | #if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM | ||
1485 | int check_securetty(const char *short_tty) FAST_FUNC; | ||
1486 | #else | ||
1487 | static ALWAYS_INLINE int check_securetty(const char *short_tty UNUSED_PARAM) { return 1; } | ||
1488 | #endif | ||
1484 | int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC; | 1489 | int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC; |
1485 | int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; | 1490 | int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; |
1486 | int ask_and_check_password(const struct passwd *pw) FAST_FUNC; | 1491 | int ask_and_check_password(const struct passwd *pw) FAST_FUNC; |
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index 898a51a89..49493c501 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src | |||
@@ -83,6 +83,7 @@ lib-y += safe_gethostname.o | |||
83 | lib-y += safe_poll.o | 83 | lib-y += safe_poll.o |
84 | lib-y += safe_strncpy.o | 84 | lib-y += safe_strncpy.o |
85 | lib-y += safe_write.o | 85 | lib-y += safe_write.o |
86 | lib-y += securetty.o | ||
86 | lib-y += setup_environment.o | 87 | lib-y += setup_environment.o |
87 | lib-y += signals.o | 88 | lib-y += signals.o |
88 | lib-y += simplify_path.o | 89 | lib-y += simplify_path.o |
diff --git a/libbb/securetty.c b/libbb/securetty.c new file mode 100644 index 000000000..176cee129 --- /dev/null +++ b/libbb/securetty.c | |||
@@ -0,0 +1,22 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * /etc/securetty checking. | ||
4 | * | ||
5 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
6 | */ | ||
7 | #include "libbb.h" | ||
8 | |||
9 | int FAST_FUNC check_securetty(const char *short_tty) | ||
10 | { | ||
11 | char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */ | ||
12 | parser_t *parser = config_open2("/etc/securetty", fopen_for_read); | ||
13 | while (config_read(parser, &buf, 1, 1, "# \t", PARSE_NORMAL)) { | ||
14 | if (strcmp(buf, short_tty) == 0) | ||
15 | break; | ||
16 | buf = NULL; | ||
17 | } | ||
18 | config_close(parser); | ||
19 | /* buf != NULL here if config file was not found, empty | ||
20 | * or line was found which equals short_tty */ | ||
21 | return buf != NULL; | ||
22 | } | ||
diff --git a/loginutils/login.c b/loginutils/login.c index d1757a65d..661a87448 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -175,25 +175,6 @@ static void die_if_nologin(void) | |||
175 | # define die_if_nologin() ((void)0) | 175 | # define die_if_nologin() ((void)0) |
176 | #endif | 176 | #endif |
177 | 177 | ||
178 | #if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM | ||
179 | static int check_securetty(const char *short_tty) | ||
180 | { | ||
181 | char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */ | ||
182 | parser_t *parser = config_open2("/etc/securetty", fopen_for_read); | ||
183 | while (config_read(parser, &buf, 1, 1, "# \t", PARSE_NORMAL)) { | ||
184 | if (strcmp(buf, short_tty) == 0) | ||
185 | break; | ||
186 | buf = NULL; | ||
187 | } | ||
188 | config_close(parser); | ||
189 | /* buf != NULL here if config file was not found, empty | ||
190 | * or line was found which equals short_tty */ | ||
191 | return buf != NULL; | ||
192 | } | ||
193 | #else | ||
194 | static ALWAYS_INLINE int check_securetty(const char *short_tty UNUSED_PARAM) { return 1; } | ||
195 | #endif | ||
196 | |||
197 | #if ENABLE_SELINUX | 178 | #if ENABLE_SELINUX |
198 | static void initselinux(char *username, char *full_tty, | 179 | static void initselinux(char *username, char *full_tty, |
199 | security_context_t *user_sid) | 180 | security_context_t *user_sid) |