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