| 1 |
/* |
| 2 |
* Author: Joshua Brindle <[email protected]> |
| 3 |
* Chad Sellers <[email protected]> |
| 4 |
* |
| 5 |
* Copyright (C) 2006 Tresys Technology, LLC |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/* This has helper functions that are common between tests */ |
| 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 |
p->policyvers = MOD_POLICYDB_VERSION_MAX; |
| 57 |
|
| 58 |
if (read_source_policy(p, filename, test_name)) { |
| 59 |
fprintf(stderr, "failed to read policy %s\n", filename); |
| 60 |
policydb_destroy(p); |
| 61 |
return -1; |
| 62 |
} |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |
| 66 |
|
| 67 |
avrule_decl_t *test_find_decl_by_sym(policydb_t * p, int symtab, const char *sym) |
| 68 |
{ |
| 69 |
scope_datum_t *scope = (scope_datum_t *) hashtab_search(p->scope[symtab].table, sym); |
| 70 |
|
| 71 |
if (scope == NULL) { |
| 72 |
return NULL; |
| 73 |
} |
| 74 |
if (scope->scope != SCOPE_DECL) { |
| 75 |
return NULL; |
| 76 |
} |
| 77 |
if (scope->decl_ids_len != 1) { |
| 78 |
return NULL; |
| 79 |
} |
| 80 |
|
| 81 |
return p->decl_val_to_struct[scope->decl_ids[0] - 1]; |
| 82 |
} |