Debian Codegraph @

tests/API/XCCDF/unittests/unit_helper.c

raw symbols SCIP
1 /*
2 * Copyright 2012--2014 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * Simon Lukasik <[email protected]>
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "unit_helper.h"
28 #include <xccdf_benchmark.h>
29 #include <oval_agent_xccdf_api.h>
30 #include <oscap_source.h>
31
32 static xccdf_test_result_type_t _always_pass_eval_rule(struct xccdf_policy *, const char *, const char *, const char *, struct xccdf_value_binding_iterator *, struct xccdf_check_import_iterator *, void *);
33 static xccdf_test_result_type_t _always_fail_eval_rule(struct xccdf_policy *, const char *, const char *, const char *, struct xccdf_value_binding_iterator *, struct xccdf_check_import_iterator *, void *);
34
35
36
37 void
38 uh_register_simple_engines(struct xccdf_policy_model * model)
39 {
40 xccdf_policy_model_register_engine_and_query_callback(model, "http://check-engine.test/pass", _always_pass_eval_rule, (void*)NULL, NULL);
41 xccdf_policy_model_register_engine_and_query_callback(model, "http://check-engine.test/fail", _always_fail_eval_rule, (void*)NULL, NULL);
42 }
43
44 struct xccdf_policy_model *
45 uh_load_xccdf(const char *filename)
46 {
47 struct xccdf_benchmark *bench = NULL;
48 struct oscap_source *source = oscap_source_new_from_file(filename);
49 if ((bench = xccdf_benchmark_import_source(source))== NULL)
50 fprintf(stderr, "Failed to import the XCCDF content from (%s).\n", filename);
51 oscap_source_free(source);
52 return xccdf_policy_model_new(bench);
53 }
54
55 struct xccdf_policy *
56 uh_get_default_policy(struct xccdf_policy_model *policy_model)
57 {
58 struct xccdf_policy *policy = xccdf_policy_model_get_policy_by_id(policy_model, NULL);
59 if (policy == NULL)
60 fprintf(stderr, "No Policy to evaluate.\n");
61 return policy;
62 }
63
64
65
66 xccdf_test_result_type_t
67 _always_pass_eval_rule(struct xccdf_policy *policy, const char *rule_id, const char *id,
68 const char *href, struct xccdf_value_binding_iterator *value_binding_it,
69 struct xccdf_check_import_iterator *check_import_it, void *usr)
70 {
71 return XCCDF_RESULT_PASS;
72 }
73
74 xccdf_test_result_type_t
75 _always_fail_eval_rule( struct xccdf_policy *policy, const char *rule_id, const char *id,
76 const char *href, struct xccdf_value_binding_iterator *value_binding_it,
77 struct xccdf_check_import_iterator *check_import_it, void *usr)
78 {
79 return XCCDF_RESULT_FAIL;
80 }
81