Debian Codegraph @

src/XCCDF_POLICY/xccdf_policy_engine.c

raw symbols SCIP
1 /*
2 * Copyright 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 * Šimon Lukašík
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "common/util.h"
28 #include "common/list.h"
29 #include "common/_error.h"
30 #include "public/xccdf_policy.h"
31 #include "xccdf_policy_engine_priv.h"
32
33 struct xccdf_policy_engine {
34 char *system; ///< Identificator of checking engine
35 xccdf_policy_engine_eval_fn callback; ///< format of callback function
36 void * usr; ///< User data structure
37 xccdf_policy_engine_query_fn query_fn; ///< query callback function
38 };
39
40 struct xccdf_policy_engine *xccdf_policy_engine_new(char *sys, xccdf_policy_engine_eval_fn eval_fn, void *usr, xccdf_policy_engine_query_fn query_fn)
41 {
42 struct xccdf_policy_engine *engine = malloc(sizeof(struct xccdf_policy_engine));
43 if (engine != NULL) {
44 engine->system = sys;
45 engine->callback = eval_fn;
46 engine->usr = usr;
47 engine->query_fn = query_fn;
48 }
49 return engine;
50 }
51
52 bool xccdf_policy_engine_filter(struct xccdf_policy_engine *engine, const char *sysname)
53 {
54 return oscap_strcmp(engine->system, sysname) == 0;
55 }
56
57 xccdf_test_result_type_t xccdf_policy_engine_eval(struct xccdf_policy_engine *engine, struct xccdf_policy *policy, const char *definition_id, const char *href_id, struct oscap_list *value_bindings, struct xccdf_check_import_iterator *check_import_it)
58 {
59 xccdf_test_result_type_t ret = XCCDF_RESULT_NOT_CHECKED;
60 if (engine == NULL) {
61 oscap_seterr(OSCAP_EFAMILY_XCCDF, "Unknown callback for given checking system. Set callback first");
62 }
63 else {
64 struct xccdf_value_binding_iterator * binding_it = (struct xccdf_value_binding_iterator *) oscap_iterator_new(value_bindings);
65 ret = engine->callback(policy, NULL, definition_id, href_id, binding_it, check_import_it, engine->usr);
66 if (binding_it != NULL)
67 xccdf_value_binding_iterator_free(binding_it);
68 }
69 return ret;
70 }
71
72 struct oscap_list *xccdf_policy_engine_query(struct xccdf_policy_engine *engine, xccdf_policy_engine_query_t query_type, void *query_data)
73 {
74 if (engine->query_fn == NULL)
75 return NULL;
76 return (struct oscap_list *) engine->query_fn(engine->usr, query_type, query_data);
77 }