Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 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 | |
| 11 | static int do_setsebool(int nargs, char **args) { |
Stephen Smalley | 0e23fee | 2012-11-28 13:52:12 -0500 | [diff] [blame] | 12 | const char *name = args[1]; |
| 13 | const char *value = args[2]; |
| 14 | SELboolean b; |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 15 | |
| 16 | if (is_selinux_enabled() <= 0) |
| 17 | return 0; |
| 18 | |
Stephen Smalley | 0e23fee | 2012-11-28 13:52:12 -0500 | [diff] [blame] | 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; |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 27 | } |
| 28 | |
Stephen Smalley | 0e23fee | 2012-11-28 13:52:12 -0500 | [diff] [blame] | 29 | if (security_set_boolean_list(1, &b, 0) < 0) |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 30 | { |
Stephen Smalley | 0e23fee | 2012-11-28 13:52:12 -0500 | [diff] [blame] | 31 | fprintf(stderr, "setsebool: could not set %s to %s: %s", name, value, strerror(errno)); |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 32 | return -1; |
| 33 | } |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | int setsebool_main(int argc, char **argv) |
| 39 | { |
Stephen Smalley | 0e23fee | 2012-11-28 13:52:12 -0500 | [diff] [blame] | 40 | if (argc != 3) { |
| 41 | fprintf(stderr, "Usage: %s name value\n", argv[0]); |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 42 | exit(1); |
| 43 | } |
| 44 | |
| 45 | return do_setsebool(argc, argv); |
| 46 | } |