1 #include <unistd.h>
2 #include <fcntl.h>
3 #include <string.h>
4 #include "selinux_internal.h"
5 #include <stdlib.h>
6 #include <errno.h>
7 #include <limits.h>
8 #include <stdio.h>
9 #include <stdio_ext.h>
10 #include "policy.h"
11
is_selinux_enabled(void)12 int is_selinux_enabled(void)
13 {
14 /* init_selinuxmnt() gets called before this function. We
15 * will assume that if a selinux file system is mounted, then
16 * selinux is enabled. */
17 return (selinux_mnt ? 1 : 0);
18 }
19
hidden_def(is_selinux_enabled)20 hidden_def(is_selinux_enabled)
21
22 /*
23 * Function: is_selinux_mls_enabled()
24 * Return: 1 on success
25 * 0 on failure
26 */
27 int is_selinux_mls_enabled(void)
28 {
29 char buf[20], path[PATH_MAX];
30 int fd, ret, enabled = 0;
31
32 if (!selinux_mnt)
33 return enabled;
34
35 snprintf(path, sizeof path, "%s/mls", selinux_mnt);
36 fd = open(path, O_RDONLY);
37 if (fd < 0)
38 return enabled;
39
40 memset(buf, 0, sizeof buf);
41
42 do {
43 ret = read(fd, buf, sizeof buf - 1);
44 } while (ret < 0 && errno == EINTR);
45 close(fd);
46 if (ret < 0)
47 return enabled;
48
49 if (!strcmp(buf, "1"))
50 enabled = 1;
51
52 return enabled;
53 }
54
55 hidden_def(is_selinux_mls_enabled)
56