static bool xccdf_item_parse_deps(xmlTextReaderPtr reader, struct xccdf_item *item) { struct oscap_list *conflicts = NULL; struct oscap_list *requires = NULL; xccdf_deps_get(item, &conflicts, &requires); switch (xccdf_element_get(reader)) { case XCCDFE_REQUIRES:{ struct oscap_list *reqs = oscap_list_new(); char *ids = xccdf_attribute_copy(reader, XCCDFA_IDREF), *idsstr = ids, *id; while ((id = strsep(&ids, " ")) != NULL) { if (strcmp(id, "") == 0) continue; oscap_list_add(reqs, oscap_strdup(id)); } if (reqs->itemcount == 0) { oscap_list_free(reqs, NULL); return false; } oscap_list_add(requires, reqs); free(idsstr); break; } case XCCDFE_CONFLICTS: oscap_list_add(conflicts, xccdf_attribute_copy(reader, XCCDFA_IDREF)); break; default: assert(false); } return true; }
struct xccdf_fix *xccdf_fix_parse(xmlTextReaderPtr reader) { struct xccdf_fix *fix = xccdf_fix_new(); fix->id = xccdf_attribute_copy(reader, XCCDFA_ID); fix->system = xccdf_attribute_copy(reader, XCCDFA_SYSTEM); fix->platform = xccdf_attribute_copy(reader, XCCDFA_PLATFORM); fix->reboot = xccdf_attribute_get_bool(reader, XCCDFA_REBOOT); fix->strategy = oscap_string_to_enum(XCCDF_STRATEGY_MAP, xccdf_attribute_get(reader, XCCDFA_STRATEGY)); fix->disruption = oscap_string_to_enum(XCCDF_LEVEL_MAP, xccdf_attribute_get(reader, XCCDFA_DISRUPTION)); fix->complexity = oscap_string_to_enum(XCCDF_LEVEL_MAP, xccdf_attribute_get(reader, XCCDFA_COMPLEXITY)); fix->content = oscap_get_xml(reader); return fix; }
struct xccdf_fixtext *xccdf_fixtext_parse(xmlTextReaderPtr reader) { struct xccdf_fixtext *fix = xccdf_fixtext_new(); fix->fixref = xccdf_attribute_copy(reader, XCCDFA_FIXREF); fix->text = oscap_text_new_parse(XCCDF_TEXT_HTMLSUB, reader); fix->reboot = xccdf_attribute_get_bool(reader, XCCDFA_REBOOT); fix->strategy = oscap_string_to_enum(XCCDF_STRATEGY_MAP, xccdf_attribute_get(reader, XCCDFA_STRATEGY)); fix->disruption = oscap_string_to_enum(XCCDF_LEVEL_MAP, xccdf_attribute_get(reader, XCCDFA_DISRUPTION)); fix->complexity = oscap_string_to_enum(XCCDF_LEVEL_MAP, xccdf_attribute_get(reader, XCCDFA_COMPLEXITY)); return fix; }
struct xccdf_check *xccdf_check_parse(xmlTextReaderPtr reader) { xccdf_element_t el = xccdf_element_get(reader); if (el != XCCDFE_CHECK && el != XCCDFE_COMPLEX_CHECK) return NULL; struct xccdf_check *check = xccdf_check_new(); check->id = xccdf_attribute_copy(reader, XCCDFA_ID); check->system = xccdf_attribute_copy(reader, XCCDFA_SYSTEM); check->selector = xccdf_attribute_copy(reader, XCCDFA_SELECTOR); check->oper = oscap_string_to_enum(XCCDF_BOOLOP_MAP, xccdf_attribute_get(reader, XCCDFA_OPERATOR)); if (xccdf_attribute_has(reader, XCCDFA_MULTICHECK) && el != XCCDFE_COMPLEX_CHECK) { check->flags.def_multicheck = true; check->flags.multicheck = xccdf_attribute_get_bool(reader, XCCDFA_MULTICHECK); } check->flags.def_negate = xccdf_attribute_has(reader, XCCDFA_NEGATE); check->flags.negate = xccdf_attribute_get_bool(reader, XCCDFA_NEGATE); int depth = oscap_element_depth(reader) + 1; while (oscap_to_start_element(reader, depth)) { switch (xccdf_element_get(reader)) { case XCCDFE_CHECK: case XCCDFE_COMPLEX_CHECK: if (check->oper == 0) break; oscap_list_add(check->children, xccdf_check_parse(reader)); break; case XCCDFE_CHECK_CONTENT_REF:{ const char *href = xccdf_attribute_get(reader, XCCDFA_HREF); if (href == NULL) break; struct xccdf_check_content_ref *ref = xccdf_check_content_ref_new(); ref->name = xccdf_attribute_copy(reader, XCCDFA_NAME); ref->href = strdup(href); oscap_list_add(check->content_refs, ref); break; } case XCCDFE_CHECK_CONTENT: if (check->content == NULL) check->content = oscap_get_xml(reader); break; case XCCDFE_CHECK_IMPORT:{ const char *name = xccdf_attribute_get(reader, XCCDFA_IMPORT_NAME); const char *xpath = xccdf_attribute_get(reader, XCCDFA_IMPORT_XPATH); if (name == NULL) // @import-name is a required attribute break; struct xccdf_check_import *imp = xccdf_check_import_new(); imp->name = strdup(name); if (xpath) // @import-xpath is just optional imp->xpath = strdup(xpath); imp->content = oscap_element_string_copy(reader); oscap_list_add(check->imports, imp); break; } case XCCDFE_CHECK_EXPORT:{ const char *name = xccdf_attribute_get(reader, XCCDFA_EXPORT_NAME); if (name == NULL) break; struct xccdf_check_export *exp = xccdf_check_export_new(); exp->name = strdup(name); exp->value = xccdf_attribute_copy(reader, XCCDFA_VALUE_ID); oscap_list_add(check->exports, exp); break; } default: break; } xmlTextReaderRead(reader); } return check; }
bool xccdf_benchmark_parse(struct xccdf_item * benchmark, xmlTextReaderPtr reader) { XCCDF_ASSERT_ELEMENT(reader, XCCDFE_BENCHMARK); assert(benchmark != NULL); if (benchmark->type != XCCDF_BENCHMARK) return false; xccdf_benchmark_set_schema_version(XBENCHMARK(benchmark), xccdf_detect_version_parser(reader)); if (!xccdf_item_process_attributes(benchmark, reader)) { xccdf_benchmark_free(XBENCHMARK(benchmark)); return false; } benchmark->sub.benchmark.style = xccdf_attribute_copy(reader, XCCDFA_STYLE); benchmark->sub.benchmark.style_href = xccdf_attribute_copy(reader, XCCDFA_STYLE_HREF); benchmark->sub.benchmark.lang = (char *) xmlTextReaderXmlLang(reader); if (xccdf_attribute_has(reader, XCCDFA_RESOLVED)) benchmark->item.flags.resolved = xccdf_attribute_get_bool(reader, XCCDFA_RESOLVED); int depth = oscap_element_depth(reader) + 1; while (oscap_to_start_element(reader, depth)) { struct xccdf_model *parsed_model; switch (xccdf_element_get(reader)) { case XCCDFE_NOTICE: oscap_list_add(benchmark->sub.benchmark.notices, xccdf_notice_new_parse(reader)); break; case XCCDFE_FRONT_MATTER: oscap_list_add(benchmark->sub.benchmark.front_matter, oscap_text_new_parse(XCCDF_TEXT_HTMLSUB, reader)); break; case XCCDFE_REAR_MATTER: oscap_list_add(benchmark->sub.benchmark.rear_matter, oscap_text_new_parse(XCCDF_TEXT_HTMLSUB, reader)); break; case XCCDFE_PLATFORM: oscap_list_add(benchmark->item.platforms, xccdf_attribute_copy(reader, XCCDFA_IDREF)); break; case XCCDFE_MODEL: parsed_model = xccdf_model_new_xml(reader); // we won't add the implied default scoring model, it is already in the benchmark if (strcmp(xccdf_model_get_system(parsed_model), "urn:xccdf:scoring:default") != 0) assume_ex(xccdf_benchmark_add_model(XBENCHMARK(benchmark), parsed_model), false); else xccdf_model_free(parsed_model); break; case XCCDFE_PLAIN_TEXT:{ const char *id = xccdf_attribute_get(reader, XCCDFA_ID); const char *data = oscap_element_string_get(reader); if (id) oscap_list_add(benchmark->sub.benchmark.plain_texts, xccdf_plain_text_new_fill(id, data == NULL ? "" : data)); break; } case XCCDFE_CPE_LIST:{ struct cpe_parser_ctx *ctx = cpe_parser_ctx_from_reader(reader); xccdf_benchmark_set_cpe_list(XBENCHMARK(benchmark), cpe_dict_model_parse(ctx)); cpe_parser_ctx_free(ctx); break; } case XCCDFE_CPE2_PLATFORMSPEC: xccdf_benchmark_set_cpe_lang_model(XBENCHMARK(benchmark), cpe_lang_model_parse(reader)); break; case XCCDFE_PROFILE: oscap_list_add(benchmark->sub.benchmark.profiles, xccdf_profile_parse(reader, benchmark)); break; case XCCDFE_GROUP: case XCCDFE_RULE: xccdf_content_parse(reader, benchmark); break; case XCCDFE_VALUE: oscap_list_add(benchmark->sub.benchmark.values, xccdf_value_parse(reader, benchmark)); break; case XCCDFE_TESTRESULT: assume_ex(xccdf_benchmark_add_result(XBENCHMARK(benchmark), xccdf_result_new_parse(reader)), false); break; default: if (!xccdf_item_process_element(benchmark, reader)) dW("Encountered an unknown element '%s' while parsing XCCDF benchmark.", xmlTextReaderConstLocalName(reader)); } xmlTextReaderRead(reader); } return true; }