1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#define FOR_setenforce
18#include "toys.h"
19
20void setenforce_main(void)
21{
22 char *new = *toys.optargs;
23 int state, ret;
24
25 if (!is_selinux_enabled()) error_exit("SELinux is disabled");
26 else if (!strcmp(new, "1") || !strcasecmp(new, "enforcing")) state = 1;
27 else if (!strcmp(new, "0") || !strcasecmp(new, "permissive")) state = 0;
28 else error_exit("Invalid state: %s", new);
29
30 ret = security_setenforce(state);
31 if (ret == -1) perror_msg("Couldn't set enforcing status to '%s'", new);
32}
33