login: move check_securetty to libbb
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Fri, 1 Jan 2016 22:20:39 +0000 (00:20 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 13 Apr 2017 10:39:03 +0000 (12:39 +0200)
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
include/libbb.h
libbb/Kbuild.src
libbb/securetty.c [new file with mode: 0644]
loginutils/login.c

index 777a4a8843840ec1ea2a979aec8562529c9dcb84..6b33ffad62d9c733a54cab4f93743ee3684cf957 100644 (file)
@@ -1481,6 +1481,11 @@ extern void selinux_or_die(void) FAST_FUNC;
 #define SETUP_ENV_NO_CHDIR  (1 << 4)
 void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
 void nuke_str(char *str) FAST_FUNC;
+#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
+int check_securetty(const char *short_tty) FAST_FUNC;
+#else
+static ALWAYS_INLINE int check_securetty(const char *short_tty UNUSED_PARAM) { return 1; }
+#endif
 int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC;
 int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
 int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
index 898a51a89cc060ef3fcc132e7333d89df81fe559..49493c501ccd1cebec5aeca3dd9ac45607d57684 100644 (file)
@@ -83,6 +83,7 @@ lib-y += safe_gethostname.o
 lib-y += safe_poll.o
 lib-y += safe_strncpy.o
 lib-y += safe_write.o
+lib-y += securetty.o
 lib-y += setup_environment.o
 lib-y += signals.o
 lib-y += simplify_path.o
diff --git a/libbb/securetty.c b/libbb/securetty.c
new file mode 100644 (file)
index 0000000..176cee1
--- /dev/null
@@ -0,0 +1,22 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * /etc/securetty checking.
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
+#include "libbb.h"
+
+int FAST_FUNC check_securetty(const char *short_tty)
+{
+       char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */
+       parser_t *parser = config_open2("/etc/securetty", fopen_for_read);
+       while (config_read(parser, &buf, 1, 1, "# \t", PARSE_NORMAL)) {
+               if (strcmp(buf, short_tty) == 0)
+                       break;
+               buf = NULL;
+       }
+       config_close(parser);
+       /* buf != NULL here if config file was not found, empty
+        * or line was found which equals short_tty */
+       return buf != NULL;
+}
index d1757a65dcd493ff71b73741c6d39915e5d4cd03..661a874486e5f69e714911f9236f2a05a863fe96 100644 (file)
@@ -175,25 +175,6 @@ static void die_if_nologin(void)
 # define die_if_nologin() ((void)0)
 #endif
 
-#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
-static int check_securetty(const char *short_tty)
-{
-       char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */
-       parser_t *parser = config_open2("/etc/securetty", fopen_for_read);
-       while (config_read(parser, &buf, 1, 1, "# \t", PARSE_NORMAL)) {
-               if (strcmp(buf, short_tty) == 0)
-                       break;
-               buf = NULL;
-       }
-       config_close(parser);
-       /* buf != NULL here if config file was not found, empty
-        * or line was found which equals short_tty */
-       return buf != NULL;
-}
-#else
-static ALWAYS_INLINE int check_securetty(const char *short_tty UNUSED_PARAM) { return 1; }
-#endif
-
 #if ENABLE_SELINUX
 static void initselinux(char *username, char *full_tty,
                                                security_context_t *user_sid)