blob: c60eb19ffa8da7ea5a2ea3369ca3c4264417d315 [file] [log] [blame]
Stephen Smalleyf0740362012-01-04 12:30:47 -05001#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
11int is_selinux_enabled(void)
12{
Stephen Smalleyf0740362012-01-04 12:30:47 -050013 /* init_selinuxmnt() gets called before this function. We
14 * will assume that if a selinux file system is mounted, then
15 * selinux is enabled. */
Stephen Smalley801cd602015-04-17 09:25:51 -040016 return (selinux_mnt ? 1 : 0);
Stephen Smalleyf0740362012-01-04 12:30:47 -050017}
18
19hidden_def(is_selinux_enabled)
20
21/*
22 * Function: is_selinux_mls_enabled()
23 * Return: 1 on success
24 * 0 on failure
25 */
26int is_selinux_mls_enabled(void)
27{
28 char buf[20], path[PATH_MAX];
29 int fd, ret, enabled = 0;
30
31 if (!selinux_mnt)
32 return enabled;
33
34 snprintf(path, sizeof path, "%s/mls", selinux_mnt);
35 fd = open(path, O_RDONLY);
36 if (fd < 0)
37 return enabled;
38
39 memset(buf, 0, sizeof buf);
40
41 do {
42 ret = read(fd, buf, sizeof buf - 1);
43 } while (ret < 0 && errno == EINTR);
44 close(fd);
45 if (ret < 0)
46 return enabled;
47
48 if (!strcmp(buf, "1"))
49 enabled = 1;
50
51 return enabled;
52}
53
54hidden_def(is_selinux_mls_enabled)