| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "parse_util.h" |
| 23 |
#include "helpers.h" |
| 24 |
#include "test-common.h" |
| 25 |
|
| 26 |
#include <sepol/policydb/policydb.h> |
| 27 |
#include <sepol/policydb/link.h> |
| 28 |
|
| 29 |
#include <CUnit/Basic.h> |
| 30 |
#include <stdlib.h> |
| 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 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
static void test_type_datum(policydb_t * p, const char *id, unsigned int *decls, int len, unsigned int primary) |
| 101 |
{ |
| 102 |
int i; |
| 103 |
unsigned int value; |
| 104 |
type_datum_t *type; |
| 105 |
|
| 106 |
|
| 107 |
type = hashtab_search(p->p_types.table, id); |
| 108 |
|
| 109 |
CU_ASSERT_FATAL(type != NULL); |
| 110 |
CU_ASSERT(type->primary == primary); |
| 111 |
CU_ASSERT(type->flavor == TYPE_TYPE); |
| 112 |
|
| 113 |
value = type->s.value; |
| 114 |
|
| 115 |
for (i = 0; i < len; i++) { |
| 116 |
type = hashtab_search(p->decl_val_to_struct[decls[i] - 1]->p_types.table, id); |
| 117 |
CU_ASSERT_FATAL(type != NULL); |
| 118 |
CU_ASSERT(type->primary == primary); |
| 119 |
CU_ASSERT(type->flavor == TYPE_TYPE); |
| 120 |
CU_ASSERT(type->s.value == value); |
| 121 |
} |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
void base_type_tests(policydb_t * base) |
| 126 |
{ |
| 127 |
unsigned int decls[2]; |
| 128 |
const char *types[2]; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 137 |
test_sym_presence(base, "g_b_type_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 138 |
test_type_datum(base, "g_b_type_1", NULL, 0, 1); |
| 139 |
|
| 140 |
test_sym_presence(base, "g_b_attr_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 141 |
types[0] = "g_b_type_1"; |
| 142 |
test_attr_types(base, "g_b_attr_1", NULL, types, 1); |
| 143 |
|
| 144 |
|
| 145 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_b"))->decl_id; |
| 146 |
test_sym_presence(base, "o1_b_type_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 147 |
test_type_datum(base, "o1_b_type_1", NULL, 0, 1); |
| 148 |
|
| 149 |
test_sym_presence(base, "o1_b_attr_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 150 |
types[0] = "o1_b_type_1"; |
| 151 |
test_attr_types(base, "o1_b_attr_1", base->decl_val_to_struct[decls[0] - 1], types, 1); |
| 152 |
|
| 153 |
|
| 154 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 155 |
test_sym_presence(base, "g_b_alias_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 156 |
test_alias_datum(base, "g_b_alias_1", "g_b_type_3", 1, 0); |
| 157 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o6_b"))->decl_id; |
| 158 |
test_sym_presence(base, "g_b_alias_2", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 159 |
test_alias_datum(base, "g_b_alias_2", "g_b_type_3", 1, 0); |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
void module_type_tests(policydb_t * base) |
| 164 |
{ |
| 165 |
unsigned int decls[2]; |
| 166 |
const char *types[2]; |
| 167 |
avrule_decl_t *d; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 181 |
test_sym_presence(base, "g_m1_type_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 182 |
test_type_datum(base, "g_m1_type_1", NULL, 0, 1); |
| 183 |
|
| 184 |
test_sym_presence(base, "g_m1_attr_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 185 |
types[0] = "g_m1_type_1"; |
| 186 |
types[1] = "g_m1_type_2"; |
| 187 |
test_attr_types(base, "g_m1_attr_1", NULL, types, 2); |
| 188 |
|
| 189 |
|
| 190 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_m1"))->decl_id; |
| 191 |
test_sym_presence(base, "o1_m1_type_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 192 |
test_type_datum(base, "o1_m1_type_1", NULL, 0, 1); |
| 193 |
|
| 194 |
test_sym_presence(base, "o1_m1_attr_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 195 |
types[0] = "o1_m1_type_2"; |
| 196 |
test_attr_types(base, "o1_m1_attr_1", base->decl_val_to_struct[decls[0] - 1], types, 1); |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 201 |
test_sym_presence(base, "g_b_attr_3", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 202 |
types[0] = "g_m1_type_3"; |
| 203 |
test_attr_types(base, "g_b_attr_3", NULL, types, 1); |
| 204 |
|
| 205 |
|
| 206 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 207 |
test_sym_presence(base, "g_b_attr_4", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 208 |
|
| 209 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_m1"))->decl_id; |
| 210 |
types[0] = "o1_m1_type_3"; |
| 211 |
test_attr_types(base, "g_b_attr_4", base->decl_val_to_struct[decls[0] - 1], types, 1); |
| 212 |
|
| 213 |
|
| 214 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 215 |
test_sym_presence(base, "g_b_attr_5", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 216 |
types[0] = "g_m1_type_4"; |
| 217 |
types[1] = "g_m2_type_4"; |
| 218 |
test_attr_types(base, "g_b_attr_5", NULL, types, 2); |
| 219 |
|
| 220 |
|
| 221 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_b"))->decl_id; |
| 222 |
test_sym_presence(base, "g_b_attr_6", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 223 |
|
| 224 |
types[0] = "g_m2_type_5"; |
| 225 |
test_attr_types(base, "g_b_attr_6", NULL, types, 1); |
| 226 |
d = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o3_m1")); |
| 227 |
types[0] = "o3_m1_type_2"; |
| 228 |
test_attr_types(base, "g_b_attr_6", d, types, 1); |
| 229 |
|
| 230 |
|
| 231 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o4_b"))->decl_id; |
| 232 |
test_sym_presence(base, "o4_b_attr_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 233 |
types[0] = "g_m1_type_5"; |
| 234 |
test_attr_types(base, "o4_b_attr_1", NULL, types, 1); |
| 235 |
|
| 236 |
|
| 237 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_b"))->decl_id; |
| 238 |
test_sym_presence(base, "o1_b_attr_2", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 239 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_m1"); |
| 240 |
types[0] = "o1_m1_type_5"; |
| 241 |
test_attr_types(base, "o1_b_attr_2", d, types, 1); |
| 242 |
|
| 243 |
|
| 244 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 245 |
test_sym_presence(base, "g_m1_attr_2", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 246 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o1_b"); |
| 247 |
types[0] = "o1_b_type_2"; |
| 248 |
test_attr_types(base, "g_m1_attr_2", d, types, 1); |
| 249 |
|
| 250 |
|
| 251 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_o3_m1"))->decl_id; |
| 252 |
test_sym_presence(base, "o3_m1_attr_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 253 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o4_b"); |
| 254 |
types[0] = "o4_b_type_1"; |
| 255 |
test_attr_types(base, "o3_m1_attr_1", d, types, 1); |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 260 |
test_sym_presence(base, "g_m1_attr_3", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 261 |
types[0] = "g_m1_type_6"; |
| 262 |
types[1] = "g_m2_type_3"; |
| 263 |
test_attr_types(base, "g_m1_attr_3", NULL, types, 2); |
| 264 |
|
| 265 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o4_b"); |
| 266 |
types[0] = "o4_b_type_2"; |
| 267 |
test_attr_types(base, "g_m1_attr_3", d, types, 1); |
| 268 |
|
| 269 |
|
| 270 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o3_m1"); |
| 271 |
decls[0] = d->decl_id; |
| 272 |
test_sym_presence(base, "o3_m1_attr_2", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 273 |
types[0] = "o3_m1_type_3"; |
| 274 |
test_attr_types(base, "o3_m1_attr_2", d, types, 1); |
| 275 |
|
| 276 |
types[0] = "g_m2_type_6"; |
| 277 |
test_attr_types(base, "o3_m1_attr_2", NULL, types, 1); |
| 278 |
|
| 279 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o2_b"); |
| 280 |
types[0] = "o2_b_type_1"; |
| 281 |
test_attr_types(base, "o3_m1_attr_2", d, types, 1); |
| 282 |
|
| 283 |
|
| 284 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 285 |
test_sym_presence(base, "g_m1_attr_4", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 286 |
types[0] = "g_m1_type_7"; |
| 287 |
test_attr_types(base, "g_m1_attr_4", NULL, types, 1); |
| 288 |
|
| 289 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o2_m2"); |
| 290 |
types[0] = "o2_m2_type_1"; |
| 291 |
test_attr_types(base, "g_m1_attr_4", d, types, 1); |
| 292 |
|
| 293 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o5_b"); |
| 294 |
types[0] = "o5_b_type_1"; |
| 295 |
test_attr_types(base, "g_m1_attr_4", d, types, 1); |
| 296 |
|
| 297 |
|
| 298 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o4_m1"); |
| 299 |
decls[0] = d->decl_id; |
| 300 |
test_sym_presence(base, "o4_m1_attr_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 301 |
types[0] = "o4_m1_type_1"; |
| 302 |
test_attr_types(base, "o4_m1_attr_1", d, types, 1); |
| 303 |
|
| 304 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o2_m2"); |
| 305 |
types[0] = "o2_m2_type_2"; |
| 306 |
test_attr_types(base, "o4_m1_attr_1", d, types, 1); |
| 307 |
|
| 308 |
d = test_find_decl_by_sym(base, SYM_TYPES, "tag_o5_b"); |
| 309 |
types[0] = "o5_b_type_2"; |
| 310 |
test_attr_types(base, "o4_m1_attr_1", d, types, 1); |
| 311 |
|
| 312 |
|
| 313 |
decls[0] = (test_find_decl_by_sym(base, SYM_TYPES, "tag_g_m1"))->decl_id; |
| 314 |
test_sym_presence(base, "g_m_alias_1", SYM_TYPES, SCOPE_DECL, decls, 1); |
| 315 |
test_alias_datum(base, "g_m_alias_1", "g_b_type_3", 1, 0); |
| 316 |
|
| 317 |
} |