1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "libbb.h"
26
27int getsebool_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
28int 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();
35 opt = getopt32(argv, "a");
36
37 if (opt) {
38 if (argc > 2)
39 bb_show_usage();
40
41 rc = security_get_boolean_names(&names, &len);
42 if (rc)
43 bb_simple_perror_msg_and_die("can't get boolean names");
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"));
72 bb_putchar('\n');
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}
83