| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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 |
|