Debian Codegraph @

src/CPE/cpe_session.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 "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/
28 #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/
29 #include "common/public/oscap.h"cxx . . $ `<file>/src/common/public/oscap.h`/
30 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
31 #include "cpe_session_priv.h"cxx . . $ `<file>/src/CPE/cpe_session_priv.h`/
32 #include "CPE/public/cpe_dict.h"cxx . . $ `<file>/src/CPE/public/cpe_dict.h`/
33 #include "CPE/public/cpe_lang.h"cxx . . $ `<file>/src/CPE/public/cpe_lang.h`/
34 #include "OVAL/public/oval_agent_api.h"cxx . . $ `<file>/src/OVAL/public/oval_agent_api.h`/
35 #include "source/public/oscap_source.h"cxx . . $ `<file>/src/source/public/oscap_source.h`/
36 #include "source/oscap_source_priv.h"cxx . . $ `<file>/src/source/oscap_source_priv.h`/
37 #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/
38
39 static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_session_add_default_cpecxx . . $ cpe_session_add_default_cpe(ab2ec83eb540b3a9).(struct cpe_sessioncxx . . $ cpe_session# *session)
40 {
41 char* cpe_dict_path = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%s/openscap-cpe-dict.xml", oscap_path_to_cpecxx . . $ oscap_path_to_cpe(33a1f659e94feb42).());
42 struct oscap_sourcecxx . . $ oscap_source# *source = oscap_source_new_from_filecxx . . $ oscap_source_new_from_file(987f8b70a317ffb9).(cpe_dict_path);
43 freecxx . . $ free(5d22bdacc48458e8).(cpe_dict_path);
44 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ret = cpe_session_add_cpe_dict_sourcecxx . . $ cpe_session_add_cpe_dict_source(4af268f3de6d9870).(session, source);
45 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(source);
46 return ret;
47 }
48
49 struct cpe_sessioncxx . . $ cpe_session# *cpe_session_newcxx . . $ cpe_session_new(4e53726e2e033d05).(void)
50 {
51 struct cpe_sessioncxx . . $ cpe_session# *cpe = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct cpe_sessioncxx . . $ cpe_session#));
52 cpe->dictscxx . . $ cpe_session#dicts. = oscap_list_newcxx . . $ oscap_list_new(ea215f73c8361bff).();
53 cpe->lang_modelscxx . . $ cpe_session#lang_models. = oscap_list_newcxx . . $ oscap_list_new(ea215f73c8361bff).();
54 cpe->oval_sessionscxx . . $ cpe_session#oval_sessions. = oscap_htable_newcxx . . $ oscap_htable_new(3c1cb2b6f390ad38).();
55 cpe->applicable_platformscxx . . $ cpe_session#applicable_platforms. = oscap_htable_newcxx . . $ oscap_htable_new(3c1cb2b6f390ad38).();
56 cpe->thin_resultscxx . . $ cpe_session#thin_results. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
57 if (!cpe_session_add_default_cpecxx . . $ cpe_session_add_default_cpe(ab2ec83eb540b3a9).(cpe)) {
58 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_XCCDFcxx . . $ `src/common/public/oscap_error.h:62:9`!, "Failed to add default CPE to newly created CPE Session.");
59 }
60 return cpe;
61 }
62
63 static inline void _xccdf_policy_destroy_cpe_oval_sessioncxx . . $ _xccdf_policy_destroy_cpe_oval_session(5d22bdacc48458e8).(void* ptr)
64 {
65 struct oval_agent_sessioncxx . . $ oval_agent_session#* session = (struct oval_agent_sessioncxx . . $ oval_agent_session#*)ptr;
66 struct oval_definition_modelcxx . . $ oval_definition_model#* model = oval_agent_get_definition_modelcxx . . $ oval_agent_get_definition_model(6e9a49c1c153e814).(session);
67 oval_agent_destroy_sessioncxx . . $ oval_agent_destroy_session(627ebdc30b34a70a).(session);
68 oval_definition_model_freecxx . . $ oval_definition_model_free(fd0cd5af216bd200).(model);
69 }
70
71 void cpe_session_freecxx . . $ cpe_session_free(b639cf00dbfac4ec).(struct cpe_sessioncxx . . $ cpe_session# *session)
72 {
73 if (session != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
74 oscap_list_freecxx . . $ oscap_list_free(e68e105c3900fcc1).(session->dictscxx . . $ cpe_session#dicts., (oscap_destruct_funccxx . . $ oscap_destruct_func#) cpe_dict_model_freecxx . . $ cpe_dict_model_free(99656294ab2c75d7).);
75 oscap_list_freecxx . . $ oscap_list_free(e68e105c3900fcc1).(session->lang_modelscxx . . $ cpe_session#lang_models., (oscap_destruct_funccxx . . $ oscap_destruct_func#) cpe_lang_model_freecxx . . $ cpe_lang_model_free(c742481f50ae5bc0).);
76 oscap_htable_freecxx . . $ oscap_htable_free(efa5da5da5d523d).(session->oval_sessionscxx . . $ cpe_session#oval_sessions., (oscap_destruct_funccxx . . $ oscap_destruct_func#) _xccdf_policy_destroy_cpe_oval_sessioncxx . . $ _xccdf_policy_destroy_cpe_oval_session(5d22bdacc48458e8).);
77 oscap_htable_freecxx . . $ oscap_htable_free(efa5da5da5d523d).(session->applicable_platformscxx . . $ cpe_session#applicable_platforms., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
78 freecxx . . $ free(5d22bdacc48458e8).(session);
79 }
80 }
81
82 static inline struct oscap_sourcecxx . . $ oscap_source# *_lookup_source_in_cachecxx . . $ _lookup_source_in_cache(3b0a1602458fd882).(struct cpe_sessioncxx . . $ cpe_session# *session, const char *prefixed_href)
83 {
84 if (session->sources_cachecxx . . $ cpe_session#sources_cache. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
85 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
86 }
87 struct oscap_sourcecxx . . $ oscap_source# *source = oscap_htable_getcxx . . $ oscap_htable_get(f5c7e8ff6c970cd3).(session->sources_cachecxx . . $ cpe_session#sources_cache., prefixed_href);
88 return source;
89 }
90
91 void cpe_session_set_thin_resultscxx . . $ cpe_session_set_thin_results(be2cc67a7d80b751).(struct cpe_sessioncxx . . $ cpe_session# *cpe, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! thin_results)
92 {
93 cpe->thin_resultscxx . . $ cpe_session#thin_results. = thin_results;
94 }
95
96 struct oval_agent_sessioncxx . . $ oval_agent_session# *cpe_session_lookup_oval_sessioncxx . . $ cpe_session_lookup_oval_session(25b39d22c4ee9fc2).(struct cpe_sessioncxx . . $ cpe_session# *cpe, const char *prefixed_href)
97 {
98 struct oval_agent_sessioncxx . . $ oval_agent_session#* session = (struct oval_agent_sessioncxx . . $ oval_agent_session#*)oscap_htable_getcxx . . $ oscap_htable_get(f5c7e8ff6c970cd3).(cpe->oval_sessionscxx . . $ cpe_session#oval_sessions., prefixed_href);
99
100 if (session == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
101 {
102 struct oscap_sourcecxx . . $ oscap_source# *source = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
103 struct oscap_sourcecxx . . $ oscap_source# *cached = _lookup_source_in_cachecxx . . $ _lookup_source_in_cache(3b0a1602458fd882).(cpe, prefixed_href);
104 if (cached == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
105 source = oscap_source_new_from_filecxx . . $ oscap_source_new_from_file(987f8b70a317ffb9).(prefixed_href);
106 cached = source;
107 }
108 struct oval_definition_modelcxx . . $ oval_definition_model#* oval_model = oval_definition_model_import_sourcecxx . . $ oval_definition_model_import_source(5c1ce95823108a2f).(cached);
109 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(source);
110
111 if (oval_model == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
112 {
113 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Can't import OVAL definition model '%s' for CPE applicability checking", prefixed_href);
114 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
115 }
116
117 char *prefixed_href_dup = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(prefixed_href);
118 char *base_name = oscap_basenamecxx . . $ oscap_basename(7a9722d75b371431).(prefixed_href_dup);
119 freecxx . . $ free(5d22bdacc48458e8).(prefixed_href_dup);
120 session = oval_agent_new_sessioncxx . . $ oval_agent_new_session(ca85c20b742af0f5).(oval_model, base_name);
121 freecxx . . $ free(5d22bdacc48458e8).(base_name);
122 if (session == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
123 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Cannot create OVAL session for '%s' for CPE applicability checking", prefixed_href);
124 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
125 }
126 if (cpe->thin_resultscxx . . $ cpe_session#thin_results.) {
127 struct oval_results_modelcxx . . $ oval_results_model# *res_model = oval_agent_get_results_modelcxx . . $ oval_agent_get_results_model(8b7d7187bb31542e).(session);
128 struct oval_directives_modelcxx . . $ oval_directives_model# *dir_model = oval_results_model_get_directives_modelcxx . . $ oval_results_model_get_directives_model(32d519058727ea70).(res_model);
129 // This is the worst function name in existence, despite its name,
130 // it's getting the oval_result_directives of the oval_directives_model.
131 // You would expect oval_directives_model_getresdirs at least, but no..
132 struct oval_result_directivescxx . . $ oval_result_directives# *dir = oval_directives_model_get_defdirscxx . . $ oval_directives_model_get_defdirs(3cbe8edfdf311cf3).(dir_model);
133 oval_result_directives_set_contentcxx . . $ oval_result_directives_set_content(d6d0d72a2ce41db6).(dir, OVAL_RESULT_TRUEcxx . . $ OVAL_RESULT_TRUE. | OVAL_RESULT_FALSEcxx . . $ OVAL_RESULT_FALSE. |
134 OVAL_RESULT_UNKNOWNcxx . . $ OVAL_RESULT_UNKNOWN. | OVAL_RESULT_NOT_EVALUATEDcxx . . $ OVAL_RESULT_NOT_EVALUATED. |
135 OVAL_RESULT_NOT_APPLICABLEcxx . . $ OVAL_RESULT_NOT_APPLICABLE. | OVAL_RESULT_ERRORcxx . . $ OVAL_RESULT_ERROR.,
136 OVAL_DIRECTIVE_CONTENT_THINcxx . . $ OVAL_DIRECTIVE_CONTENT_THIN.);
137 }
138 oscap_htable_addcxx . . $ oscap_htable_add(d9abe78f59fa00eb).(cpe->oval_sessionscxx . . $ cpe_session#oval_sessions., prefixed_href, session);
139 }
140 return session;
141 }
142
143 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_session_add_cpe_lang_model_sourcecxx . . $ cpe_session_add_cpe_lang_model_source(4af268f3de6d9870).(struct cpe_sessioncxx . . $ cpe_session# *session, struct oscap_sourcecxx . . $ oscap_source# *source)
144 {
145 struct cpe_lang_modelcxx . . $ cpe_lang_model# *lang_model = cpe_lang_model_import_sourcecxx . . $ cpe_lang_model_import_source(f203883dd62a12b8).(source);
146 return oscap_list_addcxx . . $ oscap_list_add(97f28760a5cf7823).(session->lang_modelscxx . . $ cpe_session#lang_models., lang_model);
147 }
148
149 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_session_add_cpe_dict_sourcecxx . . $ cpe_session_add_cpe_dict_source(4af268f3de6d9870).(struct cpe_sessioncxx . . $ cpe_session# *session, struct oscap_sourcecxx . . $ oscap_source# *source)
150 {
151 struct cpe_dict_modelcxx . . $ cpe_dict_model# *dict = cpe_dict_model_import_sourcecxx . . $ cpe_dict_model_import_source(855462c7c482ecd).(source);
152 return oscap_list_addcxx . . $ oscap_list_add(97f28760a5cf7823).(session->dictscxx . . $ cpe_session#dicts., dict);
153 }
154
155 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_session_add_cpe_autodetect_sourcecxx . . $ cpe_session_add_cpe_autodetect_source(4af268f3de6d9870).(struct cpe_sessioncxx . . $ cpe_session# *session, struct oscap_sourcecxx . . $ oscap_source# *source)
156 {
157 oscap_document_type_tcxx . . $ oscap_document_type_t# doc_type = oscap_source_get_scap_typecxx . . $ oscap_source_get_scap_type(1b623b3fe9f5b871).(source);
158 if (doc_type == OSCAP_DOCUMENT_CPE_DICTIONARYcxx . . $ OSCAP_DOCUMENT_CPE_DICTIONARY.) {
159 return cpe_session_add_cpe_dict_sourcecxx . . $ cpe_session_add_cpe_dict_source(4af268f3de6d9870).(session, source);
160 } else if (doc_type == OSCAP_DOCUMENT_CPE_LANGUAGEcxx . . $ OSCAP_DOCUMENT_CPE_LANGUAGE.) {
161 return cpe_session_add_cpe_lang_model_sourcecxx . . $ cpe_session_add_cpe_lang_model_source(4af268f3de6d9870).(session, source);
162 } else {
163 oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "File '%s' wasn't detected as either CPE dictionary or "
164 "CPE lang model. Can't register it to the XCCDF policy model.", oscap_source_readable_origin(source));
165 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
166 }
167 }
168
169 void cpe_session_set_cachecxx . . $ cpe_session_set_cache(b2bb2d418ae8a636).(struct cpe_sessioncxx . . $ cpe_session# *session, struct oscap_htablecxx . . $ oscap_htable# *sources_cache)
170 {
171 session->sources_cachecxx . . $ cpe_session#sources_cache. = sources_cache;
172 }