blob: 21354e2fa2fa99d2f516f88d80c4e0c95dc0817f [file] [log] [blame]
Kaarle Ritvanen517a82c2016-01-02 00:20:39 +02001/* 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
Denys Vlasenko44c0ab42017-04-13 17:55:05 +02009#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
Denys Vlasenkoa3de0b32017-04-13 13:04:05 +020010int FAST_FUNC is_tty_secure(const char *short_tty)
Kaarle Ritvanen517a82c2016-01-02 00:20:39 +020011{
12 char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */
13 parser_t *parser = config_open2("/etc/securetty", fopen_for_read);
14 while (config_read(parser, &buf, 1, 1, "# \t", PARSE_NORMAL)) {
15 if (strcmp(buf, short_tty) == 0)
16 break;
17 buf = NULL;
18 }
19 config_close(parser);
20 /* buf != NULL here if config file was not found, empty
Denys Vlasenkoa3de0b32017-04-13 13:04:05 +020021 * or line was found which equals short_tty.
22 * In all these cases, we report "this tty is secure".
23 */
Kaarle Ritvanen517a82c2016-01-02 00:20:39 +020024 return buf != NULL;
25}
Denys Vlasenko44c0ab42017-04-13 17:55:05 +020026#endif