struct oscap_source *xccdf_benchmark_export_source(struct xccdf_benchmark *benchmark, const char *filename) { xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); if (doc == NULL) { oscap_setxmlerr(xmlGetLastError()); return NULL; } xccdf_benchmark_to_dom(benchmark, doc, NULL, NULL); return oscap_source_new_from_xmlDoc(doc, filename); }
static int ds_sds_register_xmlDoc(struct ds_sds_session *session, xmlDoc* doc, xmlNodePtr component_inner_root, const char *relative_filepath) { xmlDoc *new_doc = ds_doc_from_foreign_node(component_inner_root, doc); if (new_doc == NULL) { return -1; } struct oscap_source *component_source = oscap_source_new_from_xmlDoc(new_doc, relative_filepath); ds_sds_session_register_component_source(session, relative_filepath, component_source); return 0; // TODO: Return value of ds_sds_session_register_component_source(). (commit message) }
struct oscap_source *ds_rds_create_source(struct oscap_source *sds_source, struct oscap_source *xccdf_result_source, struct oscap_htable *oval_result_sources, const char *target_file) { xmlDoc *sds_doc = oscap_source_get_xmlDoc(sds_source); if (sds_doc == NULL) { return NULL; } xmlDoc *result_file_doc = oscap_source_get_xmlDoc(xccdf_result_source); if (result_file_doc == NULL) { return NULL; } xmlDocPtr rds_doc = NULL; if (ds_rds_create_from_dom(&rds_doc, sds_doc, result_file_doc, oval_result_sources) != 0) { return NULL; } return oscap_source_new_from_xmlDoc(rds_doc, target_file); }
static int ds_sds_dump_component(const char* component_id, struct ds_sds_session *session, const char *target_filename_dirname, const char *relative_filepath) { xmlDoc *doc = ds_sds_session_get_xmlDoc(session); xmlNodePtr component = _lookup_component_in_collection(doc, component_id); if (component == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Component of given id '%s' was not found in the document.", component_id); return -1; } xmlNodePtr inner_root = node_get_child_element(component, NULL); if (inner_root == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Found component (id='%s') but it has no element contents, nothing to dump, skipping...", component_id); return -1; } // If the inner root is script, we have to treat it in a special way if (strcmp((const char*)inner_root->name, "script") == 0) { // the cast is safe to do because we are using the GNU basename, it doesn't // modify the string const char* file_basename = basename((char*)relative_filepath); const char* sce_filename = oscap_sprintf("%s/%s/%s",ds_sds_session_get_target_dir(session), target_filename_dirname, file_basename); int ret = ds_sds_dump_component_sce(inner_root->children, component_id, sce_filename); oscap_free(sce_filename); if (ret != 0) { return ret; } } // Otherwise we create a new XML doc we will dump the contents to. // We can't just dump node "innerXML" because namespaces have to be // handled. else { xmlDoc *new_doc = ds_doc_from_foreign_node(inner_root, doc); if (new_doc == NULL) { return -1; } struct oscap_source *source = oscap_source_new_from_xmlDoc(new_doc, relative_filepath); ds_sds_session_register_component_source(session, relative_filepath, source); } return 0; }
int ds_rds_dump_arf_content(struct ds_rds_session *session, const char *container_name, const char *component_name, const char *content_id) { xmlDoc *doc = ds_rds_session_get_xmlDoc(session); xmlNodePtr parent_node = ds_rds_lookup_component(doc, container_name, component_name, content_id); if (!parent_node) { oscap_seterr(OSCAP_EFAMILY_OSCAP, "Could not find any %s of id '%s'", component_name, content_id); return -1; } xmlNodePtr content_node = ds_rds_get_inner_content(NULL, parent_node); if (!content_node) return -1; xmlNodePtr candidate = content_node->children; xmlNodePtr inner_root = NULL; for (; candidate != NULL; candidate = candidate->next) { if (candidate->type != XML_ELEMENT_NODE) continue; if (inner_root) { oscap_seterr(OSCAP_EFAMILY_XML, "There are multiple nodes inside an 'arf:content' node. " "Only the last one will be used!"); } inner_root = candidate; } if (inner_root == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Could not found any child inside 'arf:content' node when looking for %s.", content_id); return -1; } // We assume that arf:content is XML. This is reasonable because both // reports and report requests are XML documents. xmlDoc *new_doc = ds_doc_from_foreign_node(inner_root, ds_rds_session_get_xmlDoc(session)); char *target_file = oscap_sprintf("%s/%s.xml", ds_rds_session_get_target_dir(session), component_name); struct oscap_source *source = oscap_source_new_from_xmlDoc(new_doc, target_file); oscap_free(target_file); return ds_rds_session_register_component_source(session, content_id, source); }