1 #include <unistd.h>
2 #include <sys/types.h>
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include <errno.h>
6 #include <string.h>
7 #include "selinux_internal.h"
8 #include "policy.h"
9 #include <stdio.h>
10 #include <limits.h>
11
security_deny_unknown(void)12 int security_deny_unknown(void)
13 {
14 int fd, ret, deny_unknown = 0;
15 char path[PATH_MAX];
16 char buf[20];
17
18 if (!selinux_mnt) {
19 errno = ENOENT;
20 return -1;
21 }
22
23 snprintf(path, sizeof(path), "%s/deny_unknown", selinux_mnt);
24 fd = open(path, O_RDONLY | O_CLOEXEC);
25 if (fd < 0)
26 return -1;
27
28 memset(buf, 0, sizeof(buf));
29 ret = read(fd, buf, sizeof(buf) - 1);
30 close(fd);
31 if (ret < 0)
32 return -1;
33
34 if (sscanf(buf, "%d", &deny_unknown) != 1)
35 return -1;
36
37 return deny_unknown;
38 }
39
40 hidden_def(security_deny_unknown);
41