| 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 |
#ifndef __COMMON_H__ |
| 23 |
#define __COMMON_H__ |
| 24 |
|
| 25 |
#include <sepol/policydb/policydb.h> |
| 26 |
#include <sepol/policydb/conditional.h> |
| 27 |
#include <CUnit/Basic.h> |
| 28 |
|
| 29 |
/* helper functions */ |
| 30 |
|
| 31 |
/* Override CU_*_FATAL() in order to help static analyzers by really asserting that an assertion holds */ |
| 32 |
#ifdef __CHECKER__ |
| 33 |
|
| 34 |
#include <assert.h> |
| 35 |
|
| 36 |
#undef CU_ASSERT_FATAL |
| 37 |
#define CU_ASSERT_FATAL(value) do { \ |
| 38 |
int _value = (value); \ |
| 39 |
CU_ASSERT(_value); \ |
| 40 |
assert(_value); \ |
| 41 |
} while (0) |
| 42 |
|
| 43 |
#undef CU_FAIL_FATAL |
| 44 |
#define CU_FAIL_FATAL(msg) do { \ |
| 45 |
CU_FAIL(msg); \ |
| 46 |
assert(0); \ |
| 47 |
} while (0) |
| 48 |
|
| 49 |
#undef CU_ASSERT_PTR_NOT_NULL_FATAL |
| 50 |
#define CU_ASSERT_PTR_NOT_NULL_FATAL(value) do { \ |
| 51 |
const void *_value = (value); \ |
| 52 |
CU_ASSERT_PTR_NOT_NULL(_value); \ |
| 53 |
assert(_value != NULL); \ |
| 54 |
} while (0) |
| 55 |
|
| 56 |
#endif /* __CHECKER__ */ |
| 57 |
|
| 58 |
|
| 59 |
/* Load a source policy into p. policydb_init will called within this function. |
| 60 |
* |
| 61 |
* Example: test_load_policy(p, POLICY_BASE, 1, "foo", "base.conf") will load the |
| 62 |
* policy "policies/foo/mls/base.conf" into p. |
| 63 |
* |
| 64 |
* Arguments: |
| 65 |
* p policydb_t into which the policy will be read. This should be |
| 66 |
* malloc'd but not passed to policydb_init. |
| 67 |
* policy_type Type of policy expected - POLICY_BASE or POLICY_MOD. |
| 68 |
* mls Boolean value indicating whether an mls policy is expected. |
| 69 |
* test_name Name of the test which will be the name of the directory in |
| 70 |
* which the policies are stored. |
| 71 |
* policy_name Name of the policy in the directory. |
| 72 |
* |
| 73 |
* Returns: |
| 74 |
* 0 success |
| 75 |
* -1 error - the policydb will be destroyed but not freed. |
| 76 |
*/ |
| 77 |
extern int test_load_policy(policydb_t * p, int policy_type, int mls, const char *test_name, const char *policy_name); |
| 78 |
|
| 79 |
/* Find an avrule_decl_t by a unique symbol. If the symbol is declared in more |
| 80 |
* than one decl an error is returned. |
| 81 |
* |
| 82 |
* Returns: |
| 83 |
* decl success |
| 84 |
* NULL error (including more than one declaration) |
| 85 |
*/ |
| 86 |
extern avrule_decl_t *test_find_decl_by_sym(policydb_t * p, int symtab, const char *sym); |
| 87 |
|
| 88 |
#endif |