summaryrefslogtreecommitdiff
path: root/src/deny_unknown.c
blob: c93998a046b0eec962ca200f07533b3ba60bfcb7 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "selinux_internal.h"
#include "policy.h"
#include <stdio.h>
#include <limits.h>

int security_deny_unknown(void)
{
	int fd, ret, deny_unknown = 0;
	char path[PATH_MAX];
	char buf[20];

	if (!selinux_mnt) {
		errno = ENOENT;
		return -1;
	}

	snprintf(path, sizeof(path), "%s/deny_unknown", selinux_mnt);
	fd = open(path, O_RDONLY);
	if (fd < 0)
		return -1;

	memset(buf, 0, sizeof(buf));
	ret = read(fd, buf, sizeof(buf) - 1);
	close(fd);
	if (ret < 0)
		return -1;

	if (sscanf(buf, "%d", &deny_unknown) != 1)
		return -1;

	return deny_unknown;
}

hidden_def(security_deny_unknown);