-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetsebool_u.c
42 lines (35 loc) · 992 Bytes
/
setsebool_u.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <selinux/selinux.h>
#include <errno.h>
static int do_setsebool(char **args) {
char *name = args[1];
const char *value = args[2];
SELboolean b;
if(is_selinux_enabled() <= 0) return 0;
b.name = name;
if(strcmp(value, "1") == 0 || strcasecmp(value, "true") == 0 || strcasecmp(value, "on") == 0) b.value = 1;
else if(strcmp(value, "0") == 0 || strcasecmp(value, "false") == 0 || strcasecmp(value, "off") == 0) b.value = 0;
else {
fprintf(stderr, "setsebool: invalid value %s\n", value);
return -1;
}
if(security_set_boolean_list(1, &b, 0) < 0) {
fprintf(stderr, "setsebool: could not set %s to %s: %s", name, value, strerror(errno));
return -1;
}
return 0;
}
int setsebool_main(int argc, char **argv)
{
if(argc != 3) {
fprintf(stderr, "Usage: %s name value\n", argv[0]);
return -1;
}
return do_setsebool(argv);
}