aboutsummaryrefslogtreecommitdiff
path: root/selinux/getsebool.c
diff options
context:
space:
mode:
Diffstat (limited to 'selinux/getsebool.c')
-rw-r--r--selinux/getsebool.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/selinux/getsebool.c b/selinux/getsebool.c
new file mode 100644
index 000000000..d593937ba
--- /dev/null
+++ b/selinux/getsebool.c
@@ -0,0 +1,65 @@
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
9#include "busybox.h"
10
11int getsebool_main(int argc, char **argv)
12{
13 int i, rc = 0, active, pending, len = 0;
14 char **names;
15 unsigned opt;
16
17 selinux_or_die();
18 opt = getopt32(argc, argv, "a");
19
20 if (opt) { /* -a */
21 if (argc > 2)
22 bb_show_usage();
23
24 rc = security_get_boolean_names(&names, &len);
25 if (rc)
26 bb_perror_msg_and_die("cannot get boolean names");
27
28 if (!len) {
29 puts("No booleans");
30 return 0;
31 }
32 }
33
34 if (!len) {
35 if (argc < 2)
36 bb_show_usage();
37 len = argc - 1;
38 names = xmalloc(sizeof(char *) * len);
39 for (i = 0; i < len; i++)
40 names[i] = xstrdup(argv[i + 1]);
41 }
42
43 for (i = 0; i < len; i++) {
44 active = security_get_boolean_active(names[i]);
45 if (active < 0) {
46 bb_error_msg_and_die("error getting active value for %s", names[i]);
47 }
48 pending = security_get_boolean_pending(names[i]);
49 if (pending < 0) {
50 bb_error_msg_and_die("error getting pending value for %s", names[i]);
51 }
52 printf("%s --> %s", names[i], (active ? "on" : "off"));
53 if (pending != active)
54 printf(" pending: %s", (pending ? "on" : "off"));
55 putchar('\n');
56 }
57
58 if (ENABLE_FEATURE_CLEAN_UP) {
59 for (i = 0; i < len; i++)
60 free(names[i]);
61 free(names);
62 }
63
64 return rc;
65}