struct cvss_metrics *cvss_metrics_new_from_xml(xmlTextReaderPtr reader) { assert(reader != NULL); int depth = oscap_element_depth(reader); enum cvss_category cat = CVSS_NONE; const char *elname = (const char *) xmlTextReaderConstLocalName(reader); if (oscap_streq(elname, "base_metrics")) cat = CVSS_BASE; if (oscap_streq(elname, "temporal_metrics")) cat = CVSS_TEMPORAL; if (oscap_streq(elname, "environmental_metrics")) cat = CVSS_ENVIRONMENTAL; if (cat == CVSS_NONE) return NULL; struct cvss_metrics *ret = cvss_metrics_new(cat); ret->upgraded_from_version = (char*) xmlTextReaderGetAttribute(reader, BAD_CAST "upgraded-from-version"); xmlTextReaderRead(reader); while (oscap_to_start_element(reader, depth + 1)) { elname = (const char *) xmlTextReaderConstLocalName(reader); if (oscap_streq(elname, "score")) ret->score = atof(oscap_element_string_get(reader)); else if (oscap_streq(elname, "source")) cvss_metrics_set_source(ret, oscap_element_string_get(reader)); else if (oscap_streq(elname, "generated-on-datetime")) cvss_metrics_set_generated_on_datetime(ret, oscap_element_string_get(reader)); else { const struct cvss_valtab_entry *val = cvss_valtab(cvss_keytab(0, elname)->key, 0, NULL, oscap_element_string_get(reader)); if (CVSS_CATEGORY(val->key) == cat) ret->metrics.ANY[CVSS_KEY_IDX(val->key)] = val->value; } xmlTextReaderRead(reader); } return ret; }
struct xccdf_ident *xccdf_ident_parse(xmlTextReaderPtr reader) { XCCDF_ASSERT_ELEMENT(reader, XCCDFE_IDENT); const char *sys = xccdf_attribute_get(reader, XCCDFA_SYSTEM); const char *id = oscap_element_string_get(reader); return xccdf_ident_new_fill(id, sys); }
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; }