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 11int 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 return (selinux_mnt ? 1 : 0); 17} 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) 55