| 1 | /* |
| 2 | * Copyright 2012--2014 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * Martin Preisler <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 24 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 25 | #endif |
| 26 | |
| 27 | #include "public/scap_ds.h"cxx . . $ `<file>/src/DS/public/scap_ds.h`/ |
| 28 | #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/ |
| 29 | #include "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/ |
| 30 | #include "common/elements.h"cxx . . $ `<file>/src/common/elements.h`/ |
| 31 | #include "sds_index_priv.h"cxx . . $ `<file>/src/DS/sds_index_priv.h`/ |
| 32 | |
| 33 | |
| 34 | #include <libxml/xmlreader.h> |
| 35 | #include <string.h> |
| 36 | |
| 37 | struct ds_stream_indexcxx . . $ ds_stream_index# |
| 38 | { |
| 39 | char* idcxx . . $ ds_stream_index#id.; |
| 40 | char* timestampcxx . . $ ds_stream_index#timestamp.; |
| 41 | char* versioncxx . . $ ds_stream_index#version.; |
| 42 | |
| 43 | struct oscap_stringlistcxx . . $ oscap_stringlist#* check_componentscxx . . $ ds_stream_index#check_components.; |
| 44 | struct oscap_stringlistcxx . . $ oscap_stringlist#* checklist_componentscxx . . $ ds_stream_index#checklist_components.; |
| 45 | struct oscap_stringlistcxx . . $ oscap_stringlist#* dictionary_componentscxx . . $ ds_stream_index#dictionary_components.; |
| 46 | struct oscap_stringlistcxx . . $ oscap_stringlist#* extended_componentscxx . . $ ds_stream_index#extended_components.; |
| 47 | |
| 48 | struct oscap_htablecxx . . $ oscap_htable# *component_id_to_component_ref_idcxx . . $ ds_stream_index#component_id_to_component_ref_id.; |
| 49 | }; |
| 50 | |
| 51 | struct ds_stream_indexcxx . . $ ds_stream_index#* ds_stream_index_newcxx . . $ ds_stream_index_new(45aec34aa21b6977).(void) |
| 52 | { |
| 53 | struct ds_stream_indexcxx . . $ ds_stream_index#* ret = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct ds_stream_indexcxx . . $ ds_stream_index#)); |
| 54 | |
| 55 | ret->idcxx . . $ ds_stream_index#id. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 56 | ret->timestampcxx . . $ ds_stream_index#timestamp. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 57 | ret->versioncxx . . $ ds_stream_index#version. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 58 | |
| 59 | ret->check_componentscxx . . $ ds_stream_index#check_components. = oscap_stringlist_newcxx . . $ oscap_stringlist_new(22a991cfbca9a1c).(); |
| 60 | ret->checklist_componentscxx . . $ ds_stream_index#checklist_components. = oscap_stringlist_newcxx . . $ oscap_stringlist_new(22a991cfbca9a1c).(); |
| 61 | ret->dictionary_componentscxx . . $ ds_stream_index#dictionary_components. = oscap_stringlist_newcxx . . $ oscap_stringlist_new(22a991cfbca9a1c).(); |
| 62 | ret->extended_componentscxx . . $ ds_stream_index#extended_components. = oscap_stringlist_newcxx . . $ oscap_stringlist_new(22a991cfbca9a1c).(); |
| 63 | |
| 64 | ret->component_id_to_component_ref_idcxx . . $ ds_stream_index#component_id_to_component_ref_id. = oscap_htable_newcxx . . $ oscap_htable_new(3c1cb2b6f390ad38).(); |
| 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | void ds_stream_index_freecxx . . $ ds_stream_index_free(3e31ab925a7c98c0).(struct ds_stream_indexcxx . . $ ds_stream_index#* s) |
| 70 | { |
| 71 | freecxx . . $ free(5d22bdacc48458e8).(s->idcxx . . $ ds_stream_index#id.); |
| 72 | freecxx . . $ free(5d22bdacc48458e8).(s->timestampcxx . . $ ds_stream_index#timestamp.); |
| 73 | freecxx . . $ free(5d22bdacc48458e8).(s->versioncxx . . $ ds_stream_index#version.); |
| 74 | |
| 75 | oscap_stringlist_freecxx . . $ oscap_stringlist_free(7df8e35292df4dfb).(s->check_componentscxx . . $ ds_stream_index#check_components.); |
| 76 | oscap_stringlist_freecxx . . $ oscap_stringlist_free(7df8e35292df4dfb).(s->checklist_componentscxx . . $ ds_stream_index#checklist_components.); |
| 77 | oscap_stringlist_freecxx . . $ oscap_stringlist_free(7df8e35292df4dfb).(s->dictionary_componentscxx . . $ ds_stream_index#dictionary_components.); |
| 78 | oscap_stringlist_freecxx . . $ oscap_stringlist_free(7df8e35292df4dfb).(s->extended_componentscxx . . $ ds_stream_index#extended_components.); |
| 79 | |
| 80 | oscap_htable_freecxx . . $ oscap_htable_free(efa5da5da5d523d).(s->component_id_to_component_ref_idcxx . . $ ds_stream_index#component_id_to_component_ref_id., (oscap_destruct_funccxx . . $ oscap_destruct_func#)freecxx . . $ free(5d22bdacc48458e8).); |
| 81 | |
| 82 | freecxx . . $ free(5d22bdacc48458e8).(s); |
| 83 | } |
| 84 | |
| 85 | const char* ds_stream_index_get_idcxx . . $ ds_stream_index_get_id(c92d33fc914bb08c).(struct ds_stream_indexcxx . . $ ds_stream_index#* s) |
| 86 | { |
| 87 | return s->idcxx . . $ ds_stream_index#id.; |
| 88 | } |
| 89 | |
| 90 | const char* ds_stream_index_get_timestampcxx . . $ ds_stream_index_get_timestamp(c92d33fc914bb08c).(struct ds_stream_indexcxx . . $ ds_stream_index#* s) |
| 91 | { |
| 92 | return s->timestampcxx . . $ ds_stream_index#timestamp.; |
| 93 | } |
| 94 | |
| 95 | const char* ds_stream_index_get_versioncxx . . $ ds_stream_index_get_version(c92d33fc914bb08c).(struct ds_stream_indexcxx . . $ ds_stream_index#* s) |
| 96 | { |
| 97 | return s->versioncxx . . $ ds_stream_index#version.; |
| 98 | } |
| 99 | |
| 100 | struct oscap_string_iteratorcxx . . $ oscap_string_iterator#* ds_stream_index_get_checkscxx . . $ ds_stream_index_get_checks(4484253c305eab5e).(struct ds_stream_indexcxx . . $ ds_stream_index#* s) |
| 101 | { |
| 102 | return oscap_iterator_newcxx . . $ oscap_iterator_new(f89fb456dfd589d7).((struct oscap_listcxx . . $ oscap_list#*)s->check_componentscxx . . $ ds_stream_index#check_components.); |
| 103 | } |
| 104 | |
| 105 | struct oscap_string_iteratorcxx . . $ oscap_string_iterator#* ds_stream_index_get_checklistscxx . . $ ds_stream_index_get_checklists(4484253c305eab5e).(struct ds_stream_indexcxx . . $ ds_stream_index#* s) |
| 106 | { |
| 107 | return oscap_iterator_newcxx . . $ oscap_iterator_new(f89fb456dfd589d7).((struct oscap_listcxx . . $ oscap_list#*)s->checklist_componentscxx . . $ ds_stream_index#checklist_components.); |
| 108 | } |
| 109 | |
| 110 | struct oscap_string_iteratorcxx . . $ oscap_string_iterator#* ds_stream_index_get_dictionariescxx . . $ ds_stream_index_get_dictionaries(4484253c305eab5e).(struct ds_stream_indexcxx . . $ ds_stream_index#* s) |
| 111 | { |
| 112 | return oscap_iterator_newcxx . . $ oscap_iterator_new(f89fb456dfd589d7).((struct oscap_listcxx . . $ oscap_list#*)s->dictionary_componentscxx . . $ ds_stream_index#dictionary_components.); |
| 113 | } |
| 114 | |
| 115 | static struct ds_stream_indexcxx . . $ ds_stream_index#* ds_stream_index_parsecxx . . $ ds_stream_index_parse(35769d988a114da5).(xmlTextReaderPtrcxx . . $ xmlTextReaderPtr# reader) |
| 116 | { |
| 117 | // sanity check |
| 118 | if (xmlTextReaderNodeTypecxx . . $ xmlTextReaderNodeType(82a242a19623f75).(reader) != XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT. || |
| 119 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).((const char*)xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader), "data-stream") != 0) |
| 120 | { |
| 121 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, |
| 122 | "Expected to have xmlTextReader at start of <ds:data-stream>, " |
| 123 | "the current event is '%i' at '%s' instead. I refuse to parse!", |
| 124 | xmlTextReaderNodeType(reader), (const char*)xmlTextReaderConstLocalName(reader)); |
| 125 | |
| 126 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 127 | } |
| 128 | |
| 129 | struct ds_stream_indexcxx . . $ ds_stream_index#* ret = ds_stream_index_newcxx . . $ ds_stream_index_new(45aec34aa21b6977).(); |
| 130 | |
| 131 | ret->idcxx . . $ ds_stream_index#id. = (char*)xmlTextReaderGetAttributecxx . . $ xmlTextReaderGetAttribute(6d056300a6ef2116).(reader, BAD_CASTcxx . . $ `<external>/11592416788776295748/xmlstring.h:34:9`! "id"); |
| 132 | ret->timestampcxx . . $ ds_stream_index#timestamp. = (char*)xmlTextReaderGetAttributecxx . . $ xmlTextReaderGetAttribute(6d056300a6ef2116).(reader, BAD_CASTcxx . . $ `<external>/11592416788776295748/xmlstring.h:34:9`! "timestamp"); |
| 133 | ret->versioncxx . . $ ds_stream_index#version. = (char*)xmlTextReaderGetAttributecxx . . $ xmlTextReaderGetAttribute(6d056300a6ef2116).(reader, BAD_CASTcxx . . $ `<external>/11592416788776295748/xmlstring.h:34:9`! "scap-version"); |
| 134 | |
| 135 | // We assume well-formedness and validity of the datastream. |
| 136 | // The parser can be broken with invalid content such as: |
| 137 | // .. <checklists><checks/><component-ref ../></checklists> .. |
| 138 | |
| 139 | struct oscap_stringlistcxx . . $ oscap_stringlist#* cref_target = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 140 | while (xmlTextReaderReadcxx . . $ xmlTextReaderRead(82a242a19623f75).(reader) == 1) |
| 141 | { |
| 142 | int node_type = xmlTextReaderNodeTypecxx . . $ xmlTextReaderNodeType(82a242a19623f75).(reader); |
| 143 | const char* local_name = (const char*)xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader); |
| 144 | |
| 145 | if (node_type == XML_READER_TYPE_END_ELEMENTcxx . . $ XML_READER_TYPE_END_ELEMENT. && // 15 == end element |
| 146 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_name, "data-stream") == 0) |
| 147 | { |
| 148 | // we are done reading |
| 149 | break; |
| 150 | } |
| 151 | // the following code switches where we push component refs |
| 152 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_name, "checklists") == 0) |
| 153 | { |
| 154 | cref_target = node_type == XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT. ? ret->checklist_componentscxx . . $ ds_stream_index#checklist_components. : NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 155 | } |
| 156 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_name, "checks") == 0) |
| 157 | { |
| 158 | cref_target = node_type == XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT. ? ret->check_componentscxx . . $ ds_stream_index#check_components. : NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 159 | } |
| 160 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_name, "dictionaries") == 0) |
| 161 | { |
| 162 | cref_target = node_type == XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT. ? ret->dictionary_componentscxx . . $ ds_stream_index#dictionary_components. : NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 163 | } |
| 164 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_name, "extended-components") == 0) |
| 165 | { |
| 166 | cref_target = node_type == XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT. ? ret->extended_componentscxx . . $ ds_stream_index#extended_components. : NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 167 | } |
| 168 | // reading of the component refs, we only care about their ID |
| 169 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_name, "component-ref") == 0 && |
| 170 | node_type == XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT.) |
| 171 | { |
| 172 | // sanity check |
| 173 | if (cref_target == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 174 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, |
| 175 | "Encountered <ds:component-ref> but it is either not inside " |
| 176 | "any container element or container elements interleave. " |
| 177 | "Please make sure the datastream is valid!"); |
| 178 | } |
| 179 | else { |
| 180 | xmlCharcxx . . $ xmlChar# *id_attr = xmlTextReaderGetAttributecxx . . $ xmlTextReaderGetAttribute(6d056300a6ef2116).(reader, BAD_CASTcxx . . $ `<external>/11592416788776295748/xmlstring.h:34:9`! "id"); |
| 181 | xmlCharcxx . . $ xmlChar# *href_attr = xmlTextReaderGetAttributeNscxx . . $ xmlTextReaderGetAttributeNs(21dfd50d05bdcb5f).(reader, BAD_CASTcxx . . $ `<external>/11592416788776295748/xmlstring.h:34:9`! "href", BAD_CASTcxx . . $ `<external>/11592416788776295748/xmlstring.h:34:9`! "http://www.w3.org/1999/xlink"); |
| 182 | |
| 183 | // this copies the id_attr string |
| 184 | oscap_stringlist_add_stringcxx . . $ oscap_stringlist_add_string(80c12aaea9c014af).(cref_target, (const char*)id_attr); |
| 185 | |
| 186 | // because of the leading '#' in the href preceding the component id |
| 187 | const char *component_id = (const char*)(href_attr && href_attr[0] ? (href_attr + 1 * sizeof(char)) : NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 188 | if (!component_id || !oscap_htable_addcxx . . $ oscap_htable_add(d9abe78f59fa00eb).(ret->component_id_to_component_ref_idcxx . . $ ds_stream_index#component_id_to_component_ref_id., component_id, (char*)id_attr)) { |
| 189 | if (component_id) { |
| 190 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, |
| 191 | "There is already a mapping from component id '%s' to component-ref id '%s'. " |
| 192 | "Having multiple mappings is legal in a datastream but it may prove problematic " |
| 193 | "when selecting component-refs using XCCDF Benchmark IDs.", |
| 194 | component_id, id_attr); |
| 195 | } |
| 196 | |
| 197 | xmlFreecxx . . $ xmlFree.(id_attr); |
| 198 | } |
| 199 | |
| 200 | xmlFreecxx . . $ xmlFree.(href_attr); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | struct ds_sds_indexcxx . . $ ds_sds_index# |
| 209 | { |
| 210 | struct oscap_listcxx . . $ oscap_list# *streamscxx . . $ ds_sds_index#streams.; |
| 211 | |
| 212 | struct oscap_htablecxx . . $ oscap_htable# *benchmark_id_to_component_idcxx . . $ ds_sds_index#benchmark_id_to_component_id.; |
| 213 | }; |
| 214 | |
| 215 | struct ds_sds_indexcxx . . $ ds_sds_index#* ds_sds_index_newcxx . . $ ds_sds_index_new(65326e5f3743bfff).(void) |
| 216 | { |
| 217 | struct ds_sds_indexcxx . . $ ds_sds_index#* ret = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct ds_sds_indexcxx . . $ ds_sds_index#)); |
| 218 | ret->streamscxx . . $ ds_sds_index#streams. = oscap_list_newcxx . . $ oscap_list_new(ea215f73c8361bff).(); |
| 219 | |
| 220 | ret->benchmark_id_to_component_idcxx . . $ ds_sds_index#benchmark_id_to_component_id. = oscap_htable_newcxx . . $ oscap_htable_new(3c1cb2b6f390ad38).(); |
| 221 | |
| 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | void ds_sds_index_freecxx . . $ ds_sds_index_free(11d86e963c8cc4be).(struct ds_sds_indexcxx . . $ ds_sds_index#* s) |
| 226 | { |
| 227 | if (s != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 228 | oscap_list_freecxx . . $ oscap_list_free(e68e105c3900fcc1).(s->streamscxx . . $ ds_sds_index#streams., (oscap_destruct_funccxx . . $ oscap_destruct_func#)ds_stream_index_freecxx . . $ ds_stream_index_free(3e31ab925a7c98c0).); |
| 229 | |
| 230 | oscap_htable_freecxx . . $ oscap_htable_free(efa5da5da5d523d).(s->benchmark_id_to_component_idcxx . . $ ds_sds_index#benchmark_id_to_component_id., (oscap_destruct_funccxx . . $ oscap_destruct_func#)freecxx . . $ free(5d22bdacc48458e8).); |
| 231 | |
| 232 | freecxx . . $ free(5d22bdacc48458e8).(s); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static void ds_sds_index_add_streamcxx . . $ ds_sds_index_add_stream(3acaf797be356a15).(struct ds_sds_indexcxx . . $ ds_sds_index#* s, struct ds_stream_indexcxx . . $ ds_stream_index#* stream) |
| 237 | { |
| 238 | oscap_list_addcxx . . $ oscap_list_add(97f28760a5cf7823).(s->streamscxx . . $ ds_sds_index#streams., stream); |
| 239 | } |
| 240 | |
| 241 | struct ds_stream_indexcxx . . $ ds_stream_index#* ds_sds_index_get_streamcxx . . $ ds_sds_index_get_stream(5c419e4b1e68b074).(struct ds_sds_indexcxx . . $ ds_sds_index#* sds, const char* stream_id) |
| 242 | { |
| 243 | struct ds_stream_indexcxx . . $ ds_stream_index#* ret = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 244 | |
| 245 | struct ds_stream_index_iteratorcxx . . $ ds_stream_index_iterator#* streams = ds_sds_index_get_streamscxx . . $ ds_sds_index_get_streams(812311662d5ba693).(sds); |
| 246 | while (ds_stream_index_iterator_has_morecxx . . $ ds_stream_index_iterator_has_more(c225a27a4fccde78).(streams)) |
| 247 | { |
| 248 | struct ds_stream_indexcxx . . $ ds_stream_index#* stream = ds_stream_index_iterator_nextcxx . . $ ds_stream_index_iterator_next(52812d4c4a7c3217).(streams); |
| 249 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(ds_stream_index_get_idcxx . . $ ds_stream_index_get_id(c92d33fc914bb08c).(stream), stream_id) == 0) |
| 250 | { |
| 251 | ret = stream; |
| 252 | break; |
| 253 | } |
| 254 | |
| 255 | } |
| 256 | ds_stream_index_iterator_freecxx . . $ ds_stream_index_iterator_free(7e4fb91f616c49f4).(streams); |
| 257 | |
| 258 | return ret; |
| 259 | } |
| 260 | |
| 261 | struct ds_stream_index_iteratorcxx . . $ ds_stream_index_iterator#* ds_sds_index_get_streamscxx . . $ ds_sds_index_get_streams(812311662d5ba693).(struct ds_sds_indexcxx . . $ ds_sds_index#* s) |
| 262 | { |
| 263 | return (struct ds_stream_index_iteratorcxx . . $ ds_stream_index_iterator#*)oscap_iterator_newcxx . . $ oscap_iterator_new(f89fb456dfd589d7).(s->streamscxx . . $ ds_sds_index#streams.); |
| 264 | } |
| 265 | |
| 266 | static char *ds_sds_component_dig_benchmark_idcxx . . $ ds_sds_component_dig_benchmark_id(93c99f8009311dd0).(xmlTextReaderPtrcxx . . $ xmlTextReaderPtr# reader) |
| 267 | { |
| 268 | // sanity check |
| 269 | if (xmlTextReaderNodeTypecxx . . $ xmlTextReaderNodeType(82a242a19623f75).(reader) != XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT. || |
| 270 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).((const char*)xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader), "component") != 0) |
| 271 | { |
| 272 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, |
| 273 | "Expected to have xmlTextReader at start of <ds:component>, " |
| 274 | "the current event is '%i' at '%s' instead. I refuse to parse!", |
| 275 | xmlTextReaderNodeType(reader), (const char*)xmlTextReaderConstLocalName(reader)); |
| 276 | |
| 277 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 278 | } |
| 279 | |
| 280 | char *ret = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 281 | while (xmlTextReaderReadcxx . . $ xmlTextReaderRead(82a242a19623f75).(reader) == 1) |
| 282 | { |
| 283 | int node_type = xmlTextReaderNodeTypecxx . . $ xmlTextReaderNodeType(82a242a19623f75).(reader); |
| 284 | const char* local_name = (const char*)xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader); |
| 285 | |
| 286 | if (node_type == XML_READER_TYPE_END_ELEMENTcxx . . $ XML_READER_TYPE_END_ELEMENT. && |
| 287 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_name, "component") == 0) { |
| 288 | // we are done reading |
| 289 | break; |
| 290 | } |
| 291 | else if (node_type == XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT. && |
| 292 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_name, "Benchmark") == 0) { |
| 293 | if (ret) { |
| 294 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, |
| 295 | "Found 2 Benchmark elements inside a single sds:component element! " |
| 296 | "Please make sure your datastream is valid. Skipping the second Benchmark."); |
| 297 | } |
| 298 | else { |
| 299 | ret = (char*)xmlTextReaderGetAttributecxx . . $ xmlTextReaderGetAttribute(6d056300a6ef2116).(reader, BAD_CASTcxx . . $ `<external>/11592416788776295748/xmlstring.h:34:9`! "id"); |
| 300 | } |
| 301 | } |
| 302 | else { |
| 303 | // ignore |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | struct ds_sds_indexcxx . . $ ds_sds_index#* ds_sds_index_parsecxx . . $ ds_sds_index_parse(76a9ccb52c440097).(xmlTextReaderPtrcxx . . $ xmlTextReaderPtr# reader) |
| 311 | { |
| 312 | if (!oscap_to_start_elementcxx . . $ oscap_to_start_element(c0c45fd800596ca5).(reader, 0)) { |
| 313 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, |
| 314 | "Expected to to have start of <ds:data-stream-collection> at document root, " |
| 315 | "no elements were found! I refuse to parse!"); |
| 316 | |
| 317 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 318 | } |
| 319 | |
| 320 | if (xmlTextReaderNodeTypecxx . . $ xmlTextReaderNodeType(82a242a19623f75).(reader) != XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT. || |
| 321 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).((const char*)xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader), "data-stream-collection") != 0) |
| 322 | { |
| 323 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, |
| 324 | "Expected to to have start of <ds:data-stream-collection> at document root, " |
| 325 | "the current event is '%i' at '%s' instead. I refuse to parse!", |
| 326 | xmlTextReaderNodeType(reader), (const char*)xmlTextReaderConstLocalName(reader)); |
| 327 | |
| 328 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 329 | } |
| 330 | |
| 331 | if (xmlTextReaderReadcxx . . $ xmlTextReaderRead(82a242a19623f75).(reader) != 1) |
| 332 | { |
| 333 | oscap_setxmlerrcxx . . $ `src/common/_error.h:36:9`!(xmlGetLastError()); |
| 334 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 335 | } |
| 336 | |
| 337 | struct ds_sds_indexcxx . . $ ds_sds_index#* ret = ds_sds_index_newcxx . . $ ds_sds_index_new(65326e5f3743bfff).(); |
| 338 | |
| 339 | while (oscap_to_start_elementcxx . . $ oscap_to_start_element(c0c45fd800596ca5).(reader, 1)) |
| 340 | { |
| 341 | const char* name = (const char *)xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader); |
| 342 | /*if (strcmp(name, "component") == 0) |
| 343 | { |
| 344 | // XSD of source datastream dictates that no ds:data-stream elements |
| 345 | // follow after ds:component element. We can safely stop reading here. |
| 346 | break; |
| 347 | }*/ |
| 348 | |
| 349 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, "data-stream") == 0) { |
| 350 | struct ds_stream_indexcxx . . $ ds_stream_index#* s = ds_stream_index_parsecxx . . $ ds_stream_index_parse(35769d988a114da5).(reader); |
| 351 | // NULL means error happened, the ds_stream_index_parse already set the error |
| 352 | // in that case |
| 353 | if (s != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 354 | ds_sds_index_add_streamcxx . . $ ds_sds_index_add_stream(3acaf797be356a15).(ret, s); |
| 355 | } |
| 356 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, "component") == 0) { |
| 357 | char *component_id = (char*)xmlTextReaderGetAttributecxx . . $ xmlTextReaderGetAttribute(6d056300a6ef2116).(reader, BAD_CASTcxx . . $ `<external>/11592416788776295748/xmlstring.h:34:9`! "id"); |
| 358 | char *benchmark_id = ds_sds_component_dig_benchmark_idcxx . . $ ds_sds_component_dig_benchmark_id(93c99f8009311dd0).(reader); |
| 359 | |
| 360 | if (benchmark_id == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 361 | freecxx . . $ free(5d22bdacc48458e8).(component_id); |
| 362 | } |
| 363 | else { |
| 364 | if (!oscap_htable_addcxx . . $ oscap_htable_add(d9abe78f59fa00eb).(ret->benchmark_id_to_component_idcxx . . $ ds_sds_index#benchmark_id_to_component_id., benchmark_id, component_id)) { |
| 365 | // This benchmark ID was already in the map, therefore there must be 2 components |
| 366 | // with Benchmarks in them that have the same IDs. In this case, all bets are off |
| 367 | // when it comes to selecting a component-ref using Benchmark ID. |
| 368 | // |
| 369 | // To establish a well defined behavior, we don't "overwrite" it with the newly |
| 370 | // found benchmark but instead use the first benchmark with such ID there. |
| 371 | |
| 372 | // TODO: Warning? |
| 373 | /*oscap_seterr(OSCAP_EFAMILY_XML, "There are at least two components containing " |
| 374 | "an XCCDF Benchmark with exactly the same ID ('%s'). Selecting a component-ref " |
| 375 | "using Benchmark ID will use the first component encountered and ignore " |
| 376 | "the subsequent ones with the same ID.", benchmark_id);*/ |
| 377 | |
| 378 | freecxx . . $ free(5d22bdacc48458e8).(component_id); |
| 379 | } |
| 380 | |
| 381 | freecxx . . $ free(5d22bdacc48458e8).(benchmark_id); |
| 382 | } |
| 383 | |
| 384 | // we are going to free the component_id string later (in ds_sds_index_free) |
| 385 | } |
| 386 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, "extended-component") == 0) { |
| 387 | // ignore, extended-component can't be an XCCDF, therefore we are sure |
| 388 | // not to be able to dig any Benchmark @id from it |
| 389 | } |
| 390 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, "Signature") == 0) { |
| 391 | // ignore, Signatures are to be checked externally, we don't load them in |
| 392 | } |
| 393 | else { |
| 394 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, "Unknown element '%s' encountered while parsing Source DataStream to ds_sds_index, skipping...", name); |
| 395 | } |
| 396 | |
| 397 | xmlTextReaderReadcxx . . $ xmlTextReaderRead(82a242a19623f75).(reader); |
| 398 | } |
| 399 | |
| 400 | return ret; |
| 401 | } |
| 402 | |
| 403 | int ds_sds_index_select_checklistcxx . . $ ds_sds_index_select_checklist(bea618b8c835104b).(struct ds_sds_indexcxx . . $ ds_sds_index#* s, |
| 404 | const char** datastream_id, const char** component_id) |
| 405 | { |
| 406 | // The following convoluted and complex code looks for a pair of |
| 407 | // datastream and checklist inside it that satisfies conditions |
| 408 | // (if any) of having specific IDs. |
| 409 | // |
| 410 | // It is possible to just pass xccdf-id in which case we have to |
| 411 | // search through all the datastreams. |
| 412 | // |
| 413 | // It is also possible to just pass datastream-id in which case we |
| 414 | // take the first checklist in given datastream. |
| 415 | // |
| 416 | // In case datastream-id is not passed AND xccdf-id is also not passed, |
| 417 | // we look for the first datastream (topdown in XML) that has any |
| 418 | // checklist. Taking the first checklist in such a datastream in this case. |
| 419 | |
| 420 | int ret = 1; |
| 421 | |
| 422 | struct ds_stream_index_iteratorcxx . . $ ds_stream_index_iterator#* streams_it = ds_sds_index_get_streamscxx . . $ ds_sds_index_get_streams(812311662d5ba693).(s); |
| 423 | while (ds_stream_index_iterator_has_morecxx . . $ ds_stream_index_iterator_has_more(c225a27a4fccde78).(streams_it)) |
| 424 | { |
| 425 | struct ds_stream_indexcxx . . $ ds_stream_index#* stream_idx = ds_stream_index_iterator_nextcxx . . $ ds_stream_index_iterator_next(52812d4c4a7c3217).(streams_it); |
| 426 | const char* stream_id = ds_stream_index_get_idcxx . . $ ds_stream_index_get_id(c92d33fc914bb08c).(stream_idx); |
| 427 | |
| 428 | if (!*datastream_id || strcmpcxx . . $ strcmp(5ae29d726ae57f88).(stream_id, *datastream_id) == 0) |
| 429 | { |
| 430 | struct oscap_string_iteratorcxx . . $ oscap_string_iterator#* checklists_it = ds_stream_index_get_checklistscxx . . $ ds_stream_index_get_checklists(4484253c305eab5e).(stream_idx); |
| 431 | while (oscap_string_iterator_has_morecxx . . $ oscap_string_iterator_has_more(3724f2faf2515a82).(checklists_it)) |
| 432 | { |
| 433 | const char* checklist_id = oscap_string_iterator_nextcxx . . $ oscap_string_iterator_next(1f2a9ae2534eef34).(checklists_it); |
| 434 | |
| 435 | if (!*component_id || strcmpcxx . . $ strcmp(5ae29d726ae57f88).(checklist_id, *component_id) == 0) |
| 436 | { |
| 437 | *component_id = checklist_id; |
| 438 | *datastream_id = ds_stream_index_get_idcxx . . $ ds_stream_index_get_id(c92d33fc914bb08c).(stream_idx); |
| 439 | ret = 0; |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | oscap_string_iterator_freecxx . . $ oscap_string_iterator_free(41a77e9ce361f406).(checklists_it); |
| 444 | } |
| 445 | } |
| 446 | ds_stream_index_iterator_freecxx . . $ ds_stream_index_iterator_free(7e4fb91f616c49f4).(streams_it); |
| 447 | |
| 448 | return ret; |
| 449 | } |
| 450 | |
| 451 | int ds_sds_index_select_checklist_by_benchmark_idcxx . . $ ds_sds_index_select_checklist_by_benchmark_id(ef460bc797fc7a23).(struct ds_sds_indexcxx . . $ ds_sds_index#* s, |
| 452 | const char *benchmark_id, const char **datastream_id, const char **component_ref_id) |
| 453 | { |
| 454 | const char *mapped_component_id = (const char*)oscap_htable_getcxx . . $ oscap_htable_get(f5c7e8ff6c970cd3).(s->benchmark_id_to_component_idcxx . . $ ds_sds_index#benchmark_id_to_component_id., benchmark_id); |
| 455 | if (!mapped_component_id) { |
| 456 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, "Can't map benchmark ID '%s' to any component ID.", benchmark_id); |
| 457 | return 1; |
| 458 | } |
| 459 | |
| 460 | int ret = 1; |
| 461 | |
| 462 | struct ds_stream_index_iteratorcxx . . $ ds_stream_index_iterator#* streams_it = ds_sds_index_get_streamscxx . . $ ds_sds_index_get_streams(812311662d5ba693).(s); |
| 463 | while (ds_stream_index_iterator_has_morecxx . . $ ds_stream_index_iterator_has_more(c225a27a4fccde78).(streams_it)) |
| 464 | { |
| 465 | struct ds_stream_indexcxx . . $ ds_stream_index# *stream_idx = ds_stream_index_iterator_nextcxx . . $ ds_stream_index_iterator_next(52812d4c4a7c3217).(streams_it); |
| 466 | const char *stream_id = ds_stream_index_get_idcxx . . $ ds_stream_index_get_id(c92d33fc914bb08c).(stream_idx); |
| 467 | |
| 468 | if (!*datastream_id || strcmpcxx . . $ strcmp(5ae29d726ae57f88).(stream_id, *datastream_id) == 0) |
| 469 | { |
| 470 | const char *candidate_component_ref_id = (const char*)oscap_htable_getcxx . . $ oscap_htable_get(f5c7e8ff6c970cd3).(stream_idx->component_id_to_component_ref_idcxx . . $ ds_stream_index#component_id_to_component_ref_id., mapped_component_id); |
| 471 | if (candidate_component_ref_id) { |
| 472 | *datastream_id = stream_id; |
| 473 | *component_ref_id = candidate_component_ref_id; |
| 474 | ret = 0; |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | ds_stream_index_iterator_freecxx . . $ ds_stream_index_iterator_free(7e4fb91f616c49f4).(streams_it); |
| 480 | |
| 481 | return ret; |
| 482 | } |
| 483 | |
| 484 | struct ds_stream_indexcxx . . $ ds_stream_index# *ds_stream_index_iterator_nextcxx . . $ ds_stream_index_iterator_next(52812d4c4a7c3217).(struct ds_stream_index_iteratorcxx . . $ ds_stream_index_iterator# *it) |
| 485 | { |
| 486 | return (struct ds_stream_indexcxx . . $ ds_stream_index#*)(oscap_iterator_nextcxx . . $ oscap_iterator_next(4c75051c806960eb).((struct oscap_iteratorcxx . . $ oscap_iterator#*)it)); |
| 487 | } |
| 488 | |
| 489 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ds_stream_index_iterator_has_morecxx . . $ ds_stream_index_iterator_has_more(c225a27a4fccde78).(struct ds_stream_index_iteratorcxx . . $ ds_stream_index_iterator# *it) |
| 490 | { |
| 491 | return oscap_iterator_has_morecxx . . $ oscap_iterator_has_more(63b1de9a5adb9205).((struct oscap_iteratorcxx . . $ oscap_iterator#*)it); |
| 492 | } |
| 493 | |
| 494 | void ds_stream_index_iterator_freecxx . . $ ds_stream_index_iterator_free(7e4fb91f616c49f4).(struct ds_stream_index_iteratorcxx . . $ ds_stream_index_iterator# *it) |
| 495 | { |
| 496 | oscap_iterator_freecxx . . $ oscap_iterator_free(3cba44c1b7872358).((struct oscap_iteratorcxx . . $ oscap_iterator#*)it); |
| 497 | } |