Skip to content
Snippets Groups Projects
Commit c45e9b9a authored by Dan Cashman's avatar Dan Cashman Committed by android-build-merger
Browse files

sepolicy-analyze: Add ability to list all attributes. am: 9d46f9b4

am: fdb9c018

Change-Id: I97a63c04df7a70822015d99eb619b4ae0147241f
parents 24d3a1cc fdb9c018
No related branches found
No related tags found
No related merge requests found
...@@ -69,6 +69,10 @@ sepolicy-analyze ...@@ -69,6 +69,10 @@ sepolicy-analyze
Displays the attributes associated with the specified type name. Displays the attributes associated with the specified type name.
sepolicy-analyze out/target/product/<board>/root/sepolicy attribute -l
Displays all attributes in the policy.
NEVERALLOW CHECKING (neverallow) NEVERALLOW CHECKING (neverallow)
sepolicy-analyze out/target/product/<board>/root/sepolicy neverallow \ sepolicy-analyze out/target/product/<board>/root/sepolicy neverallow \
[-w] [-d] [-f neverallows.conf] | [-n "neverallow string"] [-w] [-d] [-f neverallows.conf] | [-n "neverallow string"]
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "attribute.h" #include "attribute.h"
void attribute_usage() { void attribute_usage() {
fprintf(stderr, "\tattribute <name> [-r|--reverse]\n"); fprintf(stderr, "\tattribute [-l|--list] [-r|--reverse] <name>\n");
} }
static void retrieve_mapping(policydb_t *policydb, struct type_datum *dat, char *name, int reverse) { 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,29 +53,58 @@ static int list_attribute(policydb_t *policydb, char *name, int reverse)
return 0; return 0;
} }
static int print_attr(__attribute__ ((unused)) hashtab_key_t k,
hashtab_datum_t d, void *args) {
struct type_datum *dat = (struct type_datum *)d;
policydb_t *pdb = (policydb_t *)args;
if (!dat) {
fprintf(stderr, "type encountered without datum!\n");
return -1;
}
if (dat->flavor == TYPE_ATTRIB) {
printf("%s\n", pdb->p_type_val_to_name[dat->s.value - 1]);
}
return 0;
}
static int list_all_attributes(policydb_t *policydb) {
return hashtab_map(policydb->p_types.table, print_attr, policydb);
}
int attribute_func (int argc, char **argv, policydb_t *policydb) { int attribute_func (int argc, char **argv, policydb_t *policydb) {
int rc = -1;
int list = 0;
int reverse = 0; int reverse = 0;
char ch; char ch;
struct option attribute_options[] = { struct option attribute_options[] = {
{"list", no_argument, NULL, 'l'},
{"reverse", no_argument, NULL, 'r'}, {"reverse", no_argument, NULL, 'r'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
while ((ch = getopt_long(argc, argv, "r", attribute_options, NULL)) != -1) { while ((ch = getopt_long(argc, argv, "lr", attribute_options, NULL)) != -1) {
switch (ch) { switch (ch) {
case 'l':
list = 1;
break;
case 'r': case 'r':
reverse = 1; reverse = 1;
break; break;
default: default:
USAGE_ERROR = true; USAGE_ERROR = true;
return -1; goto out;
} }
} }
if (argc != 2 && !(reverse && argc == 3)) { if ((argc != 2 && !(reverse && argc == 3)) || (list && reverse)) {
USAGE_ERROR = true; USAGE_ERROR = true;
return -1; goto out;
} }
return list_attribute(policydb, argv[optind], reverse); if (list)
rc = list_all_attributes(policydb);
else
rc = list_attribute(policydb, argv[optind], reverse);
out:
return rc;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment