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