blob: 4a3d87d0f3736191b8e499596f770af27031bc74 [file] [log] [blame]
Stephen Smalley8290d102012-01-13 08:53:56 -05001#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 SELboolean *b = alloca(nargs * sizeof(SELboolean));
13 char *v;
14 int i;
15
16 if (is_selinux_enabled() <= 0)
17 return 0;
18
19 for (i = 1; i < nargs; i++) {
20 char *name = args[i];
21 v = strchr(name, '=');
22 if (!v) {
23 fprintf(stderr, "setsebool: argument %s had no =\n", name);
24 return -1;
25 }
26 *v++ = 0;
27 b[i-1].name = name;
28 if (!strcmp(v, "1") || !strcasecmp(v, "true") || !strcasecmp(v, "on"))
29 b[i-1].value = 1;
30 else if (!strcmp(v, "0") || !strcasecmp(v, "false") || !strcasecmp(v, "off"))
31 b[i-1].value = 0;
32 else {
33 fprintf(stderr, "setsebool: invalid value %s\n", v);
34 return -1;
35 }
36 }
37
38 if (security_set_boolean_list(nargs - 1, b, 0) < 0)
39 {
40 fprintf(stderr, "setsebool: unable to set booleans: %s", strerror(errno));
41 return -1;
42 }
43
44 return 0;
45}
46
47int setsebool_main(int argc, char **argv)
48{
49 if (argc < 2) {
50 fprintf(stderr, "Usage: %s name=value...\n", argv[0]);
51 exit(1);
52 }
53
54 return do_setsebool(argc, argv);
55}