| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "parse_util.h" |
| 22 |
#include "helpers.h" |
| 23 |
#include "test-common.h" |
| 24 |
|
| 25 |
#include <sepol/policydb/policydb.h> |
| 26 |
#include <sepol/policydb/link.h> |
| 27 |
|
| 28 |
#include <CUnit/Basic.h> |
| 29 |
#include <stdlib.h> |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
static void only_dominates_self(policydb_t * p, role_datum_t * role) |
| 56 |
{ |
| 57 |
ebitmap_node_t *tnode; |
| 58 |
unsigned int i; |
| 59 |
int found = 0; |
| 60 |
|
| 61 |
ebitmap_for_each_bit(&role->dominates, tnode, i) { |
| 62 |
if (ebitmap_node_get_bit(tnode, i)) { |
| 63 |
found++; |
| 64 |
CU_ASSERT(i == role->s.value - 1); |
| 65 |
} |
| 66 |
} |
| 67 |
CU_ASSERT(found == 1); |
| 68 |
} |
| 69 |
|
| 70 |
void base_role_tests(policydb_t * base) |
| 71 |
{ |
| 72 |
avrule_decl_t *decl; |
| 73 |
role_datum_t *role; |
| 74 |
unsigned int decls[2]; |
| 75 |
const char *types[2]; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 82 |
test_sym_presence(base, "g_b_role_1", SYM_ROLES, SCOPE_DECL, decls, 1); |
| 83 |
|
| 84 |
types[0] = "g_b_type_1"; |
| 85 |
role = test_role_type_set(base, "g_b_role_1", NULL, types, 1, 0); |
| 86 |
|
| 87 |
only_dominates_self(base, role); |
| 88 |
|
| 89 |
|
| 90 |
decl = test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_b"); |
| 91 |
decls[0] = decl->decl_id; |
| 92 |
test_sym_presence(base, "o1_b_role_1", SYM_ROLES, SCOPE_DECL, decls, 1); |
| 93 |
|
| 94 |
types[0] = "o1_b_type_1"; |
| 95 |
role = test_role_type_set(base, "o1_b_role_1", decl, types, 1, 0); |
| 96 |
|
| 97 |
only_dominates_self(base, role); |
| 98 |
} |
| 99 |
|
| 100 |
void module_role_tests(policydb_t * base) |
| 101 |
{ |
| 102 |
role_datum_t *role; |
| 103 |
avrule_decl_t *decl; |
| 104 |
unsigned int decls[3]; |
| 105 |
const char *types[3]; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 113 |
test_sym_presence(base, "g_m1_role_1", SYM_ROLES, SCOPE_DECL, decls, 1); |
| 114 |
|
| 115 |
types[0] = "g_m1_type_1"; |
| 116 |
role = test_role_type_set(base, "g_m1_role_1", NULL, types, 1, 0); |
| 117 |
|
| 118 |
only_dominates_self(base, role); |
| 119 |
|
| 120 |
|
| 121 |
decl = test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_m1"); |
| 122 |
decls[0] = decl->decl_id; |
| 123 |
test_sym_presence(base, "o1_m1_role_1", SYM_ROLES, SCOPE_DECL, decls, 1); |
| 124 |
|
| 125 |
types[0] = "o1_m1_type_1"; |
| 126 |
role = test_role_type_set(base, "o1_m1_role_1", decl, types, 1, 0); |
| 127 |
|
| 128 |
only_dominates_self(base, role); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 135 |
test_sym_presence(base, "g_b_role_2", SYM_ROLES, SCOPE_DECL, decls, 1); |
| 136 |
|
| 137 |
types[0] = "g_b_type_2"; |
| 138 |
types[1] = "g_m1_type_1"; |
| 139 |
role = test_role_type_set(base, "g_b_role_2", NULL, types, 2, 0); |
| 140 |
|
| 141 |
only_dominates_self(base, role); |
| 142 |
|
| 143 |
|
| 144 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 145 |
decls[1] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 146 |
decls[2] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m2"))->decl_id; |
| 147 |
test_sym_presence(base, "g_b_role_3", SYM_ROLES, SCOPE_DECL, decls, 3); |
| 148 |
|
| 149 |
types[0] = "g_b_type_2"; |
| 150 |
types[1] = "g_m1_type_2"; |
| 151 |
types[2] = "g_m2_type_2"; |
| 152 |
role = test_role_type_set(base, "g_b_role_3", NULL, types, 3, 0); |
| 153 |
|
| 154 |
only_dominates_self(base, role); |
| 155 |
|
| 156 |
|
| 157 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_b"))->decl_id; |
| 158 |
decls[1] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 159 |
test_sym_presence(base, "o1_b_role_2", SYM_ROLES, SCOPE_DECL, decls, 2); |
| 160 |
|
| 161 |
types[0] = "g_m1_type_1"; |
| 162 |
role = test_role_type_set(base, "o1_b_role_2", NULL, types, 1, 0); |
| 163 |
types[0] = "o1_b_type_1"; |
| 164 |
role = test_role_type_set(base, "o1_b_role_2", test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_b"), types, 1, 0); |
| 165 |
|
| 166 |
only_dominates_self(base, role); |
| 167 |
|
| 168 |
|
| 169 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 170 |
decls[1] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o2_m1"))->decl_id; |
| 171 |
test_sym_presence(base, "g_b_role_4", SYM_ROLES, SCOPE_DECL, decls, 2); |
| 172 |
|
| 173 |
types[0] = "g_b_type_2"; |
| 174 |
role = test_role_type_set(base, "g_b_role_4", NULL, types, 1, 0); |
| 175 |
types[0] = "g_m1_type_2"; |
| 176 |
role = test_role_type_set(base, "g_b_role_4", test_find_decl_by_sym(base, SYM_TYPES, "tag_o2_m1"), types, 1, 0); |
| 177 |
|
| 178 |
only_dominates_self(base, role); |
| 179 |
|
| 180 |
|
| 181 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o3_b"))->decl_id; |
| 182 |
decls[1] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o3_m1"))->decl_id; |
| 183 |
test_sym_presence(base, "o3_b_role_1", SYM_ROLES, SCOPE_DECL, decls, 2); |
| 184 |
|
| 185 |
types[0] = "o3_b_type_1"; |
| 186 |
role = test_role_type_set(base, "o3_b_role_1", test_find_decl_by_sym(base, SYM_TYPES, "tag_o3_b"), types, 1, 0); |
| 187 |
types[0] = "o3_m1_type_1"; |
| 188 |
role = test_role_type_set(base, "o3_b_role_1", test_find_decl_by_sym(base, SYM_TYPES, "tag_o3_m1"), types, 1, 0); |
| 189 |
|
| 190 |
only_dominates_self(base, role); |
| 191 |
|
| 192 |
|
| 193 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o4_b"))->decl_id; |
| 194 |
decls[1] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 195 |
decls[2] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m2"))->decl_id; |
| 196 |
test_sym_presence(base, "o4_b_role_1", SYM_ROLES, SCOPE_DECL, decls, 3); |
| 197 |
|
| 198 |
types[0] = "g_m1_type_1"; |
| 199 |
role = test_role_type_set(base, "o4_b_role_1", test_find_decl_by_sym(base, SYM_TYPES, "tag_o4_b"), types, 1, 0); |
| 200 |
types[0] = "g_m2_type_1"; |
| 201 |
types[1] = "g_m1_type_2"; |
| 202 |
role = test_role_type_set(base, "o4_b_role_1", NULL, types, 2, 0); |
| 203 |
|
| 204 |
only_dominates_self(base, role); |
| 205 |
} |