static struct oscap_list *xccdf_benchmark_resolve_dependencies(void *itemptr, void *userdata) { struct xccdf_item *item = XITEM(itemptr); struct oscap_list *ret = oscap_list_new(); struct xccdf_value_iterator *val_it = NULL; const char *extends = xccdf_item_get_extends(item); if (extends) oscap_list_add(ret, xccdf_benchmark_get_member(xccdf_item_get_benchmark(item), xccdf_item_get_type(item), extends)); switch (xccdf_item_get_type(item)) { case XCCDF_BENCHMARK: { OSCAP_FOR(xccdf_profile, profile, xccdf_benchmark_get_profiles(xccdf_item_to_benchmark(item))) oscap_list_add(ret, profile); val_it = xccdf_benchmark_get_values(xccdf_item_to_benchmark(item)); break; } case XCCDF_GROUP: val_it = xccdf_group_get_values(xccdf_item_to_group(item)); default: break; /* no-op */ } OSCAP_FOR(xccdf_item, child, xccdf_item_get_content(item)) oscap_list_add(ret, child); OSCAP_FOR(xccdf_value, val, val_it) oscap_list_add(ret, val); return ret; }
static inline void _print_xccdf_benchmark(struct xccdf_benchmark *bench, const char *prefix) { _print_xccdf_status(xccdf_benchmark_get_status_current(bench), prefix); printf("%sResolved: %s\n", prefix, xccdf_benchmark_get_resolved(bench) ? "true" : "false"); _print_xccdf_profiles(xccdf_benchmark_get_profiles(bench), prefix); struct xccdf_policy_model *policy_model = xccdf_policy_model_new(bench); _print_xccdf_referenced_files(policy_model, prefix); _print_xccdf_testresults(bench, prefix); xccdf_policy_model_free(policy_model); // xccdf_benchmark_free not needed, it si already freed by the policy! }
xmlNewTextChild(root_node, ns_xccdf, BAD_CAST "version", BAD_CAST version); struct oscap_string_iterator* metadata = xccdf_item_get_metadata(XITEM(benchmark)); while (oscap_string_iterator_has_more(metadata)) { const char* meta = oscap_string_iterator_next(metadata); oscap_xmlstr_to_dom(root_node, "metadata", meta); } oscap_string_iterator_free(metadata); OSCAP_FOR(xccdf_model, model, xccdf_benchmark_get_models(benchmark)) { xmlNode *model_node = xmlNewTextChild(root_node, ns_xccdf, BAD_CAST "model", NULL); xmlNewProp(model_node, BAD_CAST "system", BAD_CAST xccdf_model_get_system(model)); } struct xccdf_profile_iterator *profiles = xccdf_benchmark_get_profiles(benchmark); while (xccdf_profile_iterator_has_more(profiles)) { struct xccdf_profile *profile = xccdf_profile_iterator_next(profiles); xccdf_item_to_dom(XITEM(profile), doc, root_node); } xccdf_profile_iterator_free(profiles); struct xccdf_value_iterator *values = xccdf_benchmark_get_values(benchmark); while (xccdf_value_iterator_has_more(values)) { struct xccdf_value *value = xccdf_value_iterator_next(values); xccdf_item_to_dom(XITEM(value), doc, root_node); } xccdf_value_iterator_free(values); struct xccdf_item_iterator *items = xccdf_benchmark_get_content(benchmark); while (xccdf_item_iterator_has_more(items)) {