summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Kbuild.src1
-rw-r--r--libbb/securetty.c22
2 files changed, 23 insertions, 0 deletions
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index 898a51a..49493c5 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -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
index 0000000..176cee1
--- /dev/null
+++ b/libbb/securetty.c
@@ -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;
+}