| 1 | /* |
| 2 | * Copyright 2009-2010 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 | * "Daniel Kopecek" <[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 <stdint.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <limits.h> |
| 31 | #include <errno.h> |
| 32 | #if defined(OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!) |
| 33 | # include <pthread.h> |
| 34 | #endif |
| 35 | |
| 36 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 37 | #include "oval_probe.h"cxx . . $ `<file>/src/OVAL/public/oval_probe.h`/ |
| 38 | #include "oval_system_characteristics.h"cxx . . $ `<file>/src/OVAL/public/oval_system_characteristics.h`/ |
| 39 | #include "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/ |
| 40 | |
| 41 | #include "oval_probe_impl.h"cxx . . $ `<file>/src/OVAL/oval_probe_impl.h`/ |
| 42 | #include "oval_system_characteristics_impl.h"cxx . . $ `<file>/src/OVAL/oval_system_characteristics_impl.h`/ |
| 43 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 44 | #include "common/bfind.h"cxx . . $ `<file>/src/common/bfind.h`/ |
| 45 | #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 46 | |
| 47 | #include "_oval_probe_session.h"cxx . . $ `<file>/src/OVAL/_oval_probe_session.h`/ |
| 48 | #include "_oval_probe_handler.h"cxx . . $ `<file>/src/OVAL/_oval_probe_handler.h`/ |
| 49 | #include "oval_probe_ext.h"cxx . . $ `<file>/src/OVAL/oval_probe_ext.h`/ |
| 50 | #include "collectVarRefs_impl.h"cxx . . $ `<file>/src/OVAL/collectVarRefs_impl.h`/ |
| 51 | |
| 52 | #ifdef OS_WINDOWS |
| 53 | #define X_OK 0 |
| 54 | #endif |
| 55 | |
| 56 | /* |
| 57 | * Library side entity name cache. Initialization needs to be |
| 58 | * thread-safe and is done by oval_probe_session_new. Freeing |
| 59 | * of memory used by this cache is done at exit using a hook |
| 60 | * registered with atexit(). |
| 61 | */ |
| 62 | probe_ncache_tcxx . . $ probe_ncache_t# *OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache) = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 63 | struct id_desc_tcxx . . $ id_desc_t# OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(id_desc); |
| 64 | |
| 65 | #define __ERRBUF_SIZEcxx . . $ `src/OVAL/oval_probe.c:65:9`! 128 |
| 66 | |
| 67 | static void _syschar_add_bindingscxx . . $ _syschar_add_bindings(736953a1beaa4f24).(struct oval_syscharcxx . . $ oval_syschar# *sc, struct oval_string_mapcxx . . $ oval_string_map# *vm) |
| 68 | { |
| 69 | struct oval_iteratorcxx . . $ oval_iterator# *var_itr; |
| 70 | |
| 71 | var_itr = oval_string_map_valuescxx . . $ oval_string_map_values(52dd2feb99c28df0).(vm); |
| 72 | while (oval_collection_iterator_has_morecxx . . $ oval_collection_iterator_has_more(de0650ab9b639739).(var_itr)) { |
| 73 | struct oval_variablecxx . . $ oval_variable# *var; |
| 74 | struct oval_value_iteratorcxx . . $ oval_value_iterator# *val_itr; |
| 75 | struct oval_variable_bindingcxx . . $ oval_variable_binding# *binding; |
| 76 | |
| 77 | var = oval_collection_iterator_nextcxx . . $ oval_collection_iterator_next(344074693c9690a9).(var_itr); |
| 78 | binding = oval_variable_binding_newcxx . . $ oval_variable_binding_new(ac18c3aae7e0fb07).(var, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 79 | |
| 80 | val_itr = oval_variable_get_valuescxx . . $ oval_variable_get_values(325344158909f348).(var); |
| 81 | while (oval_value_iterator_has_morecxx . . $ oval_value_iterator_has_more(753adc45e63e3dec).(val_itr)) { |
| 82 | struct oval_valuecxx . . $ oval_value# *val; |
| 83 | char *txt; |
| 84 | |
| 85 | val = oval_value_iterator_nextcxx . . $ oval_value_iterator_next(c6f435863c40c2c6).(val_itr); |
| 86 | txt = oval_value_get_textcxx . . $ oval_value_get_text(cab4e37bbd1656d5).(val); |
| 87 | txt = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(txt); |
| 88 | oval_variable_binding_add_valuecxx . . $ oval_variable_binding_add_value(7e5c0243ecffb425).(binding, txt); |
| 89 | } |
| 90 | oval_value_iterator_freecxx . . $ oval_value_iterator_free(1b9ed96dce1b7286).(val_itr); |
| 91 | |
| 92 | oval_syschar_add_variable_bindingcxx . . $ oval_syschar_add_variable_binding(163c4e135d6bad27).(sc, binding); |
| 93 | } |
| 94 | oval_collection_iterator_freecxx . . $ oval_collection_iterator_free(ee496816570b41f7).(var_itr); |
| 95 | } |
| 96 | |
| 97 | int oval_probe_query_objectcxx . . $ oval_probe_query_object(c2fefbf93109479a).(oval_probe_session_tcxx . . $ oval_probe_session_t# *psess, struct oval_objectcxx . . $ oval_object# *object, int flags, struct oval_syscharcxx . . $ oval_syschar# **out_syschar) |
| 98 | { |
| 99 | char *oid; |
| 100 | struct oval_syscharcxx . . $ oval_syschar# *sysc; |
| 101 | oval_subtype_tcxx . . $ oval_subtype_t# type; |
| 102 | const char *type_name; |
| 103 | oval_ph_tcxx . . $ oval_ph_t# *ph; |
| 104 | struct oval_string_mapcxx . . $ oval_string_map# *vm; |
| 105 | struct oval_syschar_modelcxx . . $ oval_syschar_model# *model; |
| 106 | int ret; |
| 107 | |
| 108 | oid = oval_object_get_idcxx . . $ oval_object_get_id(c789946d38fecc83).(object); |
| 109 | model = psess->sys_modelcxx . . $ oval_probe_session#sys_model.; |
| 110 | |
| 111 | type = oval_object_get_subtypecxx . . $ oval_object_get_subtype(770582e2dbb3228b).(object); |
| 112 | type_name = oval_subtype_get_textcxx . . $ oval_subtype_get_text(ee6b3dcae047e21f).(type); |
| 113 | dIcxx . . $ `src/common/debug_priv.h:61:9`!("Querying %s object '%s', flags: %u.", type_name, oid, flags); |
| 114 | |
| 115 | sysc = oval_syschar_model_get_syscharcxx . . $ oval_syschar_model_get_syschar(5e0330551a5ec218).(model, oid); |
| 116 | if (sysc != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 117 | int variable_instance_hint = oval_syschar_get_variable_instance_hintcxx . . $ oval_syschar_get_variable_instance_hint(2d10c14f69c3219d).(sysc); |
| 118 | if (oval_syschar_get_variable_instance_hintcxx . . $ oval_syschar_get_variable_instance_hint(2d10c14f69c3219d).(sysc) != oval_syschar_get_variable_instancecxx . . $ oval_syschar_get_variable_instance(2d10c14f69c3219d).(sysc)) { |
| 119 | dIcxx . . $ `src/common/debug_priv.h:61:9`!("Creating another syschar for variable_instance=%d)", variable_instance_hint); |
| 120 | sysc = oval_syschar_newcxx . . $ oval_syschar_new(7da860ecdb2aeac).(model, object); |
| 121 | oval_syschar_set_variable_instancecxx . . $ oval_syschar_set_variable_instance(aae0a0c13cad9911).(sysc, variable_instance_hint); |
| 122 | oval_syschar_set_variable_instance_hintcxx . . $ oval_syschar_set_variable_instance_hint(aae0a0c13cad9911).(sysc, variable_instance_hint); |
| 123 | } |
| 124 | else { |
| 125 | oval_syschar_collection_flag_tcxx . . $ oval_syschar_collection_flag_t# sc_flg = oval_syschar_get_flagcxx . . $ oval_syschar_get_flag(faee96ff7b702646).(sysc); |
| 126 | const char *flag_text = oval_syschar_collection_flag_get_textcxx . . $ oval_syschar_collection_flag_get_text(5fdf4cba2f095175).(sc_flg); |
| 127 | dIcxx . . $ `src/common/debug_priv.h:61:9`!("System characteristics for %s_object '%s' already exist, flag: %s.", type_name, oid, flag_text); |
| 128 | |
| 129 | if (sc_flg != SYSCHAR_FLAG_UNKNOWNcxx . . $ SYSCHAR_FLAG_UNKNOWN. || (flags & OVAL_PDFLAG_NOREPLYcxx . . $ `src/OVAL/public/oval_probe.h:45:9`!)) { |
| 130 | if (out_syschar) |
| 131 | *out_syschar = sysc; |
| 132 | return 0; |
| 133 | } |
| 134 | } |
| 135 | } else { |
| 136 | dIcxx . . $ `src/common/debug_priv.h:61:9`!("Creating new syschar for %s_object '%s'.", type_name, oid); |
| 137 | sysc = oval_syschar_newcxx . . $ oval_syschar_new(7da860ecdb2aeac).(model, object); |
| 138 | } |
| 139 | |
| 140 | if (out_syschar) |
| 141 | *out_syschar = sysc; |
| 142 | |
| 143 | ph = oval_probe_handler_getcxx . . $ oval_probe_handler_get(a2b39ae009cb9244).(psess->phcxx . . $ oval_probe_session#ph., type); |
| 144 | |
| 145 | if (ph == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 146 | char *msg = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("OVAL object '%s_object' is not supported.", type_name); |
| 147 | |
| 148 | dWcxx . . $ `src/common/debug_priv.h:62:9`!("%s", msg); |
| 149 | oval_syschar_add_new_messagecxx . . $ oval_syschar_add_new_message(a127cd6af74f53db).(sysc, msg, OVAL_MESSAGE_LEVEL_WARNINGcxx . . $ OVAL_MESSAGE_LEVEL_WARNING.); |
| 150 | freecxx . . $ free(5d22bdacc48458e8).(msg); |
| 151 | oval_syschar_set_flagcxx . . $ oval_syschar_set_flag(46ad62f81d28bed2).(sysc, SYSCHAR_FLAG_NOT_COLLECTEDcxx . . $ SYSCHAR_FLAG_NOT_COLLECTED.); |
| 152 | |
| 153 | return 1; |
| 154 | } |
| 155 | |
| 156 | if ((ret = oval_probe_ext_handlercxx . . $ oval_probe_ext_handler(a49301219799be48).(type, ph->uptrcxx . . $ oval_ph#uptr., PROBE_HANDLER_ACT_EVALcxx . . $ `src/OVAL/_oval_probe_handler.h:47:9`!, sysc, flags)) != 0) { |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | if (!(flags & OVAL_PDFLAG_NOREPLYcxx . . $ `src/OVAL/public/oval_probe.h:45:9`!)) { |
| 161 | vm = oval_string_map_newcxx . . $ oval_string_map_new(c786b134e882bd29).(); |
| 162 | oval_obj_collect_var_refscxx . . $ oval_obj_collect_var_refs(a55e538a919ec0e1).(object, vm); |
| 163 | _syschar_add_bindingscxx . . $ _syschar_add_bindings(736953a1beaa4f24).(sysc, vm); |
| 164 | oval_string_map_freecxx . . $ oval_string_map_free(e4310474f4dc2f59).(vm, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | int oval_probe_query_sysinfocxx . . $ oval_probe_query_sysinfo(ce5e9922ccd2f8c3).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess, struct oval_sysinfocxx . . $ oval_sysinfo# **out_sysinfo) |
| 171 | { |
| 172 | struct oval_sysinfocxx . . $ oval_sysinfo# *sysinf; |
| 173 | oval_ph_tcxx . . $ oval_ph_t# *ph; |
| 174 | int ret; |
| 175 | |
| 176 | dIcxx . . $ `src/common/debug_priv.h:61:9`!("Querying system information."); |
| 177 | |
| 178 | ph = oval_probe_handler_getcxx . . $ oval_probe_handler_get(a2b39ae009cb9244).(sess->phcxx . . $ oval_probe_session#ph., OVAL_INDEPENDENT_SYSCHAR_SUBTYPEcxx . . $ OVAL_INDEPENDENT_SYSCHAR_SUBTYPE.); |
| 179 | |
| 180 | if (ph == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 181 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`! (OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "OVAL object not supported"); |
| 182 | return(-1); |
| 183 | } |
| 184 | |
| 185 | if (ph->funccxx . . $ oval_ph#func. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 186 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`! (OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "OVAL object not correctly defined"); |
| 187 | return(-1); |
| 188 | } |
| 189 | |
| 190 | sysinf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 191 | |
| 192 | ret = oval_probe_sys_handlercxx . . $ oval_probe_sys_handler(a49301219799be48).(OVAL_INDEPENDENT_SYSCHAR_SUBTYPEcxx . . $ OVAL_INDEPENDENT_SYSCHAR_SUBTYPE., ph->uptrcxx . . $ oval_ph#uptr., PROBE_HANDLER_ACT_EVALcxx . . $ `src/OVAL/_oval_probe_handler.h:47:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &sysinf, 0); |
| 193 | if (ret != 0) |
| 194 | return(ret); |
| 195 | |
| 196 | *out_sysinfo = sysinf; |
| 197 | return(0); |
| 198 | } |
| 199 | |
| 200 | static int oval_probe_query_var_refcxx . . $ oval_probe_query_var_ref(2380e1002127b5f2).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess, struct oval_statecxx . . $ oval_state# *state) |
| 201 | { |
| 202 | struct oval_state_content_iteratorcxx . . $ oval_state_content_iterator# *contents = oval_state_get_contentscxx . . $ oval_state_get_contents(e38d902cdc6b5c2d).(state); |
| 203 | while (oval_state_content_iterator_has_morecxx . . $ oval_state_content_iterator_has_more(344811bbb4806d19).(contents)) { |
| 204 | struct oval_state_contentcxx . . $ oval_state_content# *content = oval_state_content_iterator_nextcxx . . $ oval_state_content_iterator_next(43c3368aa9ccef0c).(contents); |
| 205 | struct oval_entitycxx . . $ oval_entity# * entity = oval_state_content_get_entitycxx . . $ oval_state_content_get_entity(20470541c08ba23c).(content); |
| 206 | if (oval_entity_get_varref_typecxx . . $ oval_entity_get_varref_type(ad657afef3bd7ab6).(entity) == OVAL_ENTITY_VARREF_ATTRIBUTEcxx . . $ OVAL_ENTITY_VARREF_ATTRIBUTE.) { |
| 207 | oval_syschar_collection_flag_tcxx . . $ oval_syschar_collection_flag_t# flag; |
| 208 | struct oval_variablecxx . . $ oval_variable# *var = oval_entity_get_variablecxx . . $ oval_entity_get_variable(fe3169ea470c913).(entity); |
| 209 | const char *state_id = oval_state_get_idcxx . . $ oval_state_get_id(3f993b0a468bf006).(state); |
| 210 | oval_variable_type_tcxx . . $ oval_variable_type_t# var_type = oval_variable_get_typecxx . . $ oval_variable_get_type(eb4d8c3228dab61c).(var); |
| 211 | const char *var_type_text = oval_variable_type_get_textcxx . . $ oval_variable_type_get_text(3fc5b3e1d254574e).(var_type); |
| 212 | const char *var_id = oval_variable_get_idcxx . . $ oval_variable_get_id(341a3c7e6ea3818b).(var); |
| 213 | dIcxx . . $ `src/common/debug_priv.h:61:9`!("State '%s' references %s '%s'.", state_id, |
| 214 | var_type_text, var_id); |
| 215 | |
| 216 | int ret = oval_probe_query_variablecxx . . $ oval_probe_query_variable(257bd925b7be383d).(sess, var); |
| 217 | if (ret == -1) { |
| 218 | oval_state_content_iterator_freecxx . . $ oval_state_content_iterator_free(526a40962d3af9e1).(contents); |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | flag = oval_variable_get_collection_flagcxx . . $ oval_variable_get_collection_flag(e1154c96d0101da8).(var); |
| 223 | switch (flag) { |
| 224 | case SYSCHAR_FLAG_COMPLETEcxx . . $ SYSCHAR_FLAG_COMPLETE.: |
| 225 | case SYSCHAR_FLAG_INCOMPLETEcxx . . $ SYSCHAR_FLAG_INCOMPLETE.: |
| 226 | break; |
| 227 | default: |
| 228 | oval_state_content_iterator_freecxx . . $ oval_state_content_iterator_free(526a40962d3af9e1).(contents); |
| 229 | return 0; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | oval_state_content_iterator_freecxx . . $ oval_state_content_iterator_free(526a40962d3af9e1).(contents); |
| 234 | return 1; |
| 235 | } |
| 236 | |
| 237 | int oval_probe_query_testcxx . . $ oval_probe_query_test(9cb337ebfe9a5d86).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess, struct oval_testcxx . . $ oval_test# *test) |
| 238 | { |
| 239 | struct oval_objectcxx . . $ oval_object# *object; |
| 240 | struct oval_state_iteratorcxx . . $ oval_state_iterator# *ste_itr; |
| 241 | int ret; |
| 242 | oval_subtype_tcxx . . $ oval_subtype_t# test_subtype, object_subtype; |
| 243 | |
| 244 | object = oval_test_get_objectcxx . . $ oval_test_get_object(7733aadd35446dd9).(test); |
| 245 | if (object == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 246 | return 0; |
| 247 | test_subtype = oval_test_get_subtypecxx . . $ oval_test_get_subtype(ae5a5b14a3df8d45).(test); |
| 248 | object_subtype = oval_object_get_subtypecxx . . $ oval_object_get_subtype(770582e2dbb3228b).(object); |
| 249 | if (test_subtype != object_subtype) { |
| 250 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "%s_test '%s' is not compatible with %s_object '%s'.", |
| 251 | oval_subtype_to_str(test_subtype), oval_test_get_id(test), |
| 252 | oval_subtype_to_str(object_subtype), oval_object_get_id(object)); |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | /* probe object */ |
| 257 | ret = oval_probe_query_objectcxx . . $ oval_probe_query_object(c2fefbf93109479a).(sess, object, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 258 | if (ret == -1) |
| 259 | return ret; |
| 260 | /* probe objects referenced like this: test->state->variable->object */ |
| 261 | ste_itr = oval_test_get_statescxx . . $ oval_test_get_states(b738fee4834aaaa6).(test); |
| 262 | while (oval_state_iterator_has_morecxx . . $ oval_state_iterator_has_more(bbfacbd9c1bc3d63).(ste_itr)) { |
| 263 | struct oval_statecxx . . $ oval_state# *state = oval_state_iterator_nextcxx . . $ oval_state_iterator_next(f0883bc3981b419).(ste_itr); |
| 264 | ret = oval_probe_query_var_refcxx . . $ oval_probe_query_var_ref(2380e1002127b5f2).(sess, state); |
| 265 | if (ret < 1) { |
| 266 | oval_state_iterator_freecxx . . $ oval_state_iterator_free(37c8c23faa65426a).(ste_itr); |
| 267 | return ret; |
| 268 | } |
| 269 | } |
| 270 | oval_state_iterator_freecxx . . $ oval_state_iterator_free(37c8c23faa65426a).(ste_itr); |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 |