Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * getsebool |
| 3 | * |
| 4 | * Based on libselinux 1.33.1 |
| 5 | * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp> |
| 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | a8e52da | 2016-11-23 18:46:40 +0100 | [diff] [blame] | 9 | //config:config GETSEBOOL |
Denys Vlasenko | ae178ce | 2017-07-19 14:32:54 +0200 | [diff] [blame] | 10 | //config: bool "getsebool (5.5 kb)" |
Denys Vlasenko | a8e52da | 2016-11-23 18:46:40 +0100 | [diff] [blame] | 11 | //config: default n |
| 12 | //config: depends on SELINUX |
| 13 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 14 | //config: Enable support to get SELinux boolean values. |
Denys Vlasenko | a8e52da | 2016-11-23 18:46:40 +0100 | [diff] [blame] | 15 | |
| 16 | //applet:IF_GETSEBOOL(APPLET(getsebool, BB_DIR_USR_SBIN, BB_SUID_DROP)) |
| 17 | |
| 18 | //kbuild:lib-$(CONFIG_GETSEBOOL) += getsebool.o |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 19 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 20 | //usage:#define getsebool_trivial_usage |
| 21 | //usage: "-a or getsebool boolean..." |
| 22 | //usage:#define getsebool_full_usage "\n\n" |
| 23 | //usage: " -a Show all selinux booleans" |
| 24 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 25 | #include "libbb.h" |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 26 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 27 | int getsebool_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 28 | int getsebool_main(int argc, char **argv) |
| 29 | { |
| 30 | int i, rc = 0, active, pending, len = 0; |
| 31 | char **names; |
| 32 | unsigned opt; |
| 33 | |
| 34 | selinux_or_die(); |
Denis Vlasenko | fe7cd64 | 2007-08-18 15:32:12 +0000 | [diff] [blame] | 35 | opt = getopt32(argv, "a"); |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 36 | |
| 37 | if (opt) { /* -a */ |
| 38 | if (argc > 2) |
| 39 | bb_show_usage(); |
| 40 | |
| 41 | rc = security_get_boolean_names(&names, &len); |
| 42 | if (rc) |
Denys Vlasenko | 6331cf0 | 2009-11-13 09:08:27 +0100 | [diff] [blame] | 43 | bb_perror_msg_and_die("can't get boolean names"); |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 44 | |
| 45 | if (!len) { |
| 46 | puts("No booleans"); |
| 47 | return 0; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if (!len) { |
| 52 | if (argc < 2) |
| 53 | bb_show_usage(); |
| 54 | len = argc - 1; |
| 55 | names = xmalloc(sizeof(char *) * len); |
| 56 | for (i = 0; i < len; i++) |
| 57 | names[i] = xstrdup(argv[i + 1]); |
| 58 | } |
| 59 | |
| 60 | for (i = 0; i < len; i++) { |
| 61 | active = security_get_boolean_active(names[i]); |
| 62 | if (active < 0) { |
| 63 | bb_error_msg_and_die("error getting active value for %s", names[i]); |
| 64 | } |
| 65 | pending = security_get_boolean_pending(names[i]); |
| 66 | if (pending < 0) { |
| 67 | bb_error_msg_and_die("error getting pending value for %s", names[i]); |
| 68 | } |
| 69 | printf("%s --> %s", names[i], (active ? "on" : "off")); |
| 70 | if (pending != active) |
| 71 | printf(" pending: %s", (pending ? "on" : "off")); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 72 | bb_putchar('\n'); |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 76 | for (i = 0; i < len; i++) |
| 77 | free(names[i]); |
| 78 | free(names); |
| 79 | } |
| 80 | |
| 81 | return rc; |
| 82 | } |