1 #include <unistd.h>
2 #include <sys/types.h>
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include <errno.h>
6 #include <string.h>
7 #include "selinux_internal.h"
8 #include "policy.h"
9 #include <stdio.h>
10 #include <limits.h>
11
security_setenforce(int value)12 int security_setenforce(int value)
13 {
14 int fd, ret;
15 char path[PATH_MAX];
16 char buf[20];
17
18 if (!selinux_mnt) {
19 errno = ENOENT;
20 return -1;
21 }
22
23 snprintf(path, sizeof path, "%s/enforce", selinux_mnt);
24 fd = open(path, O_RDWR);
25 if (fd < 0)
26 return -1;
27
28 snprintf(buf, sizeof buf, "%d", value);
29 ret = write(fd, buf, strlen(buf));
30 close(fd);
31 if (ret < 0)
32 return -1;
33
34 return 0;
35 }
36
37 hidden_def(security_setenforce)
38