| 1 | /** |
| 2 | * @file cpedict.c |
| 3 | * \brief Interface to Common Platform Enumeration (CPE) Dictionary. |
| 4 | * |
| 5 | * See more details at http://nvd.nist.gov/cpe.cfm |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Copyright 2009--2014 Red Hat Inc., Durham, North Carolina. |
| 10 | * All Rights Reserved. |
| 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Lesser General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2.1 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Lesser General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 | * |
| 26 | * Authors: |
| 27 | * Maros Barabas <[email protected]> |
| 28 | * Lukas Kuklinek <[email protected]> |
| 29 | */ |
| 30 | |
| 31 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 32 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 33 | #endif |
| 34 | |
| 35 | #include "public/cpe_dict.h"cxx . . $ `<file>/src/CPE/public/cpe_dict.h`/ |
| 36 | #include "cpedict_priv.h"cxx . . $ `<file>/src/CPE/cpedict_priv.h`/ |
| 37 | |
| 38 | #include "common/list.h"cxx . . $ `<file>/src/common/list.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/xmlns_priv.h"cxx . . $ `<file>/src/common/xmlns_priv.h`/ |
| 42 | #include "common/elements.h"cxx . . $ `<file>/src/common/elements.h`/ |
| 43 | #include "common/xmltext_priv.h"cxx . . $ `<file>/src/common/xmltext_priv.h`/ |
| 44 | #include "source/oscap_source_priv.h"cxx . . $ `<file>/src/source/oscap_source_priv.h`/ |
| 45 | #include "source/public/oscap_source.h"cxx . . $ `<file>/src/source/public/oscap_source.h`/ |
| 46 | #include <string.h> |
| 47 | |
| 48 | #define CPE_DICT_SUPPORTEDcxx . . $ `src/CPE/cpedict.c:48:9`! "2.3" |
| 49 | |
| 50 | struct cpe_dict_modelcxx . . $ cpe_dict_model# *cpe_dict_model_import_sourcecxx . . $ cpe_dict_model_import_source(855462c7c482ecd).(struct oscap_sourcecxx . . $ oscap_source# *source) |
| 51 | { |
| 52 | xmlTextReadercxx . . $ xmlTextReader# *reader = oscap_source_get_xmlTextReadercxx . . $ oscap_source_get_xmlTextReader(9a7ef22a0934f79d).(source); |
| 53 | if (reader == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 54 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 55 | } |
| 56 | struct cpe_dict_modelcxx . . $ cpe_dict_model# *dict = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 57 | struct cpe_parser_ctxcxx . . $ cpe_parser_ctx# *ctx = cpe_parser_ctx_from_readercxx . . $ cpe_parser_ctx_from_reader(e3d9c9b7d3b0da8).(reader); |
| 58 | if (ctx) { |
| 59 | xmlTextReaderNextNodecxx . . $ xmlTextReaderNextNode(82a242a19623f75).(cpe_parser_ctx_get_readercxx . . $ cpe_parser_ctx_get_reader(85a830d77083ba03).(ctx)); |
| 60 | dict = cpe_dict_model_parsecxx . . $ cpe_dict_model_parse(d014d982a14f83fe).(ctx); |
| 61 | if (dict != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 62 | dict->origin_filecxx . . $ cpe_dict_model#origin_file. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(oscap_source_readable_origincxx . . $ oscap_source_readable_origin(1485dc36ee4b63be).(source)); |
| 63 | } |
| 64 | } |
| 65 | cpe_parser_ctx_freecxx . . $ cpe_parser_ctx_free(270d62ec502b7607).(ctx); |
| 66 | xmlFreeTextReadercxx . . $ xmlFreeTextReader(724dbfdba9ec3ce8).(reader); |
| 67 | return dict; |
| 68 | } |
| 69 | |
| 70 | void cpe_dict_model_exportcxx . . $ cpe_dict_model_export(8b983929fdf096f8).(const struct cpe_dict_modelcxx . . $ cpe_dict_model# *dict, const char *file) |
| 71 | { |
| 72 | |
| 73 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(dict); |
| 74 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(file); |
| 75 | |
| 76 | if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 77 | return; |
| 78 | |
| 79 | cpe_dict_model_export_xmlcxx . . $ cpe_dict_model_export_xml(8b983929fdf096f8).(dict, file); |
| 80 | |
| 81 | } |
| 82 | |
| 83 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_name_match_dictcxx . . $ cpe_name_match_dict(d2c432d3e95f5fe5).(struct cpe_namecxx . . $ cpe_name# * cpe, struct cpe_dict_modelcxx . . $ cpe_dict_model# * dict) |
| 84 | { |
| 85 | // FIXME: We could match faster by matching per component and storing all |
| 86 | // cpe_dict items in a big tree where leaves contain cpe_items and |
| 87 | // inner nodes are the components. |
| 88 | |
| 89 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(cpe); |
| 90 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(dict); |
| 91 | |
| 92 | if (cpe == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || dict == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 93 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 94 | |
| 95 | struct cpe_item_iteratorcxx . . $ cpe_item_iterator# *items = cpe_dict_model_get_itemscxx . . $ cpe_dict_model_get_items(5cb21604d6b88b36).(dict); |
| 96 | |
| 97 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ret = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 98 | while (cpe_item_iterator_has_morecxx . . $ cpe_item_iterator_has_more(7dc86bb14a5a3233).(items)) { |
| 99 | struct cpe_itemcxx . . $ cpe_item#* item = cpe_item_iterator_nextcxx . . $ cpe_item_iterator_next(94b1c680ffbf1664).(items); |
| 100 | struct cpe_namecxx . . $ cpe_name#* name = cpe_item_get_namecxx . . $ cpe_item_get_name(24587e6e1062bef5).(item); |
| 101 | |
| 102 | if (cpe_name_match_onecxx . . $ cpe_name_match_one(4808e5a017f8458a).(name, cpe)) { |
| 103 | ret = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | cpe_item_iterator_freecxx . . $ cpe_item_iterator_free(8056d2d460529853).(items); |
| 108 | return ret; |
| 109 | } |
| 110 | |
| 111 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_name_applicable_dictcxx . . $ cpe_name_applicable_dict(6696ab683acb39a6).(struct cpe_namecxx . . $ cpe_name# *cpe, struct cpe_dict_modelcxx . . $ cpe_dict_model# *dict, cpe_check_fncxx . . $ cpe_check_fn# cb, void* usr) |
| 112 | { |
| 113 | // FIXME: We could match faster by matching per component and storing all |
| 114 | // cpe_dict items in a big tree where leaves contain cpe_items and |
| 115 | // inner nodes are the components. |
| 116 | |
| 117 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(cpe); |
| 118 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(dict); |
| 119 | |
| 120 | if (cpe == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || dict == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 121 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 122 | |
| 123 | struct cpe_item_iteratorcxx . . $ cpe_item_iterator# *items = cpe_dict_model_get_itemscxx . . $ cpe_dict_model_get_items(5cb21604d6b88b36).(dict); |
| 124 | |
| 125 | // essentially, we want at least one applicable match so as soon as we find |
| 126 | // a match we break and return true |
| 127 | |
| 128 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ret = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 129 | while (cpe_item_iterator_has_morecxx . . $ cpe_item_iterator_has_more(7dc86bb14a5a3233).(items)) { |
| 130 | struct cpe_itemcxx . . $ cpe_item#* item = cpe_item_iterator_nextcxx . . $ cpe_item_iterator_next(94b1c680ffbf1664).(items); |
| 131 | struct cpe_namecxx . . $ cpe_name#* name = cpe_item_get_namecxx . . $ cpe_item_get_name(24587e6e1062bef5).(item); |
| 132 | |
| 133 | if (cpe_name_match_onecxx . . $ cpe_name_match_one(4808e5a017f8458a).(cpe, name) && cpe_item_is_applicablecxx . . $ cpe_item_is_applicable(e45db6ac7b8e7003).(item, cb, usr)) { |
| 134 | ret = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | cpe_item_iterator_freecxx . . $ cpe_item_iterator_free(8056d2d460529853).(items); |
| 139 | return ret; |
| 140 | } |
| 141 | |
| 142 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_check_evaluatecxx . . $ cpe_check_evaluate(6745f28d74e653af).(const struct cpe_checkcxx . . $ cpe_check#* check, cpe_check_fncxx . . $ cpe_check_fn# cb, void* usr) |
| 143 | { |
| 144 | const char* sys = cpe_check_get_systemcxx . . $ cpe_check_get_system(342d4d34af16f3fb).(check); |
| 145 | const char* href = cpe_check_get_hrefcxx . . $ cpe_check_get_href(342d4d34af16f3fb).(check); |
| 146 | const char* name = cpe_check_get_identifiercxx . . $ cpe_check_get_identifier(342d4d34af16f3fb).(check); |
| 147 | |
| 148 | return cb(sys, href, name, usr); |
| 149 | } |
| 150 | |
| 151 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_item_is_applicablecxx . . $ cpe_item_is_applicable(e45db6ac7b8e7003).(struct cpe_itemcxx . . $ cpe_item#* item, cpe_check_fncxx . . $ cpe_check_fn# cb, void* usr) |
| 152 | { |
| 153 | struct cpe_check_iteratorcxx . . $ cpe_check_iterator#* checks = cpe_item_get_checkscxx . . $ cpe_item_get_checks(b2cc713b98abec85).(item); |
| 154 | |
| 155 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ret = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 156 | while (cpe_check_iterator_has_morecxx . . $ cpe_check_iterator_has_more(1f70a7097b5c19a8).(checks)) { |
| 157 | struct cpe_checkcxx . . $ cpe_check#* check = cpe_check_iterator_nextcxx . . $ cpe_check_iterator_next(8eec4cf4c916465a).(checks); |
| 158 | if (cpe_check_evaluatecxx . . $ cpe_check_evaluate(6745f28d74e653af).(check, cb, usr)) { |
| 159 | ret = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 160 | break; |
| 161 | } |
| 162 | } |
| 163 | cpe_check_iterator_freecxx . . $ cpe_check_iterator_free(10caa7ebda60033c).(checks); |
| 164 | |
| 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | const char * cpe_dict_model_supportedcxx . . $ cpe_dict_model_supported(33a1f659e94feb42).(void) |
| 169 | { |
| 170 | return CPE_DICT_SUPPORTEDcxx . . $ `src/CPE/cpedict.c:48:9`!; |
| 171 | } |
| 172 | |
| 173 | char *cpe_dict_detect_version_privcxx . . $ cpe_dict_detect_version_priv(93c99f8009311dd0).(xmlTextReadercxx . . $ xmlTextReader# *reader) |
| 174 | { |
| 175 | char *version = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 176 | /* find root element */ |
| 177 | while (xmlTextReaderReadcxx . . $ xmlTextReaderRead(82a242a19623f75).(reader) == 1 |
| 178 | && xmlTextReaderNodeTypecxx . . $ xmlTextReaderNodeType(82a242a19623f75).(reader) != XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT.); |
| 179 | |
| 180 | const char* elm_name = (const char *) xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader); |
| 181 | if (!elm_name || strcmpcxx . . $ strcmp(5ae29d726ae57f88).("cpe-list", elm_name)) { |
| 182 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Expected root element name 'cpe-list', found '%s'.", elm_name); |
| 183 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 184 | } |
| 185 | const char* ns_uri = (const char *) xmlTextReaderConstNamespaceUricxx . . $ xmlTextReaderConstNamespaceUri(60a5affeeceb06fd).(reader); |
| 186 | if (ns_uri == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 187 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OSCAPcxx . . $ `src/common/public/oscap_error.h:60:9`!, "Expected namespace uri for cpe-list, found none."); |
| 188 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 189 | } |
| 190 | |
| 191 | /* find generator */ |
| 192 | while (xmlTextReaderReadcxx . . $ xmlTextReaderRead(82a242a19623f75).(reader) == 1 |
| 193 | && xmlTextReaderNodeTypecxx . . $ xmlTextReaderNodeType(82a242a19623f75).(reader) != XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT.); |
| 194 | elm_name = (const char *) xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader); |
| 195 | |
| 196 | // if the element found is a generator, use it to figure out the version |
| 197 | if (elm_name && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(elm_name, "generator") == 0) { |
| 198 | /* find schema_version */ |
| 199 | const int depth = xmlTextReaderDepthcxx . . $ xmlTextReaderDepth(82a242a19623f75).(reader); |
| 200 | while (xmlTextReaderReadcxx . . $ xmlTextReaderRead(82a242a19623f75).(reader) == 1 && xmlTextReaderDepthcxx . . $ xmlTextReaderDepth(82a242a19623f75).(reader) > depth) { |
| 201 | if (xmlTextReaderNodeTypecxx . . $ xmlTextReaderNodeType(82a242a19623f75).(reader) != XML_READER_TYPE_ELEMENTcxx . . $ XML_READER_TYPE_ELEMENT.) |
| 202 | continue; |
| 203 | |
| 204 | elm_name = (const char *) xmlTextReaderConstLocalNamecxx . . $ xmlTextReaderConstLocalName(60a5affeeceb06fd).(reader); |
| 205 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(elm_name, "schema_version")) { |
| 206 | version = oscap_element_string_copycxx . . $ oscap_element_string_copy(93c99f8009311dd0).(reader); |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | else { |
| 212 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(ns_uri, XMLNS_CPE2Dcxx . . $ `src/common/xmlns_priv.h:34:9`!) == 0) { |
| 213 | // return the newest 2.x version we support |
| 214 | version = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).("2.3"); |
| 215 | } |
| 216 | } |
| 217 | return version; |
| 218 | } |