| 1 | /* |
| 2 | * Copyright 2020 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 | * Jan Černý <[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 <math.h> |
| 28 | #include <errno.h> |
| 29 | #include <yaml.h> |
| 30 | #include <yaml-path.h>cxx . . $ `<file>/yaml-filter/src/yaml-path.h`/ |
| 31 | |
| 32 | #include "yamlfilecontent_probe.h"cxx . . $ `<file>/src/OVAL/probes/independent/yamlfilecontent_probe.h`/ |
| 33 | #include "sexp-manip.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/public/sexp-manip.h`/ |
| 34 | #include "debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 35 | #include "oval_fts.h"cxx . . $ `<file>/src/OVAL/probes/oval_fts.h`/ |
| 36 | #include "list.h"cxx . . $ `<file>/src/common/list.h`/ |
| 37 | #include "probe/probe.h"cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/ |
| 38 | #include "common/oscap_pcre.h"cxx . . $ `<file>/src/common/oscap_pcre.h`/ |
| 39 | |
| 40 | #define OSCAP_YAML_STRING_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:40:9`! "tag:yaml.org,2002:str" |
| 41 | #define OSCAP_YAML_BOOL_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:41:9`! "tag:yaml.org,2002:bool" |
| 42 | #define OSCAP_YAML_FLOAT_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:42:9`! "tag:yaml.org,2002:float" |
| 43 | #define OSCAP_YAML_INT_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:43:9`! "tag:yaml.org,2002:int" |
| 44 | #define OSCAP_YAML_NULL_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:44:9`! "tag:yaml.org,2002:null" |
| 45 | |
| 46 | #define OVECCOUNTcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:46:9`! 30 /* should be a multiple of 3 */ |
| 47 | |
| 48 | int yamlfilecontent_probe_offline_mode_supportedcxx . . $ yamlfilecontent_probe_offline_mode_supported(b126dc7c1de90089).() |
| 49 | { |
| 50 | return PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.; |
| 51 | } |
| 52 | |
| 53 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! match_regexcxx . . $ match_regex(b7a7aa4a824b7595).(const char *pattern, const char *value) |
| 54 | { |
| 55 | char *errptr; |
| 56 | int erroroffset; |
| 57 | oscap_pcre_tcxx . . $ oscap_pcre_t# *re = oscap_pcre_compilecxx . . $ oscap_pcre_compile(29ca11f2d36a957a).(pattern, 0, &errptr, &erroroffset); |
| 58 | if (re == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 59 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("oscap_pcre_compile failed on pattern '%s': %s at %d", pattern, |
| 60 | errptr, erroroffset); |
| 61 | oscap_pcre_err_freecxx . . $ oscap_pcre_err_free(fda57c8427c60377).(errptr); |
| 62 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 63 | } |
| 64 | int ovector[OVECCOUNTcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:46:9`!]; |
| 65 | int rc = oscap_pcre_execcxx . . $ oscap_pcre_exec(7630dfd25fd504ec).(re, value, strlencxx . . $ strlen(751346f8406fd082).(value), 0, 0, ovector, OVECCOUNTcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:46:9`!); |
| 66 | oscap_pcre_freecxx . . $ oscap_pcre_free(804bb72472b0846e).(re); |
| 67 | if (rc > 0) { |
| 68 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 69 | } |
| 70 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 71 | } |
| 72 | |
| 73 | static SEXP_tcxx . . $ SEXP_t# *yaml_scalar_event_to_sexpcxx . . $ yaml_scalar_event_to_sexp(d8123239fd989d12).(yaml_event_tcxx . . $ yaml_event_t# *event) |
| 74 | { |
| 75 | char *tag = (char *) event->datacxx . . $ yaml_event_s#data..scalarcxx . . $ yaml_event_s#$anonymous_type_8#scalar..tagcxx . . $ yaml_event_s#$anonymous_type_8#$anonymous_type_14#tag.; |
| 76 | char *value = (char *) event->datacxx . . $ yaml_event_s#data..scalarcxx . . $ yaml_event_s#$anonymous_type_8#scalar..valuecxx . . $ yaml_event_s#$anonymous_type_8#$anonymous_type_14#value.; |
| 77 | |
| 78 | /* Nodes lacking an explicit tag are given a non-specific tag: |
| 79 | * “!” for non-plain scalars, and “?” for all other nodes |
| 80 | */ |
| 81 | if (tag == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 82 | if (event->datacxx . . $ yaml_event_s#data..scalarcxx . . $ yaml_event_s#$anonymous_type_8#scalar..stylecxx . . $ yaml_event_s#$anonymous_type_8#$anonymous_type_14#style. != YAML_PLAIN_SCALAR_STYLEcxx . . $ YAML_PLAIN_SCALAR_STYLE.) { |
| 83 | tag = "!"; |
| 84 | } else { |
| 85 | tag = "?"; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /* Nodes with "!" tag can be sequences, maps or strings, but we process |
| 90 | * only scalars in this functions, so they can only be strings. */ |
| 91 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tag, "!")) { |
| 92 | tag = OSCAP_YAML_STRING_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:40:9`!; |
| 93 | } |
| 94 | |
| 95 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! question = !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tag, "?"); |
| 96 | |
| 97 | /* Regular expressions based on https://yaml.org/spec/1.2/spec.html#id2804923 */ |
| 98 | |
| 99 | if (question || !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tag, OSCAP_YAML_BOOL_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:41:9`!)) { |
| 100 | if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^(true|True|TRUE)$", value)) { |
| 101 | return SEXP_number_newbcxx . . $ SEXP_number_newb(f1e7d218d08e4133).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 102 | } else if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^(false|False|FALSE)$", value)) { |
| 103 | return SEXP_number_newbcxx . . $ SEXP_number_newb(f1e7d218d08e4133).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); |
| 104 | } else if (!question) { |
| 105 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 106 | } |
| 107 | } |
| 108 | if (question || !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tag, OSCAP_YAML_INT_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:43:9`!)) { |
| 109 | if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^[+-]?[0-9]+$", value)) { |
| 110 | int int_value = strtolcxx . . $ strtol(44bbb87609b212fc).(value, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 10); |
| 111 | return SEXP_number_newicxx . . $ `src/OVAL/probes/SEAP/public/sexp-manip.h:103:9`!(int_value); |
| 112 | } else if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^0o[0-7]+$", value)) { |
| 113 | /* strtol doesn't understand 0o as octal prefix, it wants 0 */ |
| 114 | int int_value = strtolcxx . . $ strtol(44bbb87609b212fc).(value + 2, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 8); |
| 115 | return SEXP_number_newicxx . . $ `src/OVAL/probes/SEAP/public/sexp-manip.h:103:9`!(int_value); |
| 116 | } else if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^0x[0-9a-fA-F]+$", value)) { |
| 117 | int int_value = strtolcxx . . $ strtol(44bbb87609b212fc).(value, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 16); |
| 118 | return SEXP_number_newicxx . . $ `src/OVAL/probes/SEAP/public/sexp-manip.h:103:9`!(int_value); |
| 119 | } else if (!question) { |
| 120 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 121 | } |
| 122 | } |
| 123 | if (question || !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tag, OSCAP_YAML_FLOAT_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:42:9`!)) { |
| 124 | if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^[-+]?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$", value)) { |
| 125 | double double_value = strtodcxx . . $ strtod(3dfe5620a0d3160e).(value, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 126 | return SEXP_number_newfcxx . . $ SEXP_number_newf(653b1881b211aa0d).(double_value); |
| 127 | } else if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^[-+]?(\\.inf|\\.Inf|\\.INF)$", value)) { |
| 128 | double double_value = INFINITYcxx . . $ `<external>/11263917310783833665/math.h:92:12`!; |
| 129 | if (value[0] == '-') { |
| 130 | double_value = -INFINITYcxx . . $ `<external>/11263917310783833665/math.h:92:12`!; |
| 131 | } |
| 132 | return SEXP_number_newfcxx . . $ SEXP_number_newf(653b1881b211aa0d).(double_value); |
| 133 | } else if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^(\\.nan|\\.NaN|\\.NAN)$", value)) { |
| 134 | double double_value = NANcxx . . $ `<external>/11263917310783833665/math.h:101:12`!; |
| 135 | return SEXP_number_newfcxx . . $ SEXP_number_newf(653b1881b211aa0d).(double_value); |
| 136 | } else if (!question) { |
| 137 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 138 | } |
| 139 | } |
| 140 | if (question || !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tag, OSCAP_YAML_NULL_TAGcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:44:9`!)) { |
| 141 | if (match_regexcxx . . $ match_regex(b7a7aa4a824b7595).("^(null|Null|NULL|~|)$", value)) { |
| 142 | // TODO: Return real NULL when record's field will support nil="true" |
| 143 | return SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).("(null)", strlencxx . . $ strlen(751346f8406fd082).("(null)")); |
| 144 | } else if (!question) { |
| 145 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(value, strlencxx . . $ strlen(751346f8406fd082).(value)); |
| 150 | } |
| 151 | |
| 152 | static char *escape_keycxx . . $ escape_key(7a9722d75b371431).(char *key) |
| 153 | { |
| 154 | if (key == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 155 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 156 | |
| 157 | size_t cap_letters = 0; |
| 158 | size_t key_len = strlencxx . . $ strlen(751346f8406fd082).(key); |
| 159 | for (size_t i = 0; i < key_len; i++) |
| 160 | if ((key[i] >= 'A' && key[i] <= 'Z') || key[i] == '^') |
| 161 | cap_letters++; |
| 162 | |
| 163 | if (cap_letters == 0) |
| 164 | return key; |
| 165 | |
| 166 | char *new_key = realloccxx . . $ realloc(417ab160f6baadc6).(key, key_len + 1 + cap_letters); |
| 167 | if (new_key == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 168 | return key; |
| 169 | new_key[key_len + cap_letters] = '\0'; |
| 170 | |
| 171 | for (ssize_tcxx . . $ ssize_t# i = key_len; i >= 0; i--) { |
| 172 | if ((new_key[i] >= 'A' && new_key[i] <= 'Z') || new_key[i] == '^') { |
| 173 | if (new_key[i] != '^') |
| 174 | new_key[i] += 32; |
| 175 | memmovecxx . . $ memmove(cc817cb175f282d).(new_key + i + cap_letters, new_key + i, key_len - i); |
| 176 | new_key[i + cap_letters - 1] = '^'; |
| 177 | cap_letters--; |
| 178 | key_len = i; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | return new_key; |
| 183 | } |
| 184 | |
| 185 | #define result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!(fmt, args...) \ |
| 186 | do { \ |
| 187 | SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR, fmt, args); \ |
| 188 | probe_cobj_add_msg(probe_ctx_getresult(ctx), msg); \ |
| 189 | SEXP_free(msg); \ |
| 190 | probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_ERROR); \ |
| 191 | ret = -1; \ |
| 192 | } while (0) |
| 193 | |
| 194 | static int yaml_path_querycxx . . $ yaml_path_query(a60a5f9296a4a78b).(yaml_parser_tcxx . . $ yaml_parser_t# *parser, const char *yaml_path_cstr, struct oscap_listcxx . . $ oscap_list# *values, probe_ctxcxx . . $ probe_ctx# *ctx) |
| 195 | { |
| 196 | int ret = 0; |
| 197 | |
| 198 | yaml_path_tcxx . . $ yaml_path_t# *yaml_path = yaml_path_createcxx . . $ yaml_path_create(6a0b3c6d2c1381cc).(); |
| 199 | if (yaml_path_parsecxx . . $ yaml_path_parse(6fd2af71f8d09d83).(yaml_path, (char *) yaml_path_cstr)) { |
| 200 | result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!("Invalid YAML path '%s': %s", yaml_path_cstr, yaml_path_error_get(yaml_path)->message); |
| 201 | yaml_path_destroycxx . . $ yaml_path_destroy(3cfebe741d41ce70).(yaml_path); |
| 202 | return ret; |
| 203 | }; |
| 204 | |
| 205 | yaml_event_tcxx . . $ yaml_event_t# event; |
| 206 | yaml_event_type_tcxx . . $ yaml_event_type_t# event_type; |
| 207 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! sequence = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 208 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mapping = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 209 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! fake_mapping = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 210 | int index = 0; |
| 211 | char *key = strdupcxx . . $ strdup(a8b8e32347182212).("#"); |
| 212 | |
| 213 | struct oscap_htablecxx . . $ oscap_htable# *record = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 214 | |
| 215 | do { |
| 216 | if (!yaml_parser_parsecxx . . $ yaml_parser_parse(9fcd0b122d7bfbea).(parser, &event)) { |
| 217 | result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!("YAML parser error: %s", parser->problem); |
| 218 | goto cleanup; |
| 219 | } |
| 220 | |
| 221 | event_type = event.typecxx . . $ yaml_event_s#type.; |
| 222 | |
| 223 | if (yaml_path_filter_eventcxx . . $ yaml_path_filter_event(e4b698972853c64d).(yaml_path, parser, &event) == YAML_PATH_FILTER_RESULT_OUTcxx . . $ YAML_PATH_FILTER_RESULT_OUT.) { |
| 224 | goto next; |
| 225 | } |
| 226 | |
| 227 | if (sequence) { |
| 228 | if (event_type == YAML_SEQUENCE_END_EVENTcxx . . $ YAML_SEQUENCE_END_EVENT.) { |
| 229 | if (fake_mapping) { |
| 230 | fake_mapping = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 231 | if (record && record->itemcountcxx . . $ oscap_htable#itemcount. > 0) { |
| 232 | oscap_list_addcxx . . $ oscap_list_add(97f28760a5cf7823).(values, record); |
| 233 | } else { |
| 234 | // Do not collect empty records |
| 235 | oscap_htable_free0cxx . . $ oscap_htable_free0(dbd8f9d05ba37fd5).(record); |
| 236 | } |
| 237 | record = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 238 | } else { |
| 239 | sequence = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 240 | } |
| 241 | } else if (event_type == YAML_SEQUENCE_START_EVENTcxx . . $ YAML_SEQUENCE_START_EVENT.) { |
| 242 | if (mapping || fake_mapping) { |
| 243 | result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!("YAML path '%s' points to a multi-dimensional structure (a map or a sequence containing other sequences)", yaml_path_cstr); |
| 244 | goto cleanup; |
| 245 | } else { |
| 246 | fake_mapping = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 247 | record = oscap_htable_newcxx . . $ oscap_htable_new(3c1cb2b6f390ad38).(); |
| 248 | } |
| 249 | } |
| 250 | } else { |
| 251 | if (event_type == YAML_SEQUENCE_START_EVENTcxx . . $ YAML_SEQUENCE_START_EVENT.) { |
| 252 | sequence = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 253 | if (mapping) |
| 254 | index++; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | if (mapping) { |
| 259 | if (event_type == YAML_MAPPING_END_EVENTcxx . . $ YAML_MAPPING_END_EVENT.) { |
| 260 | mapping = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 261 | if (record && record->itemcountcxx . . $ oscap_htable#itemcount. > 0) { |
| 262 | oscap_list_addcxx . . $ oscap_list_add(97f28760a5cf7823).(values, record); |
| 263 | } else { |
| 264 | // Do not collect empty records |
| 265 | oscap_htable_free0cxx . . $ oscap_htable_free0(dbd8f9d05ba37fd5).(record); |
| 266 | } |
| 267 | record = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 268 | } else if (event_type == YAML_MAPPING_START_EVENTcxx . . $ YAML_MAPPING_START_EVENT.) { |
| 269 | result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!("YAML path '%s' points to a multi-dimensional structure (map containing another map)", yaml_path_cstr); |
| 270 | goto cleanup; |
| 271 | } |
| 272 | } else { |
| 273 | if (event_type == YAML_MAPPING_START_EVENTcxx . . $ YAML_MAPPING_START_EVENT.) { |
| 274 | if (record) { |
| 275 | result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!("YAML path '%s' points to an invalid structure (map containing another map)", yaml_path_cstr); |
| 276 | goto cleanup; |
| 277 | } |
| 278 | if (fake_mapping) { |
| 279 | result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!("YAML path '%s' points to a multi-dimensional structure (two-dimensional sequence containing a map)", yaml_path_cstr); |
| 280 | goto cleanup; |
| 281 | } |
| 282 | mapping = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 283 | sequence = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 284 | index = 0; |
| 285 | record = oscap_htable_newcxx . . $ oscap_htable_new(3c1cb2b6f390ad38).(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (event_type == YAML_SCALAR_EVENTcxx . . $ YAML_SCALAR_EVENT.) { |
| 290 | if (mapping) { |
| 291 | if (!sequence) { |
| 292 | if (index++ % 2 == 0) { |
| 293 | freecxx . . $ free(5d22bdacc48458e8).(key); |
| 294 | key = escape_keycxx . . $ escape_key(7a9722d75b371431).(strdupcxx . . $ strdup(a8b8e32347182212).((const char *) event.datacxx . . $ yaml_event_s#data..scalarcxx . . $ yaml_event_s#$anonymous_type_8#scalar..valuecxx . . $ yaml_event_s#$anonymous_type_8#$anonymous_type_14#value.)); |
| 295 | goto next; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | SEXP_tcxx . . $ SEXP_t# *sexp = yaml_scalar_event_to_sexpcxx . . $ yaml_scalar_event_to_sexp(d8123239fd989d12).(&event); |
| 301 | if (sexp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 302 | result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!("Can't convert '%s %s' to SEXP", event.data.scalar.tag, event.data.scalar.value); |
| 303 | goto cleanup; |
| 304 | } |
| 305 | |
| 306 | if (!record) |
| 307 | record = oscap_htable_newcxx . . $ oscap_htable_new(3c1cb2b6f390ad38).(); |
| 308 | struct oscap_listcxx . . $ oscap_list# *field = oscap_htable_getcxx . . $ oscap_htable_get(f5c7e8ff6c970cd3).(record, key); |
| 309 | if (!field) { |
| 310 | field = oscap_list_newcxx . . $ oscap_list_new(ea215f73c8361bff).(); |
| 311 | oscap_htable_addcxx . . $ oscap_htable_add(d9abe78f59fa00eb).(record, key, field); |
| 312 | } |
| 313 | |
| 314 | oscap_list_addcxx . . $ oscap_list_add(97f28760a5cf7823).(field, sexp); |
| 315 | } |
| 316 | next: |
| 317 | yaml_event_deletecxx . . $ yaml_event_delete(a38ec22d89279e03).(&event); |
| 318 | } while (event_type != YAML_STREAM_END_EVENTcxx . . $ YAML_STREAM_END_EVENT.); |
| 319 | |
| 320 | cleanup: |
| 321 | if (event.typecxx . . $ yaml_event_s#type. != 0) |
| 322 | yaml_event_deletecxx . . $ yaml_event_delete(a38ec22d89279e03).(&event); |
| 323 | if (record) |
| 324 | oscap_list_addcxx . . $ oscap_list_add(97f28760a5cf7823).(values, record); |
| 325 | freecxx . . $ free(5d22bdacc48458e8).(key); |
| 326 | yaml_path_destroycxx . . $ yaml_path_destroy(3cfebe741d41ce70).(yaml_path); |
| 327 | |
| 328 | return ret; |
| 329 | } |
| 330 | |
| 331 | static void record_freecxx . . $ record_free(27ed2064e5aec1b1).(struct oscap_listcxx . . $ oscap_list# *items) |
| 332 | { |
| 333 | oscap_list_freecxx . . $ oscap_list_free(e68e105c3900fcc1).(items, (oscap_destruct_funccxx . . $ oscap_destruct_func#) SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).); |
| 334 | } |
| 335 | |
| 336 | static void values_freecxx . . $ values_free(dbd8f9d05ba37fd5).(struct oscap_htablecxx . . $ oscap_htable# *record) |
| 337 | { |
| 338 | oscap_htable_freecxx . . $ oscap_htable_free(efa5da5da5d523d).(record, (oscap_destruct_funccxx . . $ oscap_destruct_func#) record_freecxx . . $ record_free(27ed2064e5aec1b1).); |
| 339 | } |
| 340 | |
| 341 | static int process_yamlcxx . . $ process_yaml(fdecabb14ed18a8e).(yaml_parser_tcxx . . $ yaml_parser_t# *parser, const char *yamlpath, SEXP_tcxx . . $ SEXP_t# *item, probe_ctxcxx . . $ probe_ctx# *ctx) |
| 342 | { |
| 343 | int ret = 0; |
| 344 | |
| 345 | if (SEXP_typeofcxx . . $ SEXP_typeof(dfe0d2bfa8d6f3af).(item) != SEXP_TYPE_LISTcxx . . $ `src/OVAL/probes/SEAP/public/sexp-types.h:78:9`!) |
| 346 | return -1; |
| 347 | |
| 348 | struct oscap_listcxx . . $ oscap_list# *values = oscap_list_newcxx . . $ oscap_list_new(ea215f73c8361bff).(); |
| 349 | |
| 350 | if (yaml_path_querycxx . . $ yaml_path_query(a60a5f9296a4a78b).(parser, yamlpath, values, ctx)) { |
| 351 | ret = -1; |
| 352 | goto cleanup; |
| 353 | } |
| 354 | |
| 355 | struct oscap_iteratorcxx . . $ oscap_iterator# *values_it = oscap_iterator_newcxx . . $ oscap_iterator_new(f89fb456dfd589d7).(values); |
| 356 | if (oscap_iterator_has_morecxx . . $ oscap_iterator_has_more(63b1de9a5adb9205).(values_it)) { |
| 357 | while (oscap_iterator_has_morecxx . . $ oscap_iterator_has_more(63b1de9a5adb9205).(values_it)) { |
| 358 | SEXP_tcxx . . $ SEXP_t# *result_ent = probe_ent_creat1cxx . . $ probe_ent_creat1(84b3695e4a0e659a).("value", 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`!); |
| 359 | probe_ent_setdatatypecxx . . $ probe_ent_setdatatype(fec947bd1b7be7b5).(result_ent, OVAL_DATATYPE_RECORDcxx . . $ OVAL_DATATYPE_RECORD.); |
| 360 | struct oscap_htablecxx . . $ oscap_htable# *record = oscap_iterator_nextcxx . . $ oscap_iterator_next(4c75051c806960eb).(values_it); |
| 361 | struct oscap_htable_iteratorcxx . . $ oscap_htable_iterator# *record_it = oscap_htable_iterator_newcxx . . $ oscap_htable_iterator_new(81743c99830972e7).(record); |
| 362 | while(oscap_htable_iterator_has_morecxx . . $ oscap_htable_iterator_has_more(eba4198ab3388c55).(record_it)) { |
| 363 | const struct oscap_htable_itemcxx . . $ oscap_htable_item# *record_item = oscap_htable_iterator_nextcxx . . $ oscap_htable_iterator_next(98c5256d433bc020).(record_it); |
| 364 | struct oscap_iteratorcxx . . $ oscap_iterator# *item_value_it = oscap_iterator_newcxx . . $ oscap_iterator_new(f89fb456dfd589d7).(record_item->valuecxx . . $ oscap_htable_item#value.); |
| 365 | SEXP_tcxx . . $ SEXP_t# se_tmp_mem; |
| 366 | SEXP_tcxx . . $ SEXP_t# *key = SEXP_string_new_rcxx . . $ SEXP_string_new_r(26dc94eb5d76b6d1).(&se_tmp_mem, record_item->keycxx . . $ oscap_htable_item#key., strlencxx . . $ strlen(751346f8406fd082).(record_item->keycxx . . $ oscap_htable_item#key.)); |
| 367 | while(oscap_iterator_has_morecxx . . $ oscap_iterator_has_more(63b1de9a5adb9205).(item_value_it)) { |
| 368 | SEXP_tcxx . . $ SEXP_t# *value_sexp = oscap_iterator_nextcxx . . $ oscap_iterator_next(4c75051c806960eb).(item_value_it); |
| 369 | SEXP_tcxx . . $ SEXP_t# *field = probe_ent_creat1cxx . . $ probe_ent_creat1(84b3695e4a0e659a).("field", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, value_sexp); |
| 370 | probe_item_attr_addcxx . . $ probe_item_attr_add(733bdcb6a09ce7ed).(field, "name", key); |
| 371 | SEXP_list_addcxx . . $ SEXP_list_add(35a066576d9f6ea6).(result_ent, field); |
| 372 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(field); |
| 373 | } |
| 374 | oscap_iterator_freecxx . . $ oscap_iterator_free(3cba44c1b7872358).(item_value_it); |
| 375 | SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_tmp_mem); |
| 376 | } |
| 377 | oscap_htable_iterator_freecxx . . $ oscap_htable_iterator_free(e07ea5562ff119bd).(record_it); |
| 378 | SEXP_list_addcxx . . $ SEXP_list_add(35a066576d9f6ea6).(item, result_ent); |
| 379 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(result_ent); |
| 380 | } |
| 381 | probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item); |
| 382 | } |
| 383 | oscap_iterator_freecxx . . $ oscap_iterator_free(3cba44c1b7872358).(values_it); |
| 384 | |
| 385 | cleanup: |
| 386 | oscap_list_freecxx . . $ oscap_list_free(e68e105c3900fcc1).(values, (oscap_destruct_funccxx . . $ oscap_destruct_func#) values_freecxx . . $ values_free(dbd8f9d05ba37fd5).); |
| 387 | |
| 388 | return ret; |
| 389 | } |
| 390 | |
| 391 | static int process_yaml_filecxx . . $ process_yaml_file(47aa398fde4fc20c).(const char *prefix, const char *path, const char *filename, const char *yamlpath, probe_ctxcxx . . $ probe_ctx# *ctx) |
| 392 | { |
| 393 | int ret = 0; |
| 394 | |
| 395 | char *filepath = oscap_path_joincxx . . $ oscap_path_join(a713fe7b9a57cf96).(path, filename); |
| 396 | if (probe_path_is_blockedcxx . . $ probe_path_is_blocked(6f786adec44f4a13).(filepath, ctx->blocked_pathscxx . . $ probe_ctx#blocked_paths.)) { |
| 397 | freecxx . . $ free(5d22bdacc48458e8).(filepath); |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | yaml_parser_tcxx . . $ yaml_parser_t# parser; |
| 402 | yaml_parser_initializecxx . . $ yaml_parser_initialize(3cfc1e679d24aa99).(&parser); |
| 403 | |
| 404 | char *filepath_with_prefix = oscap_path_joincxx . . $ oscap_path_join(a713fe7b9a57cf96).(prefix, filepath); |
| 405 | |
| 406 | FILEcxx . . $ FILE# *yaml_file = fopencxx . . $ fopen(82ec0787cd37e0a3).(filepath_with_prefix, "r"); |
| 407 | if (yaml_file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 408 | result_errorcxx . . $ `src/OVAL/probes/independent/yamlfilecontent_probe.c:185:9`!("Unable to open file '%s': %s", filepath_with_prefix, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 409 | goto cleanup; |
| 410 | } |
| 411 | |
| 412 | yaml_parser_set_input_filecxx . . $ yaml_parser_set_input_file(4779686601ea6eb).(&parser, yaml_file); |
| 413 | |
| 414 | SEXP_tcxx . . $ SEXP_t# *item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).( |
| 415 | OVAL_INDEPENDENT_YAML_FILE_CONTENTcxx . . $ OVAL_INDEPENDENT_YAML_FILE_CONTENT., |
| 416 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 417 | "filepath", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., filepath, |
| 418 | "path", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., path, |
| 419 | "filename", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., filename, |
| 420 | "yamlpath", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., yamlpath, |
| 421 | // TODO: Implement "windows_view", |
| 422 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! |
| 423 | ); |
| 424 | |
| 425 | if (process_yamlcxx . . $ process_yaml(fdecabb14ed18a8e).(&parser, yamlpath, item, ctx)) { |
| 426 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(item); |
| 427 | ret = -1; |
| 428 | goto cleanup; |
| 429 | } |
| 430 | |
| 431 | cleanup: |
| 432 | if (yaml_file != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 433 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(yaml_file); |
| 434 | yaml_parser_deletecxx . . $ yaml_parser_delete(40d81e724c2bc0e).(&parser); |
| 435 | freecxx . . $ free(5d22bdacc48458e8).(filepath_with_prefix); |
| 436 | freecxx . . $ free(5d22bdacc48458e8).(filepath); |
| 437 | |
| 438 | return ret; |
| 439 | } |
| 440 | |
| 441 | static int process_yaml_contentcxx . . $ process_yaml_content(758789663d3f347b).(const char *content, const char *yamlpath, probe_ctxcxx . . $ probe_ctx# *ctx) |
| 442 | { |
| 443 | int ret = 0; |
| 444 | |
| 445 | yaml_parser_tcxx . . $ yaml_parser_t# parser; |
| 446 | yaml_parser_initializecxx . . $ yaml_parser_initialize(3cfc1e679d24aa99).(&parser); |
| 447 | yaml_parser_set_input_stringcxx . . $ yaml_parser_set_input_string(54ce7906a24a3eb4).(&parser, (unsigned char *) content, strlencxx . . $ strlen(751346f8406fd082).(content)); |
| 448 | |
| 449 | SEXP_tcxx . . $ SEXP_t# *item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).( |
| 450 | OVAL_INDEPENDENT_YAML_FILE_CONTENTcxx . . $ OVAL_INDEPENDENT_YAML_FILE_CONTENT., |
| 451 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 452 | "content", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., content, |
| 453 | "yamlpath", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., yamlpath, |
| 454 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! |
| 455 | ); |
| 456 | |
| 457 | if (process_yamlcxx . . $ process_yaml(fdecabb14ed18a8e).(&parser, yamlpath, item, ctx)) { |
| 458 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(item); |
| 459 | ret = -1; |
| 460 | goto cleanup; |
| 461 | } |
| 462 | |
| 463 | cleanup: |
| 464 | yaml_parser_deletecxx . . $ yaml_parser_delete(40d81e724c2bc0e).(&parser); |
| 465 | |
| 466 | return ret; |
| 467 | } |
| 468 | |
| 469 | int yamlfilecontent_probe_maincxx . . $ yamlfilecontent_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *arg) |
| 470 | { |
| 471 | SEXP_tcxx . . $ SEXP_t# *probe_in = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx); |
| 472 | SEXP_tcxx . . $ SEXP_t# *behaviors_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "behaviors", 1); |
| 473 | SEXP_tcxx . . $ SEXP_t# *filepath_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "filepath", 1); |
| 474 | SEXP_tcxx . . $ SEXP_t# *path_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "path", 1); |
| 475 | SEXP_tcxx . . $ SEXP_t# *filename_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "filename", 1); |
| 476 | SEXP_tcxx . . $ SEXP_t# *yamlpath_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "yamlpath", 1); |
| 477 | SEXP_tcxx . . $ SEXP_t# *yamlpath_val = probe_ent_getvalcxx . . $ probe_ent_getval(2f7f980afaaae0f0).(yamlpath_ent); |
| 478 | char *yamlpath_str = SEXP_string_cstrcxx . . $ SEXP_string_cstr(c831a2fa12818dfe).(yamlpath_val); |
| 479 | SEXP_tcxx . . $ SEXP_t# *content_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "content", 1); |
| 480 | SEXP_tcxx . . $ SEXP_t# *content_val = probe_ent_getvalcxx . . $ probe_ent_getval(2f7f980afaaae0f0).(content_ent); |
| 481 | char *content_str = SEXP_string_cstrcxx . . $ SEXP_string_cstr(c831a2fa12818dfe).(content_val); |
| 482 | |
| 483 | if (content_str != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 484 | process_yaml_contentcxx . . $ process_yaml_content(758789663d3f347b).(content_str, yamlpath_str, ctx); |
| 485 | } else { |
| 486 | probe_filebehaviors_canonicalizecxx . . $ probe_filebehaviors_canonicalize(e661f441b24a5de6).(&behaviors_ent); |
| 487 | const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT"); |
| 488 | OVAL_FTScxx . . $ OVAL_FTS# *ofts = oval_fts_open_prefixedcxx . . $ oval_fts_open_prefixed(d2d91f0fe545c5d7).( |
| 489 | prefix, path_ent, filename_ent, filepath_ent, behaviors_ent, |
| 490 | probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx)); |
| 491 | if (ofts != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 492 | OVAL_FTSENTcxx . . $ OVAL_FTSENT# *ofts_ent; |
| 493 | while ((ofts_ent = oval_fts_readcxx . . $ oval_fts_read(592d87f37bbdbe51).(ofts)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 494 | if (ofts_ent->fts_infocxx . . $ $anonymous_type_ebdee0feb58b991e_1#fts_info. == FTS_Fcxx . . $ `<external>/345209348829246610/fts.h:126:9`! |
| 495 | || ofts_ent->fts_infocxx . . $ $anonymous_type_ebdee0feb58b991e_1#fts_info. == FTS_SLcxx . . $ `<external>/345209348829246610/fts.h:130:9`!) { |
| 496 | process_yaml_filecxx . . $ process_yaml_file(47aa398fde4fc20c).(prefix, ofts_ent->pathcxx . . $ $anonymous_type_ebdee0feb58b991e_1#path., ofts_ent->filecxx . . $ $anonymous_type_ebdee0feb58b991e_1#file., |
| 497 | yamlpath_str, ctx); |
| 498 | } |
| 499 | oval_ftsent_freecxx . . $ oval_ftsent_free(7e09326da17d8ab0).(ofts_ent); |
| 500 | } |
| 501 | oval_fts_closecxx . . $ oval_fts_close(cd898f79c195c42c).(ofts); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | freecxx . . $ free(5d22bdacc48458e8).(content_str); |
| 506 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(content_val); |
| 507 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(content_ent); |
| 508 | freecxx . . $ free(5d22bdacc48458e8).(yamlpath_str); |
| 509 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(yamlpath_val); |
| 510 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(yamlpath_ent); |
| 511 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(filename_ent); |
| 512 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(path_ent); |
| 513 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(filepath_ent); |
| 514 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(behaviors_ent); |
| 515 | return 0; |
| 516 | } |