16cd6a6acSopenharmony_ci/*
26cd6a6acSopenharmony_ci * Author: Joshua Brindle <jbrindle@tresys.com>
36cd6a6acSopenharmony_ci *         Chad Sellers <csellers@tresys.com>
46cd6a6acSopenharmony_ci *
56cd6a6acSopenharmony_ci * Copyright (C) 2006 Tresys Technology, LLC
66cd6a6acSopenharmony_ci *
76cd6a6acSopenharmony_ci *  This library is free software; you can redistribute it and/or
86cd6a6acSopenharmony_ci *  modify it under the terms of the GNU Lesser General Public
96cd6a6acSopenharmony_ci *  License as published by the Free Software Foundation; either
106cd6a6acSopenharmony_ci *  version 2.1 of the License, or (at your option) any later version.
116cd6a6acSopenharmony_ci *
126cd6a6acSopenharmony_ci *  This library is distributed in the hope that it will be useful,
136cd6a6acSopenharmony_ci *  but WITHOUT ANY WARRANTY; without even the implied warranty of
146cd6a6acSopenharmony_ci *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
156cd6a6acSopenharmony_ci *  Lesser General Public License for more details.
166cd6a6acSopenharmony_ci *
176cd6a6acSopenharmony_ci *  You should have received a copy of the GNU Lesser General Public
186cd6a6acSopenharmony_ci *  License along with this library; if not, write to the Free Software
196cd6a6acSopenharmony_ci *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
206cd6a6acSopenharmony_ci */
216cd6a6acSopenharmony_ci
226cd6a6acSopenharmony_ci#ifndef __COMMON_H__
236cd6a6acSopenharmony_ci#define __COMMON_H__
246cd6a6acSopenharmony_ci
256cd6a6acSopenharmony_ci#include <sepol/policydb/policydb.h>
266cd6a6acSopenharmony_ci#include <sepol/policydb/conditional.h>
276cd6a6acSopenharmony_ci#include <CUnit/Basic.h>
286cd6a6acSopenharmony_ci
296cd6a6acSopenharmony_ci/* helper functions */
306cd6a6acSopenharmony_ci
316cd6a6acSopenharmony_ci/* Override CU_*_FATAL() in order to help static analyzers by really asserting that an assertion holds */
326cd6a6acSopenharmony_ci#ifdef __CHECKER__
336cd6a6acSopenharmony_ci
346cd6a6acSopenharmony_ci#include <assert.h>
356cd6a6acSopenharmony_ci
366cd6a6acSopenharmony_ci#undef CU_ASSERT_FATAL
376cd6a6acSopenharmony_ci#define CU_ASSERT_FATAL(value) do { \
386cd6a6acSopenharmony_ci		int _value = (value); \
396cd6a6acSopenharmony_ci		CU_ASSERT(_value); \
406cd6a6acSopenharmony_ci		assert(_value); \
416cd6a6acSopenharmony_ci	} while (0)
426cd6a6acSopenharmony_ci
436cd6a6acSopenharmony_ci#undef CU_FAIL_FATAL
446cd6a6acSopenharmony_ci#define CU_FAIL_FATAL(msg) do { \
456cd6a6acSopenharmony_ci		CU_FAIL(msg); \
466cd6a6acSopenharmony_ci		assert(0); \
476cd6a6acSopenharmony_ci	} while (0)
486cd6a6acSopenharmony_ci
496cd6a6acSopenharmony_ci#undef CU_ASSERT_PTR_NOT_NULL_FATAL
506cd6a6acSopenharmony_ci#define CU_ASSERT_PTR_NOT_NULL_FATAL(value) do { \
516cd6a6acSopenharmony_ci		const void *_value = (value); \
526cd6a6acSopenharmony_ci		CU_ASSERT_PTR_NOT_NULL(_value); \
536cd6a6acSopenharmony_ci		assert(_value != NULL); \
546cd6a6acSopenharmony_ci	} while (0)
556cd6a6acSopenharmony_ci
566cd6a6acSopenharmony_ci#endif /* __CHECKER__ */
576cd6a6acSopenharmony_ci
586cd6a6acSopenharmony_ci
596cd6a6acSopenharmony_ci/* Load a source policy into p. policydb_init will called within this function.
606cd6a6acSopenharmony_ci *
616cd6a6acSopenharmony_ci * Example: test_load_policy(p, POLICY_BASE, 1, "foo", "base.conf") will load the
626cd6a6acSopenharmony_ci *  policy "policies/foo/mls/base.conf" into p.
636cd6a6acSopenharmony_ci *
646cd6a6acSopenharmony_ci * Arguments:
656cd6a6acSopenharmony_ci *  p            policydb_t into which the policy will be read. This should be
666cd6a6acSopenharmony_ci *                malloc'd but not passed to policydb_init.
676cd6a6acSopenharmony_ci *  policy_type  Type of policy expected - POLICY_BASE or POLICY_MOD.
686cd6a6acSopenharmony_ci *  mls          Boolean value indicating whether an mls policy is expected.
696cd6a6acSopenharmony_ci *  test_name    Name of the test which will be the name of the directory in
706cd6a6acSopenharmony_ci *                which the policies are stored.
716cd6a6acSopenharmony_ci *  policy_name  Name of the policy in the directory.
726cd6a6acSopenharmony_ci *
736cd6a6acSopenharmony_ci * Returns:
746cd6a6acSopenharmony_ci *  0            success
756cd6a6acSopenharmony_ci * -1            error - the policydb will be destroyed but not freed.
766cd6a6acSopenharmony_ci */
776cd6a6acSopenharmony_ciextern int test_load_policy(policydb_t * p, int policy_type, int mls, const char *test_name, const char *policy_name);
786cd6a6acSopenharmony_ci
796cd6a6acSopenharmony_ci/* Find an avrule_decl_t by a unique symbol. If the symbol is declared in more
806cd6a6acSopenharmony_ci * than one decl an error is returned.
816cd6a6acSopenharmony_ci *
826cd6a6acSopenharmony_ci * Returns:
836cd6a6acSopenharmony_ci *  decl      success
846cd6a6acSopenharmony_ci *  NULL      error (including more than one declaration)
856cd6a6acSopenharmony_ci */
866cd6a6acSopenharmony_ciextern avrule_decl_t *test_find_decl_by_sym(policydb_t * p, int symtab, const char *sym);
876cd6a6acSopenharmony_ci
886cd6a6acSopenharmony_ci#endif
89