aboutsummaryrefslogtreecommitdiff
path: root/libbb/securetty.c
blob: 21354e2fa2fa99d2f516f88d80c4e0c95dc0817f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* vi: set sw=4 ts=4: */
/*
 * /etc/securetty checking.
 *
 * Licensed under GPLv2, see file LICENSE in this source tree.
 */
#include "libbb.h"

#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
int FAST_FUNC is_tty_secure(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.
	 * In all these cases, we report "this tty is secure".
	 */
	return buf != NULL;
}
#endif