Debian Codegraph @

src/source/oscap_source.c

raw symbols SCIP
1 /*
2 * Copyright 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 * Author:
20 * Šimon Lukašík
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 <string.h>
28 #include <fcntl.h>
29 #ifdef OS_WINDOWS
30 #include <io.h>
31 #else
32 #include <unistd.h>
33 #endif
34 #include <libxml/parser.h>
35 #include <libxml/xmlreader.h>
36 #include <libxml/xmlerror.h>
37
38 #include "common/elements.h"cxx . . $ `<file>/src/common/elements.h`/
39 #include "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/
40 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
41 #include "common/public/oscap.h"cxx . . $ `<file>/src/common/public/oscap.h`/
42 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
43 #include "CPE/public/cpe_lang.h"cxx . . $ `<file>/src/CPE/public/cpe_lang.h`/
44 #include "CPE/cpedict_priv.h"cxx . . $ `<file>/src/CPE/cpedict_priv.h`/
45 #include "CPE/cpelang_priv.h"cxx . . $ `<file>/src/CPE/cpelang_priv.h`/
46 #include "doc_type_priv.h"cxx . . $ `<file>/src/source/doc_type_priv.h`/
47 #include "oscap_source.h"cxx . . $ `<file>/src/source/public/oscap_source.h`/
48 #include "common/oscap_string.h"cxx . . $ `<file>/src/common/oscap_string.h`/
49 #include "oscap_source_priv.h"cxx . . $ `<file>/src/source/oscap_source_priv.h`/
50 #include "OVAL/oval_parser_impl.h"cxx . . $ `<file>/src/OVAL/oval_parser_impl.h`/
51 #include "OVAL/public/oval_definitions.h"cxx . . $ `<file>/src/OVAL/public/oval_definitions.h`/
52 #include "source/bz2_priv.h"cxx . . $ `<file>/src/source/bz2_priv.h`/
53 #include "source/schematron_priv.h"cxx . . $ `<file>/src/source/schematron_priv.h`/
54 #include "source/validate_priv.h"cxx . . $ `<file>/src/source/validate_priv.h`/
55 #include "XCCDF/elements.h"cxx . . $ `<file>/src/XCCDF/elements.h`/
56 #include "XCCDF/public/xccdf_benchmark.h"cxx . . $ `<file>/src/XCCDF/public/xccdf_benchmark.h`/
57 #include "DS/sds_priv.h"cxx . . $ `<file>/src/DS/sds_priv.h`/
58
59 typedef enum oscap_source_typecxx . . $ oscap_source_type# {
60 OSCAP_SRC_FROM_USER_XML_FILEcxx . . $ OSCAP_SRC_FROM_USER_XML_FILE. = 1, ///< The source originated from XML file supplied by user
61 OSCAP_SRC_FROM_USER_MEMORYcxx . . $ OSCAP_SRC_FROM_USER_MEMORY., ///< The source originated from memory supplied by user
62 OSCAP_SRC_FROM_XML_DOMcxx . . $ OSCAP_SRC_FROM_XML_DOM., ///< The source originated from XML DOM (most often from DataStream).
63 // TODO: downloaded from an http address (XCCDF can refer to remote sources)
64 } oscap_source_type_tcxx . . $ oscap_source_type_t#;
65
66 struct oscap_sourcecxx . . $ oscap_source# {
67 oscap_document_type_tcxx . . $ oscap_document_type_t# scap_typecxx . . $ oscap_source#scap_type.; ///< Type of SCAP document (XCCDF, OVAL, ...)
68 structcxx . . $ oscap_source#$anonymous_type_0# {
69 oscap_source_type_tcxx . . $ oscap_source_type_t# typecxx . . $ oscap_source#$anonymous_type_0#type.; ///< Internal type of the oscap_source
70 char *versioncxx . . $ oscap_source#$anonymous_type_0#version.; ///< Version of the particular document type
71 char *filepathcxx . . $ oscap_source#$anonymous_type_0#filepath.; ///< Filepath (if originated from file)
72 char *memorycxx . . $ oscap_source#$anonymous_type_0#memory.; ///< Memory buffer (if originated from memory)
73 size_t memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size.; ///< Size of the memory buffer (if originated from memory)
74 } origincxx . . $ oscap_source#origin.; ///
75 structcxx . . $ oscap_source#$anonymous_type_1# {
76 xmlDoccxx . . $ xmlDoc# *doccxx . . $ oscap_source#$anonymous_type_1#doc.; /// DOM
77 } xmlcxx . . $ oscap_source#xml.;
78 };
79
80 struct oscap_sourcecxx . . $ oscap_source# *oscap_source_new_from_filecxx . . $ oscap_source_new_from_file(987f8b70a317ffb9).(const char *filepath)
81 {
82 /* TODO: At the end of the day, this shall be the only place in
83 * the library where a path to filename is set from the outside.
84 */
85 struct oscap_sourcecxx . . $ oscap_source# *source = (struct oscap_sourcecxx . . $ oscap_source# *) calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct oscap_sourcecxx . . $ oscap_source#));
86 source->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(filepath);
87 source->origincxx . . $ oscap_source#origin..typecxx . . $ oscap_source#$anonymous_type_0#type. = OSCAP_SRC_FROM_USER_XML_FILEcxx . . $ OSCAP_SRC_FROM_USER_XML_FILE.;
88 return source;
89 }
90
91 struct oscap_sourcecxx . . $ oscap_source# *oscap_source_clonecxx . . $ oscap_source_clone(ab0443cab9f10e49).(struct oscap_sourcecxx . . $ oscap_source# *old)
92 {
93 struct oscap_sourcecxx . . $ oscap_source# *new = (struct oscap_sourcecxx . . $ oscap_source# *) calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct oscap_sourcecxx . . $ oscap_source#));
94 new->scap_typecxx . . $ oscap_source#scap_type. = old->scap_typecxx . . $ oscap_source#scap_type.;
95 new->origincxx . . $ oscap_source#origin..typecxx . . $ oscap_source#$anonymous_type_0#type. = old->origincxx . . $ oscap_source#origin..typecxx . . $ oscap_source#$anonymous_type_0#type.;
96 new->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version.);
97 new->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath.);
98 new->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory.);
99 new->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size. = old->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size.;
100 new->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = xmlCopyDoccxx . . $ xmlCopyDoc(e24caa64b81680f5).(old->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc., truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
101 return new;
102 }
103
104 /**
105 * Allocate oscap_source struct and fill for memory data
106 * @param size_t size Size of data
107 * @param const char* filepath Path of file
108 * @return Allocated struct
109 */
110 static struct oscap_sourcecxx . . $ oscap_source#* _create_oscap_sourcecxx . . $ _create_oscap_source(13ced77dd27f01).(size_t size, const char* filepath)
111 {
112 struct oscap_sourcecxx . . $ oscap_source# *source = (struct oscap_sourcecxx . . $ oscap_source# *) calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct oscap_sourcecxx . . $ oscap_source#));
113 source->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size. = size;
114 source->origincxx . . $ oscap_source#origin..typecxx . . $ oscap_source#$anonymous_type_0#type. = OSCAP_SRC_FROM_USER_MEMORYcxx . . $ OSCAP_SRC_FROM_USER_MEMORY.;
115 source->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(filepath ? filepath : "NONEXISTENT");
116 return source;
117 }
118
119 struct oscap_sourcecxx . . $ oscap_source# *oscap_source_new_from_memorycxx . . $ oscap_source_new_from_memory(86df49a7a06e860a).(const char *buffer, size_t size, const char *filepath)
120 {
121 struct oscap_sourcecxx . . $ oscap_source# *source = _create_oscap_sourcecxx . . $ _create_oscap_source(13ced77dd27f01).(size, filepath);
122 source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, size);
123 memcpycxx . . $ memcpy(cc817cb175f282d).(source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory., buffer, size);
124 return source;
125 }
126
127 struct oscap_sourcecxx . . $ oscap_source# *oscap_source_new_take_memorycxx . . $ oscap_source_new_take_memory(2b1f5a784648902c).(char *buffer, size_t size, const char *filepath)
128 {
129 struct oscap_sourcecxx . . $ oscap_source#* source = _create_oscap_sourcecxx . . $ _create_oscap_source(13ced77dd27f01).(size, filepath);
130 source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory. = buffer;
131 return source;
132 }
133
134 struct oscap_sourcecxx . . $ oscap_source# *oscap_source_new_from_xmlDoccxx . . $ oscap_source_new_from_xmlDoc(20d5db8f38e74517).(xmlDoccxx . . $ xmlDoc# *doc, const char *filepath)
135 {
136 struct oscap_sourcecxx . . $ oscap_source# *source = (struct oscap_sourcecxx . . $ oscap_source# *) calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct oscap_sourcecxx . . $ oscap_source#));
137 source->origincxx . . $ oscap_source#origin..typecxx . . $ oscap_source#$anonymous_type_0#type. = OSCAP_SRC_FROM_XML_DOMcxx . . $ OSCAP_SRC_FROM_XML_DOM.;
138 source->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(filepath ? filepath : "NONEXISTENT");
139 source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = doc;
140 return source;
141 }
142
143 void oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(struct oscap_sourcecxx . . $ oscap_source# *source)
144 {
145 if (source != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
146 freecxx . . $ free(5d22bdacc48458e8).(source->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath.);
147 freecxx . . $ free(5d22bdacc48458e8).(source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory.);
148 if (source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
149 xmlFreeDoccxx . . $ xmlFreeDoc(42de24d0ab3f771).(source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc.);
150 }
151 freecxx . . $ free(5d22bdacc48458e8).(source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version.);
152 freecxx . . $ free(5d22bdacc48458e8).(source);
153 }
154 }
155
156 void oscap_source_free_xmlDoccxx . . $ oscap_source_free_xmlDoc(1a322e80279420f6).(struct oscap_sourcecxx . . $ oscap_source# *source)
157 {
158 if (source != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
159 if (source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
160 xmlFreeDoccxx . . $ xmlFreeDoc(42de24d0ab3f771).(source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc.);
161 source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
162 }
163 }
164 }
165
166 /**
167 * Returns human readable description of oscap_source origin
168 */
169 const char *oscap_source_readable_origincxx . . $ oscap_source_readable_origin(1485dc36ee4b63be).(const struct oscap_sourcecxx . . $ oscap_source# *source)
170 {
171 // TODO: This may just return NONEXISTANT for sources from raw memory or xmlDoc
172 // and that's not very useful.
173 return source->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath.;
174 }
175
176 xmlTextReadercxx . . $ xmlTextReader# *oscap_source_get_xmlTextReadercxx . . $ oscap_source_get_xmlTextReader(9a7ef22a0934f79d).(struct oscap_sourcecxx . . $ oscap_source# *source)
177 {
178 xmlDoccxx . . $ xmlDoc# *doc = oscap_source_get_xmlDoccxx . . $ oscap_source_get_xmlDoc(51aac4e66711e6e6).(source);
179 if (doc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
180 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
181 }
182 xmlTextReadercxx . . $ xmlTextReader# *reader = xmlReaderWalkercxx . . $ xmlReaderWalker(af3755914c249f7f).(doc);
183 if (reader == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
184 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, "Unable to create xmlTextReader for %s", oscap_source_readable_origin(source));
185 oscap_setxmlerrcxx . . $ `src/common/_error.h:36:9`!(xmlGetLastError());
186 }
187 return reader;
188 }
189
190 oscap_document_type_tcxx . . $ oscap_document_type_t# oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(struct oscap_sourcecxx . . $ oscap_source# *source)
191 {
192 if (source->scap_typecxx . . $ oscap_source#scap_type. == OSCAP_DOCUMENT_UNKNOWNcxx . . $ OSCAP_DOCUMENT_UNKNOWN.) {
193 xmlTextReadercxx . . $ xmlTextReader# *reader = oscap_source_get_xmlTextReadercxx . . $ oscap_source_get_xmlTextReader(9a7ef22a0934f79d).(source);
194 if (reader == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
195 // the oscap error is already set
196 return OSCAP_DOCUMENT_UNKNOWNcxx . . $ OSCAP_DOCUMENT_UNKNOWN.;
197 }
198 if (oscap_determine_document_type_readercxx . . $ oscap_determine_document_type_reader(2443a3037591db81).(reader, &(source->scap_typecxx . . $ oscap_source#scap_type.)) == -1) {
199 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, "Unknown document type: '%s'", oscap_source_readable_origin(source));
200 // in case of error scap_type must remain UNKNOWN
201 assertcxx . . $ `/usr/include/assert.h:50:10`!(source->scap_type == OSCAP_DOCUMENT_UNKNOWN);
202 }
203 xmlFreeTextReadercxx . . $ xmlFreeTextReader(724dbfdba9ec3ce8).(reader);
204 }
205 return source->scap_typecxx . . $ oscap_source#scap_type.;
206 }
207
208 const char *oscap_source_get_filepathcxx . . $ oscap_source_get_filepath(e20df36988f50e45).(struct oscap_sourcecxx . . $ oscap_source# *source)
209 {
210 return source->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath.;
211 }
212
213 static void xmlErrorCbcxx . . $ xmlErrorCb(fba88424a01b5f9c).(struct oscap_stringcxx . . $ oscap_string# *buffer, const char * format, ...)
214 {
215 va_listcxx . . $ va_list# ap;
216 va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(ap, format);
217
218 char* error_msg = oscap_vsprintfcxx . . $ oscap_vsprintf(db813db1ba4aba5a).(format, ap);
219 oscap_string_append_stringcxx . . $ oscap_string_append_string(bdf4962f194308bb).(buffer, error_msg);
220 freecxx . . $ free(5d22bdacc48458e8).(error_msg);
221
222 va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(ap);
223 }
224
225 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! fd_file_is_executablecxx . . $ fd_file_is_executable(83c267b20bac841a).(int fd)
226 {
227 int fd_dup = dupcxx . . $ dup(7864480464b09eea).(fd);
228 if (fd_dup == -1) {
229 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
230 }
231 lseekcxx . . $ lseek(f1afe674ac17c82e).(fd_dup, 0, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
232 FILEcxx . . $ FILE#* file = fdopencxx . . $ fdopen(8f4e2d7350ebd077).(fd_dup, "r");
233
234 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
235 // Cannot determine type of file we cannot open
236 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
237 }
238
239 // Check SHEBANG
240 // When we read after end of file, we get EOF (-1),
241 // So we don't have to do any special check
242 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! is_exec = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
243 if ( fgetccxx . . $ fgetc(89bc1efcdac0ca22).(file) != (int)'#' ) is_exec = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
244 if ( fgetccxx . . $ fgetc(89bc1efcdac0ca22).(file) != (int)'!' ) is_exec = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
245
246 fclosecxx . . $ fclose(89bc1efcdac0ca22).(file);
247 lseekcxx . . $ lseek(f1afe674ac17c82e).(fd, 0, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
248 return is_exec;
249 }
250
251 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! memory_file_is_executablecxx . . $ memory_file_is_executable(4be6f7de8d2c8d82).(const char* memory, const size_t size)
252 {
253 if (size < 2){
254 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; // Cannot read SHEBANG
255 }
256
257 // Check that file in memory starts with SHEBANG
258 if ( memory[0] != '#' ) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
259 if ( memory[1] != '!' ) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
260 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
261 }
262
263 xmlDoccxx . . $ xmlDoc# *oscap_source_get_xmlDoccxx . . $ oscap_source_get_xmlDoc(51aac4e66711e6e6).(struct oscap_sourcecxx . . $ oscap_source# *source)
264 {
265 // We check origin.memory first because even with it being non-NULL
266 // filepath will be non-NULL, it will contain the filepath hint.
267 struct oscap_stringcxx . . $ oscap_string# *xml_error_string = oscap_string_newcxx . . $ oscap_string_new(a2a7aea7d1de9315).();
268 xmlSetGenericErrorFunccxx . . $ xmlSetGenericErrorFunc(ca1e9f6422436c5e).(xml_error_string, (xmlGenericErrorFunccxx . . $ xmlGenericErrorFunc#)xmlErrorCbcxx . . $ xmlErrorCb(fba88424a01b5f9c).);
269
270 if (source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
271 if (source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
272 if (bz2_memory_is_bzipcxx . . $ bz2_memory_is_bzip(4be6f7de8d2c8d82).(source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory., source->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size.)) {
273 #ifdef BZIP2_FOUNDcxx . . $ `build/config.h:50:9`!
274 source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = bz2_mem_read_doccxx . . $ bz2_mem_read_doc(a702256848c0d94e).(source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory., source->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size.);
275 #else
276 oscap_seterr(OSCAP_EFAMILY_OSCAP, "Unable to unpack bz2 from buffer memory '%s'. Please compile OpenSCAP with bz2 support.", oscap_source_readable_origin(source));
277 #endif
278 } else
279 {
280 source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = xmlReadMemorycxx . . $ xmlReadMemory(be05adc870cf55a3).(source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory., source->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
281 if (source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
282 if (memory_file_is_executablecxx . . $ memory_file_is_executable(4be6f7de8d2c8d82).(source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory., source->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size.)) {
283 dIcxx . . $ `src/common/debug_priv.h:61:9`!("oscap-source in memory was detected as executable file '%s'. Skipped XML parsing", oscap_source_readable_origin(source));
284 oscap_string_clearcxx . . $ oscap_string_clear(bf7769a094bde656).(xml_error_string);
285 } else {
286 oscap_setxmlerrcxx . . $ `src/common/_error.h:36:9`!(xmlGetLastError());
287 const char *error_msg = oscap_string_get_cstrcxx . . $ oscap_string_get_cstr(4dc31ca86595c117).(xml_error_string);
288 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, "%sUnable to parse XML from user memory buffer", error_msg);
289 oscap_string_clearcxx . . $ oscap_string_clear(bf7769a094bde656).(xml_error_string);
290 }
291 }
292 }
293 }
294 else {
295 int fd = opencxx . . $ open(e156e3aa1e5c4ad1).(source->origincxx . . $ oscap_source#origin..filepathcxx . . $ oscap_source#$anonymous_type_0#filepath., O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!);
296 if ( fd == -1 ){
297 source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
298 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, "Unable to open file: '%s'", oscap_source_readable_origin(source));
299 } else {
300 if (bz2_fd_is_bzipcxx . . $ bz2_fd_is_bzip(83c267b20bac841a).(fd)) {
301 #ifdef BZIP2_FOUNDcxx . . $ `build/config.h:50:9`!
302 source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = bz2_fd_read_doccxx . . $ bz2_fd_read_doc(d2eb9631c5e91c58).(fd);
303 #else
304 source->xml.doc = NULL;
305 oscap_seterr(OSCAP_EFAMILY_OSCAP, "Unable to unpack bz2 file '%s'. Please compile OpenSCAP with bz2 support.", oscap_source_readable_origin(source));
306 #endif
307 } else
308 {
309 source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = xmlReadFdcxx . . $ xmlReadFd(ee6bae36839fdf75).(fd, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
310 if (source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
311 if (fd_file_is_executablecxx . . $ fd_file_is_executable(83c267b20bac841a).(fd)) {
312 dIcxx . . $ `src/common/debug_priv.h:61:9`!("oscap-source file was detected as executable file '%s'. Skipped XML parsing", oscap_source_readable_origin(source));
313 oscap_string_clearcxx . . $ oscap_string_clear(bf7769a094bde656).(xml_error_string);
314 } else {
315 oscap_setxmlerrcxx . . $ `src/common/_error.h:36:9`!(xmlGetLastError());
316 const char *error_msg = oscap_string_get_cstrcxx . . $ oscap_string_get_cstr(4dc31ca86595c117).(xml_error_string);
317 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, "%sUnable to parse XML at: '%s'", error_msg, oscap_source_readable_origin(source));
318 oscap_string_clearcxx . . $ oscap_string_clear(bf7769a094bde656).(xml_error_string);
319 }
320 }
321 }
322 closecxx . . $ close(7864480464b09eea).(fd);
323 }
324 }
325 }
326
327 xmlSetGenericErrorFunccxx . . $ xmlSetGenericErrorFunc(ca1e9f6422436c5e).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
328
329 if (!oscap_string_emptycxx . . $ oscap_string_empty(7916fe0434b4321e).(xml_error_string)) {
330 const char *error_msg = oscap_string_get_cstrcxx . . $ oscap_string_get_cstr(4dc31ca86595c117).(xml_error_string);
331 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, "%sFound xml error.", error_msg);
332 }
333
334 oscap_string_freecxx . . $ oscap_string_free(bf7769a094bde656).(xml_error_string);
335 return source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc.;
336 }
337
338 xmlDoccxx . . $ xmlDoc# *oscap_source_pop_xmlDoccxx . . $ oscap_source_pop_xmlDoc(51aac4e66711e6e6).(struct oscap_sourcecxx . . $ oscap_source# *source)
339 {
340 xmlDoccxx . . $ xmlDoc# *doc = oscap_source_get_xmlDoccxx . . $ oscap_source_get_xmlDoc(51aac4e66711e6e6).(source);
341 source->xmlcxx . . $ oscap_source#xml..doccxx . . $ oscap_source#$anonymous_type_1#doc. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
342 return doc;
343 }
344
345 int oscap_source_validatecxx . . $ oscap_source_validate(58e1cfedb30f1c20).(struct oscap_sourcecxx . . $ oscap_source# *source, xml_reportercxx . . $ xml_reporter# reporter, void *user)
346 {
347 int ret;
348 oscap_document_type_tcxx . . $ oscap_document_type_t# scap_type = oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(source);
349
350 if (scap_type == OSCAP_DOCUMENT_UNKNOWNcxx . . $ OSCAP_DOCUMENT_UNKNOWN.) {
351 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Unrecognized document type for: %s", oscap_source_readable_origin(source));
352 ret = -1;
353 } else {
354 const char *schema_version = oscap_source_get_schema_versioncxx . . $ oscap_source_get_schema_version(e20df36988f50e45).(source);
355 if (!schema_version) {
356 schema_version = "unknown schema version";
357 }
358 const char *type_name = oscap_document_type_to_stringcxx . . $ oscap_document_type_to_string(1cec73a42285d610).(scap_type);
359 const char *origin = oscap_source_readable_origincxx . . $ oscap_source_readable_origin(1485dc36ee4b63be).(source);
360 dDcxx . . $ `src/common/debug_priv.h:64:9`!("Validating %s (%s) document from %s.", type_name, schema_version, origin);
361 ret = oscap_source_validate_privcxx . . $ oscap_source_validate_priv(4172a4befd4189f7).(source, scap_type, schema_version, reporter, user);
362 if (ret != 0) {
363 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Invalid %s (%s) content in %s.", type_name, schema_version, origin);
364 }
365 }
366 return ret;
367 }
368
369 int oscap_source_validate_schematroncxx . . $ oscap_source_validate_schematron(a38c22d0fd42c683).(struct oscap_sourcecxx . . $ oscap_source# *source)
370 {
371 oscap_document_type_tcxx . . $ oscap_document_type_t# scap_type = oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(source);
372 const char *schema_version = oscap_source_get_schema_versioncxx . . $ oscap_source_get_schema_version(e20df36988f50e45).(source);
373 if (!schema_version) {
374 schema_version = "unknown schema version";
375 }
376 int ret = oscap_source_validate_schematron_privcxx . . $ oscap_source_validate_schematron_priv(4191b822de29fb8a).(source, scap_type, schema_version);
377 if (ret != 0) {
378 const char *type_name = oscap_document_type_to_stringcxx . . $ oscap_document_type_to_string(1cec73a42285d610).(scap_type);
379 const char *origin = oscap_source_readable_origincxx . . $ oscap_source_readable_origin(1485dc36ee4b63be).(source);
380 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Invalid %s (%s) content in %s.", type_name, schema_version, origin);
381 }
382 return ret;
383 }
384
385 const char *oscap_source_get_schema_versioncxx . . $ oscap_source_get_schema_version(e20df36988f50e45).(struct oscap_sourcecxx . . $ oscap_source# *source)
386 {
387 if (source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
388 xmlTextReadercxx . . $ xmlTextReader# *reader = oscap_source_get_xmlTextReadercxx . . $ oscap_source_get_xmlTextReader(9a7ef22a0934f79d).(source);
389 if (reader == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
390 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
391 }
392 switch (oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(source)) {
393 case OSCAP_DOCUMENT_SDScxx . . $ OSCAP_DOCUMENT_SDS.:
394 source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = ds_sds_detect_versioncxx . . $ ds_sds_detect_version(93c99f8009311dd0).(reader);
395 break;
396 case OSCAP_DOCUMENT_ARFcxx . . $ OSCAP_DOCUMENT_ARF.:
397 source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).("1.1");
398 break;
399 case OSCAP_DOCUMENT_OVAL_DEFINITIONScxx . . $ OSCAP_DOCUMENT_OVAL_DEFINITIONS.:
400 case OSCAP_DOCUMENT_OVAL_VARIABLEScxx . . $ OSCAP_DOCUMENT_OVAL_VARIABLES.:
401 case OSCAP_DOCUMENT_OVAL_DIRECTIVEScxx . . $ OSCAP_DOCUMENT_OVAL_DIRECTIVES.:
402 case OSCAP_DOCUMENT_OVAL_SYSCHARcxx . . $ OSCAP_DOCUMENT_OVAL_SYSCHAR.:
403 case OSCAP_DOCUMENT_OVAL_RESULTScxx . . $ OSCAP_DOCUMENT_OVAL_RESULTS.:
404 source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = oval_determine_document_schema_version_privcxx . . $ oval_determine_document_schema_version_priv(87e9f2ea92df6ee9).(
405 reader, oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(source));
406 break;
407 case OSCAP_DOCUMENT_XCCDFcxx . . $ OSCAP_DOCUMENT_XCCDF.:
408 case OSCAP_DOCUMENT_XCCDF_TAILORINGcxx . . $ OSCAP_DOCUMENT_XCCDF_TAILORING.:
409 source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = xccdf_detect_version_privcxx . . $ xccdf_detect_version_priv(93c99f8009311dd0).(reader);
410 break;
411 case OSCAP_DOCUMENT_CPE_DICTIONARYcxx . . $ OSCAP_DOCUMENT_CPE_DICTIONARY.:
412 source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = cpe_dict_detect_version_privcxx . . $ cpe_dict_detect_version_priv(93c99f8009311dd0).(reader);
413 break;
414 case OSCAP_DOCUMENT_CPE_LANGUAGEcxx . . $ OSCAP_DOCUMENT_CPE_LANGUAGE.:
415 source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = cpe_lang_model_detect_version_privcxx . . $ cpe_lang_model_detect_version_priv(93c99f8009311dd0).(reader);
416 break;
417 case OSCAP_DOCUMENT_SCE_RESULTcxx . . $ OSCAP_DOCUMENT_SCE_RESULT.:
418 source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).("1.0");
419 break;
420 case OSCAP_DOCUMENT_OCILcxx . . $ OSCAP_DOCUMENT_OCIL.:
421 source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).("2.0");
422 break;
423 default:
424 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Could not determine origin.version for document %s: Unknown type: %s",
425 oscap_source_readable_origin(source),
426 oscap_document_type_to_string(oscap_source_get_scap_type(source)));
427 break;
428 }
429 xmlFreeTextReadercxx . . $ xmlFreeTextReader(724dbfdba9ec3ce8).(reader);
430 }
431 return source->origincxx . . $ oscap_source#origin..versioncxx . . $ oscap_source#$anonymous_type_0#version.;
432 }
433
434 int oscap_source_save_ascxx . . $ oscap_source_save_as(b44a10f6a0e05d3e).(struct oscap_sourcecxx . . $ oscap_source# *source, const char *filename)
435 {
436 // TODO: This assumes XML and xmlDoc being available
437 const char *target = filename != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ? filename : oscap_source_readable_origincxx . . $ oscap_source_readable_origin(1485dc36ee4b63be).(source);
438 xmlDoccxx . . $ xmlDoc# *doc = oscap_source_get_xmlDoccxx . . $ oscap_source_get_xmlDoc(51aac4e66711e6e6).(source);
439 if (doc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
440 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Could not save document to %s: DOM representation not available.", target);
441 return -1;
442 }
443 return oscap_xml_save_filenamecxx . . $ oscap_xml_save_filename(4641885591a9fcee).(target, doc) == 1 ? 0 : -1;
444 }
445
446 int oscap_source_to_fdcxx . . $ oscap_source_to_fd(3c83cdd1dab7bcdf).(struct oscap_sourcecxx . . $ oscap_source# *source, int fd)
447 {
448 xmlDoccxx . . $ xmlDoc# *doc = oscap_source_get_xmlDoccxx . . $ oscap_source_get_xmlDoc(51aac4e66711e6e6).(source);
449 if (doc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
450 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Could not save document: DOM representation not available.");
451 return -1;
452 }
453 return oscap_xml_save_fdcxx . . $ oscap_xml_save_fd(1ac6e7a5d64265a7).(fd, doc) == 1 ? 0 : -1;
454
455 }
456
457 int oscap_source_get_raw_memorycxx . . $ oscap_source_get_raw_memory(c17bb729b188260b).(struct oscap_sourcecxx . . $ oscap_source# *source, char **buffer, size_t *size)
458 {
459 if (source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
460 char *ret = (char*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(source->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size.);
461 memcpycxx . . $ memcpy(cc817cb175f282d).(ret, source->origincxx . . $ oscap_source#origin..memorycxx . . $ oscap_source#$anonymous_type_0#memory., source->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size.);
462 *buffer = ret;
463 *size = source->origincxx . . $ oscap_source#origin..memory_sizecxx . . $ oscap_source#$anonymous_type_0#memory_size.;
464 return 0;
465 }
466 else {
467 xmlDoccxx . . $ xmlDoc# *doc = oscap_source_get_xmlDoccxx . . $ oscap_source_get_xmlDoc(51aac4e66711e6e6).(source);
468
469 if (doc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
470 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!,
471 "Can't retrieve raw memory. Given oscap_source doesn't originate from "
472 "raw memory and xmlDoc isn't available.");
473 return 1;
474 }
475
476 // libxml2 asks us to use xmlFree on the returned buffer,
477 // free works fine however. Instead of doing a memory copy dance
478 // here we just let libxml2 fill the buffer.
479 // However int and size_t can be different so we do the safe thing.
480 int isize = 0;
481 xmlDocDumpMemorycxx . . $ xmlDocDumpMemory(83f86c903c6ff59a).(doc, (xmlCharcxx . . $ xmlChar#**)buffer, &isize);
482 *size = isize;
483 return 0;
484 }
485 }