Debian Codegraph @

src/OVAL/oval_session.c

raw symbols SCIP
1 /*
2 * Copyright 2015 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 * Michal Šrubař <[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 #ifdef OS_WINDOWS
28 #include <io.h>
29 #else
30 #include <unistd.h>
31 #endif
32 #include <string.h>
33 #if defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!)
34 #include <linux/limits.h>
35 #endif
36 #include <limits.h>
37
38 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
39 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
40 #include "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/
41 #include "common/oscapxml.h"cxx . . $ `<file>/src/common/oscapxml.h`/
42 #include "source/xslt_priv.h"cxx . . $ `<file>/src/source/xslt_priv.h`/
43 #include "public/oval_agent_api.h"cxx . . $ `<file>/src/OVAL/public/oval_agent_api.h`/
44 #include "public/oval_session.h"cxx . . $ `<file>/src/OVAL/public/oval_session.h`/
45 #include "../DS/public/ds_sds_session.h"cxx . . $ `<file>/src/DS/public/ds_sds_session.h`/
46 #include "oscap_source.h"cxx . . $ `<file>/src/source/public/oscap_source.h`/
47 #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/
48
49
50 static const char *oscap_productnamecxx . . $ oscap_productname. = "cpe:/a:open-scap:oscap";
51 static const char *oval_results_reportcxx . . $ oval_results_report. = "oval-results-report.xsl";
52
53 struct oval_sessioncxx . . $ oval_session# {
54 /* Main source assigned with the main file (SDS or OVAL) */
55 struct oscap_sourcecxx . . $ oscap_source# *sourcecxx . . $ oval_session#source.;
56 struct oval_definition_modelcxx . . $ oval_definition_model# *def_modelcxx . . $ oval_session#def_model.;
57 struct oval_variable_modelcxx . . $ oval_variable_model# *var_modelcxx . . $ oval_session#var_model.;
58 struct oval_results_modelcxx . . $ oval_results_model# *res_modelcxx . . $ oval_session#res_model.;
59
60 oval_agent_session_tcxx . . $ oval_agent_session_t# *sesscxx . . $ oval_session#sess.;
61 struct ds_sds_sessioncxx . . $ ds_sds_session# *sds_sessioncxx . . $ oval_session#sds_session.;
62
63 structcxx . . $ oval_session#$anonymous_type_0# {
64 struct oscap_sourcecxx . . $ oscap_source# *definitionscxx . . $ oval_session#$anonymous_type_0#definitions.;
65 struct oscap_sourcecxx . . $ oscap_source# *variablescxx . . $ oval_session#$anonymous_type_0#variables.;
66 struct oscap_sourcecxx . . $ oscap_source# *directivescxx . . $ oval_session#$anonymous_type_0#directives.;
67 } ovalcxx . . $ oval_session#oval.;
68
69 char *datastream_idcxx . . $ oval_session#datastream_id.;
70 /* particular OVAL component if there are two OVALs in one datastream */
71 char *component_idcxx . . $ oval_session#component_id.;
72
73 structcxx . . $ oval_session#$anonymous_type_1# {
74 char *resultscxx . . $ oval_session#$anonymous_type_1#results.;
75 char *reportcxx . . $ oval_session#$anonymous_type_1#report.;
76 } exportcxx . . $ oval_session#export.;
77
78 structcxx . . $ oval_session#$anonymous_type_2# {
79 /* it's called when there is something invalid in input/output files */
80 xml_reportercxx . . $ xml_reporter# xml_fncxx . . $ oval_session#$anonymous_type_2#xml_fn.;
81 } reportercxx . . $ oval_session#reporter.;
82
83 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! validationcxx . . $ oval_session#validation.;
84 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! export_sys_charscxx . . $ oval_session#export_sys_chars.;
85 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! full_validationcxx . . $ oval_session#full_validation.;
86 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! fetch_remote_resourcescxx . . $ oval_session#fetch_remote_resources.;
87 download_progress_calllback_tcxx . . $ download_progress_calllback_t# progresscxx . . $ oval_session#progress.;
88 const char *local_filescxx . . $ oval_session#local_files.;
89 };
90
91 struct oval_sessioncxx . . $ oval_session# *oval_session_newcxx . . $ oval_session_new(7e5bcee7aed03c6).(const char *filename)
92 {
93 oscap_document_type_tcxx . . $ oscap_document_type_t# scap_type;
94 struct oval_sessioncxx . . $ oval_session# *session;
95
96 session = (struct oval_sessioncxx . . $ oval_session# *) calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct oval_sessioncxx . . $ oval_session#));
97
98 session->sourcecxx . . $ oval_session#source. = oscap_source_new_from_filecxx . . $ oscap_source_new_from_file(987f8b70a317ffb9).(filename);
99 if ((scap_type = oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(session->sourcecxx . . $ oval_session#source.)) == OSCAP_DOCUMENT_UNKNOWNcxx . . $ OSCAP_DOCUMENT_UNKNOWN.) {
100 oval_session_freecxx . . $ oval_session_free(11614b9dd32fc055).(session);
101 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
102 }
103
104 if (scap_type != OSCAP_DOCUMENT_OVAL_DEFINITIONScxx . . $ OSCAP_DOCUMENT_OVAL_DEFINITIONS. && scap_type != OSCAP_DOCUMENT_SDScxx . . $ OSCAP_DOCUMENT_SDS.) {
105 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Session input file was determined but it"
106 " isn't an OVAL file nor a source datastream file.");
107 oval_session_freecxx . . $ oval_session_free(11614b9dd32fc055).(session);
108 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
109 }
110
111 session->export_sys_charscxx . . $ oval_session#export_sys_chars. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
112
113 dIcxx . . $ `src/common/debug_priv.h:61:9`!("Created a new OVAL session from input file '%s'.", filename);
114 return session;
115 }
116
117 void oval_session_set_variablescxx . . $ oval_session_set_variables(c30ebac49622957).(struct oval_sessioncxx . . $ oval_session# *session, const char *filename)
118 {
119 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
120
121 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(session->ovalcxx . . $ oval_session#oval..variablescxx . . $ oval_session#$anonymous_type_0#variables.);
122
123 if (filename != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
124 session->ovalcxx . . $ oval_session#oval..variablescxx . . $ oval_session#$anonymous_type_0#variables. = oscap_source_new_from_filecxx . . $ oscap_source_new_from_file(987f8b70a317ffb9).(filename);
125 else
126 session->ovalcxx . . $ oval_session#oval..variablescxx . . $ oval_session#$anonymous_type_0#variables. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; /* reset */
127 }
128
129 void oval_session_set_directivescxx . . $ oval_session_set_directives(c30ebac49622957).(struct oval_sessioncxx . . $ oval_session# *session, const char *filename)
130 {
131 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
132
133 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(session->ovalcxx . . $ oval_session#oval..directivescxx . . $ oval_session#$anonymous_type_0#directives.);
134
135 if (filename != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
136 session->ovalcxx . . $ oval_session#oval..directivescxx . . $ oval_session#$anonymous_type_0#directives. = oscap_source_new_from_filecxx . . $ oscap_source_new_from_file(987f8b70a317ffb9).(filename);
137 else
138 session->ovalcxx . . $ oval_session#oval..directivescxx . . $ oval_session#$anonymous_type_0#directives. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
139 }
140
141 void oval_session_set_validationcxx . . $ oval_session_set_validation(94f71ae260bf6161).(struct oval_sessioncxx . . $ oval_session# *session, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! validate, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! full_validation)
142 {
143 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
144
145 session->validationcxx . . $ oval_session#validation. = validate;
146 session->full_validationcxx . . $ oval_session#full_validation. = full_validation;
147 }
148
149 void oval_session_set_datastream_idcxx . . $ oval_session_set_datastream_id(c30ebac49622957).(struct oval_sessioncxx . . $ oval_session# *session, const char *id)
150 {
151 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
152
153 freecxx . . $ free(5d22bdacc48458e8).(session->datastream_idcxx . . $ oval_session#datastream_id.);
154 session->datastream_idcxx . . $ oval_session#datastream_id. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(id);
155 }
156
157 void oval_session_set_component_idcxx . . $ oval_session_set_component_id(c30ebac49622957).(struct oval_sessioncxx . . $ oval_session# *session, const char *id)
158 {
159 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
160
161 freecxx . . $ free(5d22bdacc48458e8).(session->component_idcxx . . $ oval_session#component_id.);
162 session->component_idcxx . . $ oval_session#component_id. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(id);
163 }
164
165 void oval_session_set_results_exportcxx . . $ oval_session_set_results_export(c30ebac49622957).(struct oval_sessioncxx . . $ oval_session# *session, const char *filename)
166 {
167 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
168
169 freecxx . . $ free(5d22bdacc48458e8).(session->exportcxx . . $ oval_session#export..resultscxx . . $ oval_session#$anonymous_type_1#results.);
170 session->exportcxx . . $ oval_session#export..resultscxx . . $ oval_session#$anonymous_type_1#results. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(filename);
171 }
172
173 void oval_session_set_report_exportcxx . . $ oval_session_set_report_export(c30ebac49622957).(struct oval_sessioncxx . . $ oval_session# *session, const char *filename)
174 {
175 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
176
177 freecxx . . $ free(5d22bdacc48458e8).(session->exportcxx . . $ oval_session#export..reportcxx . . $ oval_session#$anonymous_type_1#report.);
178 session->exportcxx . . $ oval_session#export..reportcxx . . $ oval_session#$anonymous_type_1#report. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(filename);
179 }
180
181 void oval_session_set_xml_reportercxx . . $ oval_session_set_xml_reporter(bd6c795d022aee50).(struct oval_sessioncxx . . $ oval_session# *session, xml_reportercxx . . $ xml_reporter# fn)
182 {
183 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
184
185 session->reportercxx . . $ oval_session#reporter..xml_fncxx . . $ oval_session#$anonymous_type_2#xml_fn. = fn;
186 }
187
188 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! oval_session_validatecxx . . $ oval_session_validate(ad70a7d8ad38ab81).(struct oval_sessioncxx . . $ oval_session# *session, struct oscap_sourcecxx . . $ oscap_source# *source, oscap_document_type_tcxx . . $ oscap_document_type_t# type)
189 {
190 if (oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(source) == type) {
191 if (oscap_source_validatecxx . . $ oscap_source_validate(58e1cfedb30f1c20).(source, session->reportercxx . . $ oval_session#reporter..xml_fncxx . . $ oval_session#$anonymous_type_2#xml_fn., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!))
192 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
193 }
194 else {
195 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "Type mismatch: %s. Expecting %s "
196 "but found %s.", oscap_source_readable_origin(source),
197 oscap_document_type_to_string(type),
198 oscap_document_type_to_string(oscap_source_get_scap_type(source)));
199 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
200 }
201
202 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
203 }
204
205 static int oval_session_load_definitionscxx . . $ oval_session_load_definitions(f27a3c4c3b1f0f09).(struct oval_sessioncxx . . $ oval_session# *session)
206 {
207 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
208 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session->source);
209
210 oscap_document_type_tcxx . . $ oscap_document_type_t# type = oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(session->sourcecxx . . $ oval_session#source.);
211 if (type != OSCAP_DOCUMENT_OVAL_DEFINITIONScxx . . $ OSCAP_DOCUMENT_OVAL_DEFINITIONS. && type != OSCAP_DOCUMENT_SDScxx . . $ OSCAP_DOCUMENT_SDS.) {
212 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "Type mismatch: %s. Expecting %s "
213 "or %s but found %s.", oscap_source_readable_origin(session->source),
214 oscap_document_type_to_string(OSCAP_DOCUMENT_OVAL_DEFINITIONS),
215 oscap_document_type_to_string(OSCAP_DOCUMENT_SDS),
216 oscap_document_type_to_string(type));
217 return 1;
218 }
219 else {
220 if (session->validationcxx . . $ oval_session#validation. && !oval_session_validatecxx . . $ oval_session_validate(ad70a7d8ad38ab81).(session, session->sourcecxx . . $ oval_session#source., type))
221 return 1;
222 }
223
224 if (oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(session->sourcecxx . . $ oval_session#source.) == OSCAP_DOCUMENT_SDScxx . . $ OSCAP_DOCUMENT_SDS.) {
225 if ((session->sds_sessioncxx . . $ oval_session#sds_session. = ds_sds_session_new_from_sourcecxx . . $ ds_sds_session_new_from_source(84081d5e8394044f).(session->sourcecxx . . $ oval_session#source.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
226 return 1;
227 }
228 ds_sds_session_configure_remote_resourcescxx . . $ ds_sds_session_configure_remote_resources(61c5f4052dda9a0f).(session->sds_sessioncxx . . $ oval_session#sds_session., session->fetch_remote_resourcescxx . . $ oval_session#fetch_remote_resources., session->local_filescxx . . $ oval_session#local_files., session->progresscxx . . $ oval_session#progress.);
229 ds_sds_session_set_datastream_idcxx . . $ ds_sds_session_set_datastream_id(d40402bb7044504c).(session->sds_sessioncxx . . $ oval_session#sds_session., session->datastream_idcxx . . $ oval_session#datastream_id.);
230 if (ds_sds_session_register_component_with_dependenciescxx . . $ ds_sds_session_register_component_with_dependencies(2e27e35b07e9ac87).(session->sds_sessioncxx . . $ oval_session#sds_session.,
231 "checks", session->component_idcxx . . $ oval_session#component_id., "oval.xml") != 0) {
232 return 1;
233 }
234
235 session->ovalcxx . . $ oval_session#oval..definitionscxx . . $ oval_session#$anonymous_type_0#definitions. = ds_sds_session_get_component_by_hrefcxx . . $ ds_sds_session_get_component_by_href(46a19ef06873a4cc).(session->sds_sessioncxx . . $ oval_session#sds_session., "oval.xml");
236 if (session->ovalcxx . . $ oval_session#oval..definitionscxx . . $ oval_session#$anonymous_type_0#definitions. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
237 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "Internal error: OVAL file was not found in "
238 "Source DataStream session cache!");
239 return 1;
240 }
241 }
242 else {
243 session->ovalcxx . . $ oval_session#oval..definitionscxx . . $ oval_session#$anonymous_type_0#definitions. = session->sourcecxx . . $ oval_session#source.;
244 }
245
246 /* import OVAL Definitions */
247 if (session->def_modelcxx . . $ oval_session#def_model.) oval_definition_model_freecxx . . $ oval_definition_model_free(fd0cd5af216bd200).(session->def_modelcxx . . $ oval_session#def_model.);
248 session->def_modelcxx . . $ oval_session#def_model. = oval_definition_model_import_sourcecxx . . $ oval_definition_model_import_source(5c1ce95823108a2f).(session->ovalcxx . . $ oval_session#oval..definitionscxx . . $ oval_session#$anonymous_type_0#definitions.);
249 if (session->def_modelcxx . . $ oval_session#def_model. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
250 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "Failed to import the OVAL Definitions from '%s'.",
251 oscap_source_readable_origin(session->oval.definitions));
252 return 1;
253 }
254
255 return 0;
256 }
257
258 static int oval_session_load_variablescxx . . $ oval_session_load_variables(f27a3c4c3b1f0f09).(struct oval_sessioncxx . . $ oval_session# *session)
259 {
260 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
261
262 if (session->ovalcxx . . $ oval_session#oval..variablescxx . . $ oval_session#$anonymous_type_0#variables. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
263
264 if (session->def_modelcxx . . $ oval_session#def_model. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
265 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "No OVAL Definitions to bind the variables to.");
266 return 1;
267 }
268 if (session->validationcxx . . $ oval_session#validation. && !oval_session_validatecxx . . $ oval_session_validate(ad70a7d8ad38ab81).(session, session->ovalcxx . . $ oval_session#oval..variablescxx . . $ oval_session#$anonymous_type_0#variables., OSCAP_DOCUMENT_OVAL_VARIABLEScxx . . $ OSCAP_DOCUMENT_OVAL_VARIABLES.)) {
269 return 1;
270 }
271
272 /* bind external variables */
273 if (session->ovalcxx . . $ oval_session#oval..variablescxx . . $ oval_session#$anonymous_type_0#variables.) {
274 session->var_modelcxx . . $ oval_session#var_model. = oval_variable_model_import_sourcecxx . . $ oval_variable_model_import_source(46e0a903906bd39).(session->ovalcxx . . $ oval_session#oval..variablescxx . . $ oval_session#$anonymous_type_0#variables.);
275
276 if (session->var_modelcxx . . $ oval_session#var_model. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
277 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "Failed to import the OVAL Variables "
278 "from '%s'.", oscap_source_get_filepath(session->oval.variables));
279 return 1;
280 }
281
282 if (oval_definition_model_bind_variable_modelcxx . . $ oval_definition_model_bind_variable_model(92d91b6d8ac81b76).(session->def_modelcxx . . $ oval_session#def_model., session->var_modelcxx . . $ oval_session#var_model.)) {
283 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "Failed to bind Variables to Definitions.");
284 return 1;
285 }
286 }
287 dIcxx . . $ `src/common/debug_priv.h:61:9`!("Loaded OVAL variables.");
288 } else {
289 dIcxx . . $ `src/common/debug_priv.h:61:9`!("No external OVAL variables provided.");
290 }
291
292 return 0;
293 }
294
295 int oval_session_loadcxx . . $ oval_session_load(f27a3c4c3b1f0f09).(struct oval_sessioncxx . . $ oval_session# *session)
296 {
297 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
298
299 int ret = 0;
300
301 if ((ret = oval_session_load_definitionscxx . . $ oval_session_load_definitions(f27a3c4c3b1f0f09).(session)) != 0) {
302 return ret;
303 }
304 if ((ret = oval_session_load_variablescxx . . $ oval_session_load_variables(f27a3c4c3b1f0f09).(session)) != 0) {
305 return ret;
306 }
307
308 return ret;
309 }
310
311 static int oval_session_setup_agentcxx . . $ oval_session_setup_agent(f27a3c4c3b1f0f09).(struct oval_sessioncxx . . $ oval_session# *session)
312 {
313 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
314
315 char *path_clone;
316
317 path_clone = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(oscap_source_readable_origincxx . . $ oscap_source_readable_origin(1485dc36ee4b63be).(session->ovalcxx . . $ oval_session#oval..definitionscxx . . $ oval_session#$anonymous_type_0#definitions.));
318 if (path_clone == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
319 return 1;
320 }
321
322 /* free the previous Agent session if this function was already called */
323 if (session->sesscxx . . $ oval_session#sess.)
324 oval_agent_destroy_sessioncxx . . $ oval_agent_destroy_session(627ebdc30b34a70a).(session->sesscxx . . $ oval_session#sess.);
325
326 char *base_name = oscap_basenamecxx . . $ oscap_basename(7a9722d75b371431).(path_clone);
327 session->sesscxx . . $ oval_session#sess. = oval_agent_new_sessioncxx . . $ oval_agent_new_session(ca85c20b742af0f5).(session->def_modelcxx . . $ oval_session#def_model., base_name);
328 freecxx . . $ free(5d22bdacc48458e8).(base_name);
329 if (session->sesscxx . . $ oval_session#sess. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
330 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "Failed to create a new agent session.");
331 freecxx . . $ free(5d22bdacc48458e8).(path_clone);
332 return 1;
333 }
334 freecxx . . $ free(5d22bdacc48458e8).(path_clone);
335
336 oval_agent_set_product_namecxx . . $ oval_agent_set_product_name(4646a8b4d8a0fdcf).(session->sesscxx . . $ oval_session#sess., (char *)oscap_productnamecxx . . $ oscap_productname.);
337 return 0;
338 }
339
340 int oval_session_evaluate_idcxx . . $ oval_session_evaluate_id(b26c66e0bbe4a772).(struct oval_sessioncxx . . $ oval_session# *session, const char *id, oval_result_tcxx . . $ oval_result_t# *result)
341 {
342 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
343
344 if (id == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
345 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "No OVAL Definion id set.");
346 return 1;
347 }
348
349 if (oval_session_setup_agentcxx . . $ oval_session_setup_agent(f27a3c4c3b1f0f09).(session) != 0) {
350 return 1;
351 }
352
353 oval_agent_eval_definitioncxx . . $ oval_agent_eval_definition(f96e825d70a43f1e).(session->sesscxx . . $ oval_session#sess., id);
354 *result = OVAL_RESULT_NOT_EVALUATEDcxx . . $ OVAL_RESULT_NOT_EVALUATED.;
355 oval_agent_get_definition_resultcxx . . $ oval_agent_get_definition_result(16f71d6dbd2ef110).(session->sesscxx . . $ oval_session#sess., id, result);
356 if (oscap_errcxx . . $ oscap_err(c9857a73d68e59ba).()) {
357 return 1;
358 }
359
360 session->res_modelcxx . . $ oval_session#res_model. = oval_agent_get_results_modelcxx . . $ oval_agent_get_results_model(8b7d7187bb31542e).(session->sesscxx . . $ oval_session#sess.);
361
362 return 0;
363 }
364
365 int oval_session_evaluatecxx . . $ oval_session_evaluate(64e19f7148ea5ac9).(struct oval_sessioncxx . . $ oval_session# *session, agent_reportercxx . . $ agent_reporter# fn, void *arg)
366 {
367 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
368
369 if (oval_session_setup_agentcxx . . $ oval_session_setup_agent(f27a3c4c3b1f0f09).(session) != 0) {
370 return 1;
371 }
372
373 oval_agent_eval_systemcxx . . $ oval_agent_eval_system(2f09aee744ea6d81).(session->sesscxx . . $ oval_session#sess., fn, arg);
374 if (oscap_errcxx . . $ oscap_err(c9857a73d68e59ba).()) {
375 return 1;
376 }
377
378 session->res_modelcxx . . $ oval_session#res_model. = oval_agent_get_results_modelcxx . . $ oval_agent_get_results_model(8b7d7187bb31542e).(session->sesscxx . . $ oval_session#sess.);
379
380 dIcxx . . $ `src/common/debug_priv.h:61:9`!("OVAL evaluation successfully finished.");
381 return 0;
382 }
383
384 int oval_session_exportcxx . . $ oval_session_export(f27a3c4c3b1f0f09).(struct oval_sessioncxx . . $ oval_session# *session)
385 {
386 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(session);
387
388 struct oval_directives_modelcxx . . $ oval_directives_model# *dir_model = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
389 struct oscap_sourcecxx . . $ oscap_source# *result = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; /* OVAL Results */
390 const char *filename = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
391 int ret = 0;
392
393 /* Import OVAL Directives if any */
394 if (session->ovalcxx . . $ oval_session#oval..directivescxx . . $ oval_session#$anonymous_type_0#directives. && session->res_modelcxx . . $ oval_session#res_model.) {
395 /* OVAL Directives can be used only if there are OVAL Resutls and these are
396 * only available if there is a Results model which mean that either
397 * evaluation or analyse was performed. */
398 dir_model = oval_directives_model_newcxx . . $ oval_directives_model_new(3f85e657173754f7).();
399 if (oval_directives_model_import_sourcecxx . . $ oval_directives_model_import_source(a58cf06db02a42f2).(dir_model, session->ovalcxx . . $ oval_session#oval..directivescxx . . $ oval_session#$anonymous_type_0#directives.) != 0)
400 goto cleanup;
401 }
402
403 /* Get OVAL Results if evaluation or analyse has been done and apply
404 * directives to them */
405 if (session->res_modelcxx . . $ oval_session#res_model. && (session->exportcxx . . $ oval_session#export..resultscxx . . $ oval_session#$anonymous_type_1#results. || session->exportcxx . . $ oval_session#export..reportcxx . . $ oval_session#$anonymous_type_1#report.)) {
406 oval_results_model_set_export_system_characteristicscxx . . $ oval_results_model_set_export_system_characteristics(6f36610d00c3f37a).(session->res_modelcxx . . $ oval_session#res_model., session->export_sys_charscxx . . $ oval_session#export_sys_chars.);
407 result = oval_results_model_export_sourcecxx . . $ oval_results_model_export_source(e532d9403ded9eaf).(session->res_modelcxx . . $ oval_session#res_model., dir_model, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
408 filename = session->exportcxx . . $ oval_session#export..resultscxx . . $ oval_session#$anonymous_type_1#results.;
409 }
410
411 /* Validate OVAL Results. The 'result' in condition will make sure that there is
412 * something to validate */
413 if (result && session->validationcxx . . $ oval_session#validation. && session->full_validationcxx . . $ oval_session#full_validation.) {
414 if (!oval_session_validatecxx . . $ oval_session_validate(ad70a7d8ad38ab81).(session, result, OSCAP_DOCUMENT_OVAL_RESULTScxx . . $ OSCAP_DOCUMENT_OVAL_RESULTS.))
415 goto cleanup;
416 }
417
418 if (session->exportcxx . . $ oval_session#export..resultscxx . . $ oval_session#$anonymous_type_1#results. && result) { /* export to XML */
419 if (oscap_source_save_ascxx . . $ oscap_source_save_as(b44a10f6a0e05d3e).(result, filename) != 0)
420 goto cleanup;
421 }
422
423 if (session->exportcxx . . $ oval_session#export..reportcxx . . $ oval_session#$anonymous_type_1#report. && result) { /* export to HTML */
424 char pwd[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
425
426 if (getcwdcxx . . $ getcwd(dff97f9eb74e1544).(pwd, sizeof(pwd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
427 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, "ERROR: %s", strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
428 goto cleanup;
429 }
430
431 /* add params oscap-version & pwd */
432 const char *stdparams[] = { "oscap-version", oscap_get_versioncxx . . $ oscap_get_version(33a1f659e94feb42).(), "pwd", pwd, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! };
433
434 /* TODO: let the user set the xsl by oval_session_set_report_xsl? */
435 if (oscap_source_apply_xslt_pathcxx . . $ oscap_source_apply_xslt_path(55db94cfa4db2719).(result, oval_results_reportcxx . . $ oval_results_report.,
436 session->exportcxx . . $ oval_session#export..reportcxx . . $ oval_session#$anonymous_type_1#report., stdparams, oscap_path_to_xsltcxx . . $ oscap_path_to_xslt(33a1f659e94feb42).()) == -1) {
437 goto cleanup;
438 }
439 }
440
441 ret = 0; /* successfull export */
442
443 cleanup:
444 if (result)
445 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(result);
446 if (dir_model)
447 oval_directives_model_freecxx . . $ oval_directives_model_free(89931e7170a08f7).(dir_model);
448 return ret;
449 }
450
451 void oval_session_set_export_system_characteristicscxx . . $ oval_session_set_export_system_characteristics(70bc3799e9300764).(struct oval_sessioncxx . . $ oval_session# *session, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! export)
452 {
453 session->export_sys_charscxx . . $ oval_session#export_sys_chars. = export;
454 }
455
456 void oval_session_configure_remote_resourcescxx . . $ oval_session_configure_remote_resources(aff8698e1152fdfc).(struct oval_sessioncxx . . $ oval_session# *session, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! allowed, const char *local_files, download_progress_calllback_tcxx . . $ download_progress_calllback_t# callback)
457 {
458 session->fetch_remote_resourcescxx . . $ oval_session#fetch_remote_resources. = allowed;
459 session->local_filescxx . . $ oval_session#local_files. = local_files;
460 session->progresscxx . . $ oval_session#progress. = callback;
461 }
462
463 void oval_session_set_remote_resourcescxx . . $ oval_session_set_remote_resources(6e598ed31969247c).(struct oval_sessioncxx . . $ oval_session# *session, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! allowed, download_progress_calllback_tcxx . . $ download_progress_calllback_t# callback)
464 {
465 oval_session_configure_remote_resourcescxx . . $ oval_session_configure_remote_resources(aff8698e1152fdfc).(session, allowed, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, callback);
466 }
467
468 void oval_session_freecxx . . $ oval_session_free(11614b9dd32fc055).(struct oval_sessioncxx . . $ oval_session# *session)
469 {
470 if (session == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
471 return;
472
473 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(session->ovalcxx . . $ oval_session#oval..directivescxx . . $ oval_session#$anonymous_type_0#directives.);
474 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(session->ovalcxx . . $ oval_session#oval..variablescxx . . $ oval_session#$anonymous_type_0#variables.);
475 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(session->sourcecxx . . $ oval_session#source.);
476 freecxx . . $ free(5d22bdacc48458e8).(session->datastream_idcxx . . $ oval_session#datastream_id.);
477 freecxx . . $ free(5d22bdacc48458e8).(session->component_idcxx . . $ oval_session#component_id.);
478 freecxx . . $ free(5d22bdacc48458e8).(session->exportcxx . . $ oval_session#export..resultscxx . . $ oval_session#$anonymous_type_1#results.);
479 freecxx . . $ free(5d22bdacc48458e8).(session->exportcxx . . $ oval_session#export..reportcxx . . $ oval_session#$anonymous_type_1#report.);
480 if (session->sesscxx . . $ oval_session#sess.)
481 oval_agent_destroy_sessioncxx . . $ oval_agent_destroy_session(627ebdc30b34a70a).(session->sesscxx . . $ oval_session#sess.);
482 if (session->def_modelcxx . . $ oval_session#def_model.)
483 oval_definition_model_freecxx . . $ oval_definition_model_free(fd0cd5af216bd200).(session->def_modelcxx . . $ oval_session#def_model.);
484 ds_sds_session_freecxx . . $ ds_sds_session_free(41ab223cf3ccc737).(session->sds_sessioncxx . . $ oval_session#sds_session.);
485 freecxx . . $ free(5d22bdacc48458e8).(session);
486 }