| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "helpers.h" |
| 25 |
#include "parse_util.h" |
| 26 |
|
| 27 |
#include <sepol/policydb/expand.h> |
| 28 |
#include <sepol/policydb/avrule_block.h> |
| 29 |
|
| 30 |
#include <CUnit/Basic.h> |
| 31 |
|
| 32 |
#include <stdlib.h> |
| 33 |
#include <limits.h> |
| 34 |
|
| 35 |
int test_load_policy(policydb_t * p, int policy_type, int mls, const char *test_name, const char *policy_name) |
| 36 |
{ |
| 37 |
char filename[PATH_MAX]; |
| 38 |
|
| 39 |
if (mls) { |
| 40 |
if (snprintf(filename, PATH_MAX, "policies/%s/%s.mls", test_name, policy_name) < 0) { |
| 41 |
return -1; |
| 42 |
} |
| 43 |
} else { |
| 44 |
if (snprintf(filename, PATH_MAX, "policies/%s/%s.std", test_name, policy_name) < 0) { |
| 45 |
return -1; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
if (policydb_init(p)) { |
| 50 |
fprintf(stderr, "Out of memory"); |
| 51 |
return -1; |
| 52 |
} |
| 53 |
|
| 54 |
p->policy_type = policy_type; |
| 55 |
p->mls = mls; |
| 56 |
|
| 57 |
if (read_source_policy(p, filename, test_name)) { |
| 58 |
fprintf(stderr, "failed to read policy %s\n", filename); |
| 59 |
policydb_destroy(p); |
| 60 |
return -1; |
| 61 |
} |
| 62 |
|
| 63 |
return 0; |
| 64 |
} |
| 65 |
|
| 66 |
avrule_decl_t *test_find_decl_by_sym(policydb_t * p, int symtab, const char *sym) |
| 67 |
{ |
| 68 |
scope_datum_t *scope = (scope_datum_t *) hashtab_search(p->scope[symtab].table, sym); |
| 69 |
|
| 70 |
if (scope == NULL) { |
| 71 |
return NULL; |
| 72 |
} |
| 73 |
if (scope->scope != SCOPE_DECL) { |
| 74 |
return NULL; |
| 75 |
} |
| 76 |
if (scope->decl_ids_len != 1) { |
| 77 |
return NULL; |
| 78 |
} |
| 79 |
|
| 80 |
return p->decl_val_to_struct[scope->decl_ids[0] - 1]; |
| 81 |
} |