| 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 |
|
| 11 |
int is_selinux_enabled(void) |
| 12 |
{ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifdef ANDROID |
| 17 |
return (selinux_mnt ? 1 : 0); |
| 18 |
#else |
| 19 |
return (selinux_mnt && has_selinux_config); |
| 20 |
#endif |
| 21 |
} |
| 22 |
|
| 23 |
hidden_def(is_selinux_enabled) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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) |