Print permissive rules

This commit is contained in:
topjohnwu 2023-08-02 09:11:22 -07:00
parent f2e109ad7d
commit 17ba5cba3e

View File

@ -83,15 +83,18 @@ static int avtab_remove_node(avtab_t *h, avtab_ptr_t node) {
if (!h || !h->htable) if (!h || !h->htable)
return SEPOL_ENOMEM; return SEPOL_ENOMEM;
int hvalue = avtab_hash(&node->key, h->mask); int hvalue = avtab_hash(&node->key, h->mask);
avtab_ptr_t prev, cur; avtab_ptr_t prev = nullptr;
for (prev = nullptr, cur = h->htable[hvalue]; cur; prev = cur, cur = cur->next) { avtab_ptr_t cur = h->htable[hvalue];
while (cur) {
if (cur == node) if (cur == node)
break; break;
prev = cur;
cur = cur->next;
} }
if (cur == nullptr) if (cur == nullptr)
return SEPOL_ENOENT; return SEPOL_ENOENT;
// Detach from hash table // Detach from link list
if (prev) if (prev)
prev->next = node->next; prev->next = node->next;
else else
@ -99,7 +102,6 @@ static int avtab_remove_node(avtab_t *h, avtab_ptr_t node) {
h->nel--; h->nel--;
// Free memory // Free memory
if (node->key.specified & AVTAB_XPERMS)
free(node->datum.xperms); free(node->datum.xperms);
free(node); free(node);
return 0; return 0;
@ -730,12 +732,12 @@ void sepolicy::print_rules() {
} }
void sepol_impl::print_type(FILE *fp, type_datum_t *type) { void sepol_impl::print_type(FILE *fp, type_datum_t *type) {
const char *name = db->p_type_val_to_name[type->s.value - 1];
if (name == nullptr)
return;
if (type->flavor == TYPE_ATTRIB) { if (type->flavor == TYPE_ATTRIB) {
if (const char *attr = db->p_type_val_to_name[type->s.value - 1]) { fprintf(fp, "attribute %s\n", name);
fprintf(fp, "attribute %s\n", attr);
}
} else if (type->flavor == TYPE_TYPE) { } else if (type->flavor == TYPE_TYPE) {
if (const char *name = db->p_type_val_to_name[type->s.value - 1]) {
bool first = true; bool first = true;
ebitmap_t *bitmap = &db->type_attr_map[type->s.value - 1]; ebitmap_t *bitmap = &db->type_attr_map[type->s.value - 1];
for (uint32_t i = 0; i <= bitmap->highbit; ++i) { for (uint32_t i = 0; i <= bitmap->highbit; ++i) {
@ -756,6 +758,8 @@ void sepol_impl::print_type(FILE *fp, type_datum_t *type) {
fprintf(fp, " }\n"); fprintf(fp, " }\n");
} }
} }
if (ebitmap_get_bit(&db->permissive_map, type->s.value)) {
fprintf(stdout, "permissive %s\n", name);
} }
} }