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 | * |
| 7 | */ |
| 8 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 9 | #include "libbb.h" |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 10 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 11 | int getsebool_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 12 | int getsebool_main(int argc, char **argv) |
| 13 | { |
| 14 | int i, rc = 0, active, pending, len = 0; |
| 15 | char **names; |
| 16 | unsigned opt; |
| 17 | |
| 18 | selinux_or_die(); |
Denis Vlasenko | fe7cd64 | 2007-08-18 15:32:12 +0000 | [diff] [blame] | 19 | opt = getopt32(argv, "a"); |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 20 | |
| 21 | if (opt) { /* -a */ |
| 22 | if (argc > 2) |
| 23 | bb_show_usage(); |
| 24 | |
| 25 | rc = security_get_boolean_names(&names, &len); |
| 26 | if (rc) |
| 27 | bb_perror_msg_and_die("cannot get boolean names"); |
| 28 | |
| 29 | if (!len) { |
| 30 | puts("No booleans"); |
| 31 | return 0; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | if (!len) { |
| 36 | if (argc < 2) |
| 37 | bb_show_usage(); |
| 38 | len = argc - 1; |
| 39 | names = xmalloc(sizeof(char *) * len); |
| 40 | for (i = 0; i < len; i++) |
| 41 | names[i] = xstrdup(argv[i + 1]); |
| 42 | } |
| 43 | |
| 44 | for (i = 0; i < len; i++) { |
| 45 | active = security_get_boolean_active(names[i]); |
| 46 | if (active < 0) { |
| 47 | bb_error_msg_and_die("error getting active value for %s", names[i]); |
| 48 | } |
| 49 | pending = security_get_boolean_pending(names[i]); |
| 50 | if (pending < 0) { |
| 51 | bb_error_msg_and_die("error getting pending value for %s", names[i]); |
| 52 | } |
| 53 | printf("%s --> %s", names[i], (active ? "on" : "off")); |
| 54 | if (pending != active) |
| 55 | printf(" pending: %s", (pending ? "on" : "off")); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 56 | bb_putchar('\n'); |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 60 | for (i = 0; i < len; i++) |
| 61 | free(names[i]); |
| 62 | free(names); |
| 63 | } |
| 64 | |
| 65 | return rc; |
| 66 | } |