| 1 | /* |
| 2 | * Copyright 2013 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: Martin Preisler <[email protected]> |
| 20 | */ |
| 21 | |
| 22 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 23 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 24 | #endif |
| 25 | |
| 26 | #include "public/check_engine_plugin.h"cxx . . $ `<file>/src/XCCDF_POLICY/public/check_engine_plugin.h`/ |
| 27 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 28 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 29 | #include "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/ |
| 30 | |
| 31 | #ifndef OS_WINDOWS |
| 32 | #include <dlfcn.h> |
| 33 | #endif |
| 34 | |
| 35 | #define STRINGIZE_NXcxx . . $ `src/XCCDF_POLICY/check_engine_plugin.c:35:9`!(A) #A |
| 36 | #define STRINGIZEcxx . . $ `src/XCCDF_POLICY/check_engine_plugin.c:36:9`!(A) STRINGIZE_NXcxx . . $ `src/XCCDF_POLICY/check_engine_plugin.c:35:9`!(A) |
| 37 | |
| 38 | static struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *check_engine_plugin_def_newcxx . . $ check_engine_plugin_def_new(ef0910cadb4f72ee).(void) |
| 39 | { |
| 40 | struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *ret = (struct check_engine_plugin_defcxx . . $ check_engine_plugin_def#*) calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct check_engine_plugin_defcxx . . $ check_engine_plugin_def#)); |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static void check_engine_plugin_def_freecxx . . $ check_engine_plugin_def_free(be78ae89c758d8d0).(struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *plugin) |
| 45 | { |
| 46 | //if (plugin->module_handle) |
| 47 | // FIXME: Warning? |
| 48 | |
| 49 | freecxx . . $ free(5d22bdacc48458e8).(plugin); |
| 50 | } |
| 51 | |
| 52 | struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *check_engine_plugin_load2cxx . . $ check_engine_plugin_load2(9071ba705b7532d3).(const char* path, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! quiet) |
| 53 | { |
| 54 | #ifndef OS_WINDOWS |
| 55 | struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *ret = check_engine_plugin_def_newcxx . . $ check_engine_plugin_def_new(ef0910cadb4f72ee).(); |
| 56 | |
| 57 | const char *path_prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_CHECK_ENGINE_PLUGIN_DIR"); |
| 58 | char *full_path = path_prefix ? oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%s/%s", path_prefix, path) : oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(path); |
| 59 | // NB: valgrind reports a leak on the next line, I have confirmed this to be a false positive |
| 60 | ret->module_handlecxx . . $ check_engine_plugin_def#module_handle. = dlopencxx . . $ dlopen(fb9ec0bb113f3da8).(full_path, RTLD_LAZYcxx . . $ `<external>/10632388298615623587/dlfcn.h:24:9`!); |
| 61 | freecxx . . $ free(5d22bdacc48458e8).(full_path); |
| 62 | |
| 63 | char *error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 64 | if (!ret->module_handlecxx . . $ check_engine_plugin_def#module_handle.) { |
| 65 | error = dlerrorcxx . . $ dlerror(41208ce6ca65dd58).(); |
| 66 | |
| 67 | if (!quiet) |
| 68 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 69 | "Failed to load extra check engine from '%s'. Details: '%s'.", |
| 70 | path, error); |
| 71 | |
| 72 | check_engine_plugin_def_freecxx . . $ check_engine_plugin_def_free(be78ae89c758d8d0).(ret); |
| 73 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 74 | } |
| 75 | |
| 76 | check_engine_plugin_entry_fncxx . . $ check_engine_plugin_entry_fn# entry_fn = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 77 | *(void **)(&entry_fn) = dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(ret->module_handlecxx . . $ check_engine_plugin_def#module_handle., STRINGIZEcxx . . $ `src/XCCDF_POLICY/check_engine_plugin.c:36:9`!(OPENSCAP_CHECK_ENGINE_PLUGIN_ENTRYcxx . . $ `src/XCCDF_POLICY/public/check_engine_plugin.h:70:9`!)); |
| 78 | |
| 79 | if ((error = dlerrorcxx . . $ dlerror(41208ce6ca65dd58).()) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 80 | if (!quiet) |
| 81 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 82 | "Failed to retrieve module entry '%s' from loaded extra check engine '%s'. Details: '%s'.", |
| 83 | STRINGIZEcxx . . $ `src/XCCDF_POLICY/check_engine_plugin.c:36:9`!(OPENSCAP_CHECK_ENGINE_PLUGIN_ENTRYcxx . . $ `src/XCCDF_POLICY/public/check_engine_plugin.h:70:9`!), path, error); |
| 84 | |
| 85 | dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(ret->module_handlecxx . . $ check_engine_plugin_def#module_handle.); |
| 86 | check_engine_plugin_def_freecxx . . $ check_engine_plugin_def_free(be78ae89c758d8d0).(ret); |
| 87 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 88 | } |
| 89 | |
| 90 | if ((*entry_fn)(ret) != 0) { |
| 91 | if (!quiet) |
| 92 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 93 | "Failed to fill check_engine_plugin_def when loading check engine plugin '%s'.", path); |
| 94 | |
| 95 | dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(ret->module_handlecxx . . $ check_engine_plugin_def#module_handle.); |
| 96 | check_engine_plugin_def_freecxx . . $ check_engine_plugin_def_free(be78ae89c758d8d0).(ret); |
| 97 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 98 | } |
| 99 | |
| 100 | return ret; |
| 101 | #else |
| 102 | // TODO |
| 103 | return NULL; |
| 104 | #endif |
| 105 | } |
| 106 | |
| 107 | struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *check_engine_plugin_loadcxx . . $ check_engine_plugin_load(6b0bd49d80dee2ea).(const char* path) |
| 108 | { |
| 109 | return check_engine_plugin_load2cxx . . $ check_engine_plugin_load2(9071ba705b7532d3).(path, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); |
| 110 | } |
| 111 | |
| 112 | void check_engine_plugin_unloadcxx . . $ check_engine_plugin_unload(be78ae89c758d8d0).(struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *plugin) |
| 113 | { |
| 114 | #ifndef OS_WINDOWS |
| 115 | if (!plugin->module_handlecxx . . $ check_engine_plugin_def#module_handle.) { |
| 116 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 117 | "Failed to unload this check engine plugin. It seems the plugin hasn't been loaded!"); |
| 118 | } |
| 119 | else { |
| 120 | dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(plugin->module_handlecxx . . $ check_engine_plugin_def#module_handle.); |
| 121 | plugin->module_handlecxx . . $ check_engine_plugin_def#module_handle. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 122 | } |
| 123 | #else |
| 124 | // TODO |
| 125 | #endif |
| 126 | |
| 127 | check_engine_plugin_def_freecxx . . $ check_engine_plugin_def_free(be78ae89c758d8d0).(plugin); |
| 128 | } |
| 129 | |
| 130 | int check_engine_plugin_registercxx . . $ check_engine_plugin_register(5f88fd8f7be40b51).(struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *plugin, struct xccdf_policy_modelcxx . . $ xccdf_policy_model# *model, const char* path_hint) |
| 131 | { |
| 132 | if (!plugin->module_handlecxx . . $ check_engine_plugin_def#module_handle.) { |
| 133 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 134 | "Failed to register this check engine plugin to given policy_model, the plugin hasn't been loaded!"); |
| 135 | |
| 136 | return -1; |
| 137 | } |
| 138 | |
| 139 | if (!plugin->register_fncxx . . $ check_engine_plugin_def#register_fn.) { |
| 140 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 141 | "Plugin seems to have been loaded but its register_fn member hasn't been filled. Bad plugin entry function implementation suspected."); |
| 142 | |
| 143 | return -1; |
| 144 | } |
| 145 | |
| 146 | return (plugin->register_fncxx . . $ check_engine_plugin_def#register_fn.)(model, path_hint, &plugin->user_datacxx . . $ check_engine_plugin_def#user_data.); |
| 147 | } |
| 148 | |
| 149 | int check_engine_plugin_cleanupcxx . . $ check_engine_plugin_cleanup(1e3e5a4311b15a9f).(struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *plugin, struct xccdf_policy_modelcxx . . $ xccdf_policy_model# *model) |
| 150 | { |
| 151 | if (!plugin->module_handlecxx . . $ check_engine_plugin_def#module_handle.) { |
| 152 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 153 | "Failed to cleanup this check engine plugin, the plugin hasn't been loaded!"); |
| 154 | |
| 155 | return -1; |
| 156 | } |
| 157 | |
| 158 | if (!plugin->cleanup_fncxx . . $ check_engine_plugin_def#cleanup_fn.) { |
| 159 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 160 | "Plugin seems to have been loaded but its cleanup_fn member hasn't been filled. Bad plugin entry function implementation suspected."); |
| 161 | |
| 162 | return -1; |
| 163 | } |
| 164 | |
| 165 | return (plugin->cleanup_fncxx . . $ check_engine_plugin_def#cleanup_fn.)(model, &plugin->user_datacxx . . $ check_engine_plugin_def#user_data.); |
| 166 | } |
| 167 | |
| 168 | int check_engine_plugin_export_resultscxx . . $ check_engine_plugin_export_results(91b4e5814a106804).(struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *plugin, struct xccdf_policy_modelcxx . . $ xccdf_policy_model# *model, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! validate, const char *path_hint) |
| 169 | { |
| 170 | if (!plugin->module_handlecxx . . $ check_engine_plugin_def#module_handle.) { |
| 171 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 172 | "Failed to export results from this check engine plugin, the plugin hasn't been loaded!"); |
| 173 | |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | if (!plugin->export_results_fncxx . . $ check_engine_plugin_def#export_results_fn.) { |
| 178 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 179 | "Plugin seems to have been loaded but its export_results_fn member hasn't been filled. Bad plugin entry function implementation suspected."); |
| 180 | |
| 181 | return -1; |
| 182 | } |
| 183 | |
| 184 | return (plugin->export_results_fncxx . . $ check_engine_plugin_def#export_results_fn.)(model, validate, path_hint, &plugin->user_datacxx . . $ check_engine_plugin_def#user_data.); |
| 185 | } |
| 186 | |
| 187 | const char *check_engine_plugin_get_capabilitiescxx . . $ check_engine_plugin_get_capabilities(8ffb468a72dc1f09).(struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *plugin) |
| 188 | { |
| 189 | if (!plugin->module_handlecxx . . $ check_engine_plugin_def#module_handle.) { |
| 190 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 191 | "Failed to get capabilities of this check engine plugin, the plugin hasn't been loaded!"); |
| 192 | |
| 193 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 194 | } |
| 195 | |
| 196 | if (!plugin->get_capabilities_fncxx . . $ check_engine_plugin_def#get_capabilities_fn.) { |
| 197 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_GLIBCcxx . . $ `src/common/public/oscap_error.h:58:9`!, |
| 198 | "Plugin seems to have been loaded but its get_capabilities_fn member hasn't been filled. Bad plugin entry function implementation suspected."); |
| 199 | |
| 200 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 201 | } |
| 202 | |
| 203 | return (plugin->get_capabilities_fncxx . . $ check_engine_plugin_def#get_capabilities_fn.)(&plugin->user_datacxx . . $ check_engine_plugin_def#user_data.); |
| 204 | } |
| 205 | |
| 206 | #ifndef LT_CURRENT_MINUS_AGEcxx . . $ `build/config.h:9:9`! |
| 207 | #error "LT_CURRENT_MINUS_AGE has not been defined! It is necessary to figure out plugin paths to load." |
| 208 | #endif |
| 209 | |
| 210 | const char * const known_pluginscxx . . $ known_plugins.[] = {"libopenscap_sce.so." STRINGIZEcxx . . $ `src/XCCDF_POLICY/check_engine_plugin.c:36:9`!(LT_CURRENT_MINUS_AGEcxx . . $ `build/config.h:9:9`!), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!}; |
| 211 | |
| 212 | const char * const *check_engine_plugin_get_known_pluginscxx . . $ check_engine_plugin_get_known_plugins(93405d8a1d31001f).(void) |
| 213 | { |
| 214 | return known_pluginscxx . . $ known_plugins.; |
| 215 | } |