Home | History | Annotate | Download | only in sepolicy-analyze
      1 #include "attribute.h"
      2 
      3 void attribute_usage() {
      4     fprintf(stderr, "\tattribute <attribute-name>\n");
      5 }
      6 
      7 static int list_attribute(policydb_t * policydb, char *name)
      8 {
      9     struct type_datum *attr;
     10     struct ebitmap_node *n;
     11     unsigned int bit;
     12 
     13     attr = hashtab_search(policydb->p_types.table, name);
     14     if (!attr) {
     15         fprintf(stderr, "%s is not defined in this policy.\n", name);
     16         return -1;
     17     }
     18 
     19     if (attr->flavor != TYPE_ATTRIB) {
     20         fprintf(stderr, "%s is a type not an attribute in this policy.\n", name);
     21         return -1;
     22     }
     23 
     24     ebitmap_for_each_bit(&policydb->attr_type_map[attr->s.value - 1], n, bit) {
     25         if (!ebitmap_node_get_bit(n, bit))
     26             continue;
     27         printf("%s\n", policydb->p_type_val_to_name[bit]);
     28     }
     29 
     30     return 0;
     31 }
     32 
     33 int attribute_func (int argc, char **argv, policydb_t *policydb) {
     34     if (argc != 2) {
     35         USAGE_ERROR = true;
     36         return -1;
     37     }
     38     return list_attribute(policydb, argv[1]);
     39 }
     40