diff options
author | Dan Cashman | 2017-04-14 18:35:12 -0500 |
---|---|---|
committer | Dan Cashman | 2017-04-18 13:08:43 -0500 |
commit | 9d46f9b4f09da557bc737b8a541c5af0fe2fff6e (patch) | |
tree | 12c971fca46fde9eecd3c543735bf66a4ebbc824 /tools | |
parent | 9f152d98eaab9f85993a638394f280abc98e0d79 (diff) | |
download | system-sepolicy-9d46f9b4f09da557bc737b8a541c5af0fe2fff6e.tar.gz system-sepolicy-9d46f9b4f09da557bc737b8a541c5af0fe2fff6e.tar.xz system-sepolicy-9d46f9b4f09da557bc737b8a541c5af0fe2fff6e.zip |
sepolicy-analyze: Add ability to list all attributes.
This could be useful in diffs between policy versions.
Bug: 37357742
Test: sepolicy-analyze lists all attributes in precompiled_policy.
Change-Id: I6532a93d4102cf9cb12b73ee8ed86ece368f9131
Diffstat (limited to 'tools')
-rw-r--r-- | tools/sepolicy-analyze/README | 4 | ||||
-rw-r--r-- | tools/sepolicy-analyze/attribute.c | 41 |
2 files changed, 39 insertions, 6 deletions
diff --git a/tools/sepolicy-analyze/README b/tools/sepolicy-analyze/README index fdee588e..c6657ec4 100644 --- a/tools/sepolicy-analyze/README +++ b/tools/sepolicy-analyze/README | |||
@@ -69,6 +69,10 @@ sepolicy-analyze | |||
69 | 69 | ||
70 | Displays the attributes associated with the specified type name. | 70 | Displays the attributes associated with the specified type name. |
71 | 71 | ||
72 | sepolicy-analyze out/target/product/<board>/root/sepolicy attribute -l | ||
73 | |||
74 | Displays all attributes in the policy. | ||
75 | |||
72 | NEVERALLOW CHECKING (neverallow) | 76 | NEVERALLOW CHECKING (neverallow) |
73 | sepolicy-analyze out/target/product/<board>/root/sepolicy neverallow \ | 77 | sepolicy-analyze out/target/product/<board>/root/sepolicy neverallow \ |
74 | [-w] [-d] [-f neverallows.conf] | [-n "neverallow string"] | 78 | [-w] [-d] [-f neverallows.conf] | [-n "neverallow string"] |
diff --git a/tools/sepolicy-analyze/attribute.c b/tools/sepolicy-analyze/attribute.c index ae98aa98..f7c9b4c8 100644 --- a/tools/sepolicy-analyze/attribute.c +++ b/tools/sepolicy-analyze/attribute.c | |||
@@ -3,7 +3,7 @@ | |||
3 | #include "attribute.h" | 3 | #include "attribute.h" |
4 | 4 | ||
5 | void attribute_usage() { | 5 | void attribute_usage() { |
6 | fprintf(stderr, "\tattribute <name> [-r|--reverse]\n"); | 6 | fprintf(stderr, "\tattribute [-l|--list] [-r|--reverse] <name>\n"); |
7 | } | 7 | } |
8 | 8 | ||
9 | static void retrieve_mapping(policydb_t *policydb, struct type_datum *dat, char *name, int reverse) { | 9 | static void retrieve_mapping(policydb_t *policydb, struct type_datum *dat, char *name, int reverse) { |
@@ -53,29 +53,58 @@ static int list_attribute(policydb_t *policydb, char *name, int reverse) | |||
53 | return 0; | 53 | return 0; |
54 | } | 54 | } |
55 | 55 | ||
56 | static int print_attr(__attribute__ ((unused)) hashtab_key_t k, | ||
57 | hashtab_datum_t d, void *args) { | ||
58 | struct type_datum *dat = (struct type_datum *)d; | ||
59 | policydb_t *pdb = (policydb_t *)args; | ||
60 | if (!dat) { | ||
61 | fprintf(stderr, "type encountered without datum!\n"); | ||
62 | return -1; | ||
63 | } | ||
64 | if (dat->flavor == TYPE_ATTRIB) { | ||
65 | printf("%s\n", pdb->p_type_val_to_name[dat->s.value - 1]); | ||
66 | } | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | static int list_all_attributes(policydb_t *policydb) { | ||
71 | return hashtab_map(policydb->p_types.table, print_attr, policydb); | ||
72 | } | ||
73 | |||
56 | int attribute_func (int argc, char **argv, policydb_t *policydb) { | 74 | int attribute_func (int argc, char **argv, policydb_t *policydb) { |
75 | int rc = -1; | ||
76 | int list = 0; | ||
57 | int reverse = 0; | 77 | int reverse = 0; |
58 | char ch; | 78 | char ch; |
59 | 79 | ||
60 | struct option attribute_options[] = { | 80 | struct option attribute_options[] = { |
81 | {"list", no_argument, NULL, 'l'}, | ||
61 | {"reverse", no_argument, NULL, 'r'}, | 82 | {"reverse", no_argument, NULL, 'r'}, |
62 | {NULL, 0, NULL, 0} | 83 | {NULL, 0, NULL, 0} |
63 | }; | 84 | }; |
64 | 85 | ||
65 | while ((ch = getopt_long(argc, argv, "r", attribute_options, NULL)) != -1) { | 86 | while ((ch = getopt_long(argc, argv, "lr", attribute_options, NULL)) != -1) { |
66 | switch (ch) { | 87 | switch (ch) { |
88 | case 'l': | ||
89 | list = 1; | ||
90 | break; | ||
67 | case 'r': | 91 | case 'r': |
68 | reverse = 1; | 92 | reverse = 1; |
69 | break; | 93 | break; |
70 | default: | 94 | default: |
71 | USAGE_ERROR = true; | 95 | USAGE_ERROR = true; |
72 | return -1; | 96 | goto out; |
73 | } | 97 | } |
74 | } | 98 | } |
75 | 99 | ||
76 | if (argc != 2 && !(reverse && argc == 3)) { | 100 | if ((argc != 2 && !(reverse && argc == 3)) || (list && reverse)) { |
77 | USAGE_ERROR = true; | 101 | USAGE_ERROR = true; |
78 | return -1; | 102 | goto out; |
79 | } | 103 | } |
80 | return list_attribute(policydb, argv[optind], reverse); | 104 | if (list) |
105 | rc = list_all_attributes(policydb); | ||
106 | else | ||
107 | rc = list_attribute(policydb, argv[optind], reverse); | ||
108 | out: | ||
109 | return rc; | ||
81 | } | 110 | } |