• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "policy.h"
10 
is_selinux_enabled(void)11 int is_selinux_enabled(void)
12 {
13 	/* init_selinuxmnt() gets called before this function. We
14  	 * will assume that if a selinux file system is mounted, then
15  	 * selinux is enabled. */
16 #ifdef ANDROID
17 	return (selinux_mnt ? 1 : 0);
18 #else
19 	return (selinux_mnt && has_selinux_config);
20 #endif
21 }
22 
hidden_def(is_selinux_enabled)23 hidden_def(is_selinux_enabled)
24 
25 /*
26  * Function: is_selinux_mls_enabled()
27  * Return:   1 on success
28  *	     0 on failure
29  */
30 int is_selinux_mls_enabled(void)
31 {
32 	char buf[20], path[PATH_MAX];
33 	int fd, ret, enabled = 0;
34 
35 	if (!selinux_mnt)
36 		return enabled;
37 
38 	snprintf(path, sizeof path, "%s/mls", selinux_mnt);
39 	fd = open(path, O_RDONLY | O_CLOEXEC);
40 	if (fd < 0)
41 		return enabled;
42 
43 	memset(buf, 0, sizeof buf);
44 
45 	do {
46 		ret = read(fd, buf, sizeof buf - 1);
47 	} while (ret < 0 && errno == EINTR);
48 	close(fd);
49 	if (ret < 0)
50 		return enabled;
51 
52 	if (!strcmp(buf, "1"))
53 		enabled = 1;
54 
55 	return enabled;
56 }
57 
58 hidden_def(is_selinux_mls_enabled)
59