blob: ea080d483a8693a802aae5cd1866e1bc0c93f065 [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 *
7 */
8
Denis Vlasenkob6adbf12007-05-26 19:00:18 +00009#include "libbb.h"
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000010
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000011int getsebool_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000012int 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 Vlasenkofe7cd642007-08-18 15:32:12 +000019 opt = getopt32(argv, "a");
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000020
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 Vlasenko4daad902007-09-27 10:20:47 +000056 bb_putchar('\n');
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000057 }
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}