blob: e8f0fefb053d4b53106fa9001faae6b7a0b7bc42 [file] [log] [blame]
Denis Vlasenkod46d3c22007-02-06 19:28:50 +00001/*
2 * getsebool
3 *
4 * Based on libselinux 1.33.1
5 * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp>
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenkod46d3c22007-02-06 19:28:50 +00008 */
9
Pere Orga5bc8c002011-04-11 03:29:49 +020010//usage:#define getsebool_trivial_usage
11//usage: "-a or getsebool boolean..."
12//usage:#define getsebool_full_usage "\n\n"
13//usage: " -a Show all selinux booleans"
14
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000015#include "libbb.h"
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000016
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000017int getsebool_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000018int getsebool_main(int argc, char **argv)
19{
20 int i, rc = 0, active, pending, len = 0;
21 char **names;
22 unsigned opt;
23
24 selinux_or_die();
Denis Vlasenkofe7cd642007-08-18 15:32:12 +000025 opt = getopt32(argv, "a");
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000026
27 if (opt) { /* -a */
28 if (argc > 2)
29 bb_show_usage();
30
31 rc = security_get_boolean_names(&names, &len);
32 if (rc)
Denys Vlasenko6331cf02009-11-13 09:08:27 +010033 bb_perror_msg_and_die("can't get boolean names");
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000034
35 if (!len) {
36 puts("No booleans");
37 return 0;
38 }
39 }
40
41 if (!len) {
42 if (argc < 2)
43 bb_show_usage();
44 len = argc - 1;
45 names = xmalloc(sizeof(char *) * len);
46 for (i = 0; i < len; i++)
47 names[i] = xstrdup(argv[i + 1]);
48 }
49
50 for (i = 0; i < len; i++) {
51 active = security_get_boolean_active(names[i]);
52 if (active < 0) {
53 bb_error_msg_and_die("error getting active value for %s", names[i]);
54 }
55 pending = security_get_boolean_pending(names[i]);
56 if (pending < 0) {
57 bb_error_msg_and_die("error getting pending value for %s", names[i]);
58 }
59 printf("%s --> %s", names[i], (active ? "on" : "off"));
60 if (pending != active)
61 printf(" pending: %s", (pending ? "on" : "off"));
Denis Vlasenko4daad902007-09-27 10:20:47 +000062 bb_putchar('\n');
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000063 }
64
65 if (ENABLE_FEATURE_CLEAN_UP) {
66 for (i = 0; i < len; i++)
67 free(names[i]);
68 free(names);
69 }
70
71 return rc;
72}