blob: f79a6127c3909dffa59356cd647e3cf210072c08 [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) {
Stephen Smalley0e23fee2012-11-28 13:52:12 -050012 const char *name = args[1];
13 const char *value = args[2];
14 SELboolean b;
Stephen Smalley8290d102012-01-13 08:53:56 -050015
16 if (is_selinux_enabled() <= 0)
17 return 0;
18
Stephen Smalley0e23fee2012-11-28 13:52:12 -050019 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;
Stephen Smalley8290d102012-01-13 08:53:56 -050027 }
28
Stephen Smalley0e23fee2012-11-28 13:52:12 -050029 if (security_set_boolean_list(1, &b, 0) < 0)
Stephen Smalley8290d102012-01-13 08:53:56 -050030 {
Stephen Smalley0e23fee2012-11-28 13:52:12 -050031 fprintf(stderr, "setsebool: could not set %s to %s: %s", name, value, strerror(errno));
Stephen Smalley8290d102012-01-13 08:53:56 -050032 return -1;
33 }
34
35 return 0;
36}
37
38int setsebool_main(int argc, char **argv)
39{
Stephen Smalley0e23fee2012-11-28 13:52:12 -050040 if (argc != 3) {
41 fprintf(stderr, "Usage: %s name value\n", argv[0]);
Stephen Smalley8290d102012-01-13 08:53:56 -050042 exit(1);
43 }
44
45 return do_setsebool(argc, argv);
46}