Blame libselinux/src/enabled.c
|
Chris PeBenito |
473ea7 |
#include <unistd.h>
|
|
Chris PeBenito |
473ea7 |
#include <fcntl.h>
|
|
Chris PeBenito |
473ea7 |
#include <string.h>
|
|
Chris PeBenito |
473ea7 |
#include "selinux_internal.h"
|
|
Chris PeBenito |
473ea7 |
#include <stdlib.h>
|
|
Chris PeBenito |
473ea7 |
#include <errno.h>
|
|
Chris PeBenito |
473ea7 |
#include <limits.h>
|
|
Chris PeBenito |
473ea7 |
#include <asm/page.h>
|
|
Chris PeBenito |
473ea7 |
#include <stdio.h>
|
|
Chris PeBenito |
473ea7 |
#include "policy.h"
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
int is_selinux_enabled(void)
|
|
Chris PeBenito |
473ea7 |
{
|
|
Chris PeBenito |
473ea7 |
char *buf;
|
|
Chris PeBenito |
473ea7 |
size_t size;
|
|
Chris PeBenito |
473ea7 |
int fd;
|
|
Chris PeBenito |
473ea7 |
ssize_t ret;
|
|
Chris PeBenito |
473ea7 |
int enabled = 0;
|
|
Chris PeBenito |
473ea7 |
security_context_t con;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
fd = open("/proc/filesystems", O_RDONLY);
|
|
Chris PeBenito |
473ea7 |
if (fd < 0)
|
|
Chris PeBenito |
473ea7 |
return -1;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
size = PAGE_SIZE;
|
|
Chris PeBenito |
473ea7 |
buf = malloc(size);
|
|
Chris PeBenito |
473ea7 |
if (!buf) {
|
|
Chris PeBenito |
473ea7 |
enabled = -1;
|
|
Chris PeBenito |
473ea7 |
goto out;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
memset(buf, 0, size);
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
ret = read(fd, buf, size - 1);
|
|
Chris PeBenito |
473ea7 |
if (ret < 0) {
|
|
Chris PeBenito |
473ea7 |
enabled = -1;
|
|
Chris PeBenito |
473ea7 |
goto out2;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
if (!strstr(buf, "selinuxfs"))
|
|
Chris PeBenito |
473ea7 |
goto out2;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
enabled = 1;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
if (getcon_raw(&con) == 0) {
|
|
Chris PeBenito |
473ea7 |
if (!strcmp(con, "kernel"))
|
|
Chris PeBenito |
473ea7 |
enabled = 0;
|
|
Chris PeBenito |
473ea7 |
freecon(con);
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
out2:
|
|
Chris PeBenito |
473ea7 |
free(buf);
|
|
Chris PeBenito |
473ea7 |
out:
|
|
Chris PeBenito |
473ea7 |
close(fd);
|
|
Chris PeBenito |
473ea7 |
return enabled;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
hidden_def(is_selinux_enabled)
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/*
|
|
Chris PeBenito |
473ea7 |
* Function: is_selinux_mls_enabled()
|
|
Chris PeBenito |
473ea7 |
* Return: 1 on success
|
|
Chris PeBenito |
473ea7 |
* 0 on failure
|
|
Chris PeBenito |
473ea7 |
*/
|
|
Chris PeBenito |
473ea7 |
int is_selinux_mls_enabled(void)
|
|
Chris PeBenito |
473ea7 |
{
|
|
Chris PeBenito |
473ea7 |
char buf[20], path[PATH_MAX];
|
|
Chris PeBenito |
473ea7 |
int fd, ret, enabled = 0;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
snprintf(path, sizeof path, "%s/mls", selinux_mnt);
|
|
Chris PeBenito |
473ea7 |
fd = open(path, O_RDONLY);
|
|
Chris PeBenito |
473ea7 |
if (fd < 0)
|
|
Chris PeBenito |
473ea7 |
return enabled;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
memset(buf, 0, sizeof buf);
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
ret = read(fd, buf, sizeof buf-1);
|
|
Chris PeBenito |
473ea7 |
close(fd);
|
|
Chris PeBenito |
473ea7 |
if (ret < 0)
|
|
Chris PeBenito |
473ea7 |
return enabled;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
if (!strcmp(buf, "1"))
|
|
Chris PeBenito |
473ea7 |
enabled = 1;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
return enabled;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
hidden_def(is_selinux_mls_enabled)
|