| 1 | /** |
| 2 | * @file sce_engine.c |
| 3 | * \brief Script Check Engine |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Copyright 2011--2013 Red Hat Inc., Durham, North Carolina. |
| 8 | * All Rights Reserved. |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Lesser General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2.1 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with this library; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | * |
| 24 | * Authors: |
| 25 | * "Martin Preisler" <[email protected]> |
| 26 | */ |
| 27 | |
| 28 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 29 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 30 | #endif |
| 31 | |
| 32 | #include "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/ |
| 33 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 34 | #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/ |
| 35 | #include "common/oscap_acquire.h"cxx . . $ `<file>/src/common/oscap_acquire.h`/ |
| 36 | #include "common/oscap_string.h"cxx . . $ `<file>/src/common/oscap_string.h`/ |
| 37 | #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 38 | #include "sce_engine_api.h"cxx . . $ `<file>/src/SCE/public/sce_engine_api.h`/ |
| 39 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 40 | |
| 41 | #include <stdlib.h> |
| 42 | #include <string.h> |
| 43 | #include <stdio.h> |
| 44 | |
| 45 | #if defined(OS_FREEBSD) |
| 46 | #include <sys/procctl.h> |
| 47 | #include <signal.h> |
| 48 | #include <sys/wait.h> |
| 49 | #else |
| 50 | #include <wait.h> |
| 51 | #endif |
| 52 | |
| 53 | #include <unistd.h> |
| 54 | #include <sys/stat.h> |
| 55 | #include <assert.h> |
| 56 | #include <fcntl.h> |
| 57 | #include <sys/types.h> |
| 58 | #if defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!) |
| 59 | #include <sys/prctl.h> |
| 60 | #endif |
| 61 | #include <limits.h> |
| 62 | #include <unistd.h> |
| 63 | #include <libgen.h> |
| 64 | |
| 65 | #define SCE_SCRIPTcxx . . $ `src/SCE/sce_engine.c:65:9`! "oscap-run-sce-script" |
| 66 | |
| 67 | struct sce_check_resultcxx . . $ sce_check_result# |
| 68 | { |
| 69 | char* hrefcxx . . $ sce_check_result#href.; |
| 70 | char* basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!; |
| 71 | char* std_outcxx . . $ sce_check_result#std_out.; |
| 72 | char* std_errcxx . . $ sce_check_result#std_err.; |
| 73 | int exit_codecxx . . $ sce_check_result#exit_code.; |
| 74 | struct oscap_stringlistcxx . . $ oscap_stringlist#* environment_variablescxx . . $ sce_check_result#environment_variables.; |
| 75 | xccdf_test_result_type_tcxx . . $ xccdf_test_result_type_t# xccdf_resultcxx . . $ sce_check_result#xccdf_result.; |
| 76 | }; |
| 77 | |
| 78 | struct sce_check_resultcxx . . $ sce_check_result#* sce_check_result_newcxx . . $ sce_check_result_new(322c8399b548b45a).(void) |
| 79 | { |
| 80 | struct sce_check_resultcxx . . $ sce_check_result#* ret = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct sce_check_resultcxx . . $ sce_check_result#)); |
| 81 | ret->hrefcxx . . $ sce_check_result#href. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 82 | ret->basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`! = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 83 | ret->std_outcxx . . $ sce_check_result#std_out. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 84 | ret->std_errcxx . . $ sce_check_result#std_err. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 85 | ret->environment_variablescxx . . $ sce_check_result#environment_variables. = oscap_stringlist_newcxx . . $ oscap_stringlist_new(22a991cfbca9a1c).(); |
| 86 | ret->xccdf_resultcxx . . $ sce_check_result#xccdf_result. = XCCDF_RESULT_UNKNOWNcxx . . $ XCCDF_RESULT_UNKNOWN.; |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | void sce_check_result_freecxx . . $ sce_check_result_free(62a0ea64ab464323).(struct sce_check_resultcxx . . $ sce_check_result#* v) |
| 92 | { |
| 93 | if (!v) |
| 94 | return; |
| 95 | |
| 96 | freecxx . . $ free(5d22bdacc48458e8).(v->hrefcxx . . $ sce_check_result#href.); |
| 97 | freecxx . . $ free(5d22bdacc48458e8).(v->basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!); |
| 98 | freecxx . . $ free(5d22bdacc48458e8).(v->std_outcxx . . $ sce_check_result#std_out.); |
| 99 | freecxx . . $ free(5d22bdacc48458e8).(v->std_errcxx . . $ sce_check_result#std_err.); |
| 100 | |
| 101 | oscap_stringlist_freecxx . . $ oscap_stringlist_free(7df8e35292df4dfb).(v->environment_variablescxx . . $ sce_check_result#environment_variables.); |
| 102 | |
| 103 | freecxx . . $ free(5d22bdacc48458e8).(v); |
| 104 | } |
| 105 | |
| 106 | void sce_check_result_set_hrefcxx . . $ sce_check_result_set_href(84ed1ba2de1ba4ee).(struct sce_check_resultcxx . . $ sce_check_result#* v, const char* href) |
| 107 | { |
| 108 | freecxx . . $ free(5d22bdacc48458e8).(v->hrefcxx . . $ sce_check_result#href.); |
| 109 | v->hrefcxx . . $ sce_check_result#href. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(href); |
| 110 | } |
| 111 | |
| 112 | const char* sce_check_result_get_hrefcxx . . $ sce_check_result_get_href(a3aefccd2beab286).(struct sce_check_resultcxx . . $ sce_check_result#* v) |
| 113 | { |
| 114 | return v->hrefcxx . . $ sce_check_result#href.; |
| 115 | } |
| 116 | |
| 117 | void sce_check_result_set_basenamecxx . . $ sce_check_result_set_basename(84ed1ba2de1ba4ee).(struct sce_check_resultcxx . . $ sce_check_result#* v, const char* base_name) |
| 118 | { |
| 119 | freecxx . . $ free(5d22bdacc48458e8).(v->basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!); |
| 120 | v->basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`! = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(base_name); |
| 121 | } |
| 122 | |
| 123 | const char* sce_check_result_get_basenamecxx . . $ sce_check_result_get_basename(a3aefccd2beab286).(struct sce_check_resultcxx . . $ sce_check_result#* v) |
| 124 | { |
| 125 | return v->basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!; |
| 126 | } |
| 127 | |
| 128 | void sce_check_result_set_stdoutcxx . . $ sce_check_result_set_stdout(84ed1ba2de1ba4ee).(struct sce_check_resultcxx . . $ sce_check_result#* v, const char* _stdout) |
| 129 | { |
| 130 | freecxx . . $ free(5d22bdacc48458e8).(v->std_outcxx . . $ sce_check_result#std_out.); |
| 131 | v->std_outcxx . . $ sce_check_result#std_out. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(_stdout); |
| 132 | } |
| 133 | |
| 134 | const char* sce_check_result_get_stdoutcxx . . $ sce_check_result_get_stdout(a3aefccd2beab286).(struct sce_check_resultcxx . . $ sce_check_result#* v) |
| 135 | { |
| 136 | return v->std_outcxx . . $ sce_check_result#std_out.; |
| 137 | } |
| 138 | |
| 139 | void sce_check_result_set_stderrcxx . . $ sce_check_result_set_stderr(84ed1ba2de1ba4ee).(struct sce_check_resultcxx . . $ sce_check_result#* v, const char* _stderr) |
| 140 | { |
| 141 | freecxx . . $ free(5d22bdacc48458e8).(v->std_errcxx . . $ sce_check_result#std_err.); |
| 142 | v->std_errcxx . . $ sce_check_result#std_err. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(_stderr); |
| 143 | } |
| 144 | |
| 145 | const char* sce_check_result_get_stderrcxx . . $ sce_check_result_get_stderr(a3aefccd2beab286).(struct sce_check_resultcxx . . $ sce_check_result#* v) |
| 146 | { |
| 147 | return v->std_errcxx . . $ sce_check_result#std_err.; |
| 148 | } |
| 149 | |
| 150 | void sce_check_result_set_exit_codecxx . . $ sce_check_result_set_exit_code(f11ef7399be4a329).(struct sce_check_resultcxx . . $ sce_check_result#* v, int exit_code) |
| 151 | { |
| 152 | v->exit_codecxx . . $ sce_check_result#exit_code. = exit_code; |
| 153 | } |
| 154 | |
| 155 | int sce_check_result_get_exit_codecxx . . $ sce_check_result_get_exit_code(54f4f742a21f18e1).(struct sce_check_resultcxx . . $ sce_check_result#* v) |
| 156 | { |
| 157 | return v->exit_codecxx . . $ sce_check_result#exit_code.; |
| 158 | } |
| 159 | |
| 160 | void sce_check_result_reset_environment_variablescxx . . $ sce_check_result_reset_environment_variables(62a0ea64ab464323).(struct sce_check_resultcxx . . $ sce_check_result#* v) |
| 161 | { |
| 162 | oscap_stringlist_freecxx . . $ oscap_stringlist_free(7df8e35292df4dfb).(v->environment_variablescxx . . $ sce_check_result#environment_variables.); |
| 163 | v->environment_variablescxx . . $ sce_check_result#environment_variables. = oscap_stringlist_newcxx . . $ oscap_stringlist_new(22a991cfbca9a1c).(); |
| 164 | } |
| 165 | |
| 166 | void sce_check_result_add_environment_variablecxx . . $ sce_check_result_add_environment_variable(84ed1ba2de1ba4ee).(struct sce_check_resultcxx . . $ sce_check_result#* v, const char* var) |
| 167 | { |
| 168 | oscap_stringlist_add_stringcxx . . $ oscap_stringlist_add_string(80c12aaea9c014af).(v->environment_variablescxx . . $ sce_check_result#environment_variables., var); |
| 169 | } |
| 170 | |
| 171 | void sce_check_result_set_xccdf_resultcxx . . $ sce_check_result_set_xccdf_result(c0fb5b9a2a42dcd).(struct sce_check_resultcxx . . $ sce_check_result#* v, xccdf_test_result_type_tcxx . . $ xccdf_test_result_type_t# result) |
| 172 | { |
| 173 | v->xccdf_resultcxx . . $ sce_check_result#xccdf_result. = result; |
| 174 | } |
| 175 | |
| 176 | xccdf_test_result_type_tcxx . . $ xccdf_test_result_type_t# sce_check_result_get_xccdf_resultcxx . . $ sce_check_result_get_xccdf_result(dbc7076846e2676c).(struct sce_check_resultcxx . . $ sce_check_result#* v) |
| 177 | { |
| 178 | return v->xccdf_resultcxx . . $ sce_check_result#xccdf_result.; |
| 179 | } |
| 180 | |
| 181 | void sce_check_result_exportcxx . . $ sce_check_result_export(84ed1ba2de1ba4ee).(struct sce_check_resultcxx . . $ sce_check_result#* v, const char* target_file) |
| 182 | { |
| 183 | FILEcxx . . $ FILE#* f = fopencxx . . $ fopen(82ec0787cd37e0a3).(target_file, "w"); |
| 184 | if (!f) |
| 185 | { |
| 186 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_SCEcxx . . $ `src/common/public/oscap_error.h:63:9`!, "Can't open file '%s' for writing.", target_file); |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); |
| 191 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "<sceres:sce_results xmlns:sceres=\"http://open-scap.org/page/SCE_result_file\" script-path=\"%s\">\n", sce_check_result_get_basenamecxx . . $ sce_check_result_get_basename(a3aefccd2beab286).(v)); |
| 192 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t<sceres:environment>\n"); |
| 193 | struct oscap_string_iteratorcxx . . $ oscap_string_iterator#* it = oscap_stringlist_get_stringscxx . . $ oscap_stringlist_get_strings(13be827fcd32d2b9).(v->environment_variablescxx . . $ sce_check_result#environment_variables.); |
| 194 | while (oscap_string_iterator_has_morecxx . . $ oscap_string_iterator_has_more(3724f2faf2515a82).(it)) |
| 195 | { |
| 196 | const char* env = oscap_string_iterator_nextcxx . . $ oscap_string_iterator_next(1f2a9ae2534eef34).(it); |
| 197 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t\t<sceres:entry><![CDATA[%s]]></sceres:entry>\n", env); |
| 198 | } |
| 199 | oscap_string_iterator_freecxx . . $ oscap_string_iterator_free(41a77e9ce361f406).(it); |
| 200 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t</sceres:environment>\n"); |
| 201 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t<sceres:stdout><![CDATA[\n"); |
| 202 | size_t ret = fwritecxx . . $ fwrite(ab0609fa07c47d6e).(v->std_outcxx . . $ sce_check_result#std_out., 1, strlencxx . . $ strlen(751346f8406fd082).(v->std_outcxx . . $ sce_check_result#std_out.), f); |
| 203 | if (ret < strlencxx . . $ strlen(751346f8406fd082).(v->std_outcxx . . $ sce_check_result#std_out.)) |
| 204 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_SCEcxx . . $ `src/common/public/oscap_error.h:63:9`!, "Failed to write stdout result to %s.\n", target_file); |
| 205 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t]]></sceres:stdout>\n"); |
| 206 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t<sceres:stderr><![CDATA[\n"); |
| 207 | ret = fwritecxx . . $ fwrite(ab0609fa07c47d6e).(v->std_errcxx . . $ sce_check_result#std_err., 1, strlencxx . . $ strlen(751346f8406fd082).(v->std_errcxx . . $ sce_check_result#std_err.), f); |
| 208 | if (ret < strlencxx . . $ strlen(751346f8406fd082).(v->std_errcxx . . $ sce_check_result#std_err.)) |
| 209 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_SCEcxx . . $ `src/common/public/oscap_error.h:63:9`!, "Failed to write stderr result to %s.\n", target_file); |
| 210 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t]]></sceres:stderr>\n"); |
| 211 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t<sceres:exit_code>%i</sceres:exit_code>\n", sce_check_result_get_exit_codecxx . . $ sce_check_result_get_exit_code(54f4f742a21f18e1).(v)); |
| 212 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "\t<sceres:result>%s</sceres:result>\n", xccdf_test_result_type_get_textcxx . . $ xccdf_test_result_type_get_text(b7e1b929574c5650).(sce_check_result_get_xccdf_resultcxx . . $ sce_check_result_get_xccdf_result(dbc7076846e2676c).(v))); |
| 213 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "</sceres:sce_results>\n"); |
| 214 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(f); |
| 215 | } |
| 216 | |
| 217 | struct sce_sessioncxx . . $ sce_session# |
| 218 | { |
| 219 | struct oscap_listcxx . . $ oscap_list#* resultscxx . . $ sce_session#results.; |
| 220 | }; |
| 221 | |
| 222 | struct sce_sessioncxx . . $ sce_session#* sce_session_newcxx . . $ sce_session_new(f6756c21b4c547d7).(void) |
| 223 | { |
| 224 | struct sce_sessioncxx . . $ sce_session#* ret = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct sce_sessioncxx . . $ sce_session#)); |
| 225 | ret->resultscxx . . $ sce_session#results. = oscap_list_newcxx . . $ oscap_list_new(ea215f73c8361bff).(); |
| 226 | |
| 227 | return ret; |
| 228 | } |
| 229 | |
| 230 | void sce_session_freecxx . . $ sce_session_free(74296c8485745771).(struct sce_sessioncxx . . $ sce_session#* s) |
| 231 | { |
| 232 | if (!s) |
| 233 | return; |
| 234 | |
| 235 | oscap_list_freecxx . . $ oscap_list_free(e68e105c3900fcc1).(s->resultscxx . . $ sce_session#results., (oscap_destruct_funccxx . . $ oscap_destruct_func#) sce_check_result_freecxx . . $ sce_check_result_free(62a0ea64ab464323).); |
| 236 | freecxx . . $ free(5d22bdacc48458e8).(s); |
| 237 | } |
| 238 | |
| 239 | void sce_session_resetcxx . . $ sce_session_reset(74296c8485745771).(struct sce_sessioncxx . . $ sce_session#* s) |
| 240 | { |
| 241 | oscap_list_freecxx . . $ oscap_list_free(e68e105c3900fcc1).(s->resultscxx . . $ sce_session#results., (oscap_destruct_funccxx . . $ oscap_destruct_func#) sce_check_result_freecxx . . $ sce_check_result_free(62a0ea64ab464323).); |
| 242 | s->resultscxx . . $ sce_session#results. = oscap_list_newcxx . . $ oscap_list_new(ea215f73c8361bff).(); |
| 243 | } |
| 244 | |
| 245 | void sce_session_add_check_resultcxx . . $ sce_session_add_check_result(c66b63514b8ed67a).(struct sce_sessioncxx . . $ sce_session#* s, struct sce_check_resultcxx . . $ sce_check_result#* result) |
| 246 | { |
| 247 | oscap_list_pushcxx . . $ oscap_list_push(97f28760a5cf7823).(s->resultscxx . . $ sce_session#results., result); |
| 248 | } |
| 249 | |
| 250 | OSCAP_ITERATOR_GENcxx . . $ `src/common/util.h:123:9`!(sce_check_result) |
| 251 | |
| 252 | struct sce_check_result_iteratorcxx . . $ sce_check_result_iterator# *sce_session_get_check_resultscxx . . $ sce_session_get_check_results(631e7e3c7918875b).(struct sce_sessioncxx . . $ sce_session#* s) |
| 253 | { |
| 254 | return oscap_iterator_newcxx . . $ oscap_iterator_new(f89fb456dfd589d7).(s->resultscxx . . $ sce_session#results.); |
| 255 | } |
| 256 | |
| 257 | void sce_session_export_to_directorycxx . . $ sce_session_export_to_directory(6a87d3a4f50413cd).(struct sce_sessioncxx . . $ sce_session#* s, const char* directory) |
| 258 | { |
| 259 | struct sce_check_result_iteratorcxx . . $ sce_check_result_iterator# * it = sce_session_get_check_resultscxx . . $ sce_session_get_check_results(631e7e3c7918875b).(s); |
| 260 | |
| 261 | while(sce_check_result_iterator_has_morecxx . . $ sce_check_result_iterator_has_more(8878db1c6e4b4ae3).(it)) |
| 262 | { |
| 263 | struct sce_check_resultcxx . . $ sce_check_result# * result = sce_check_result_iterator_nextcxx . . $ sce_check_result_iterator_next(635aa288c67a5480).(it); |
| 264 | char* target = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%s/%s.result.xml", directory, sce_check_result_get_basenamecxx . . $ sce_check_result_get_basename(a3aefccd2beab286).(result)); |
| 265 | sce_check_result_exportcxx . . $ sce_check_result_export(84ed1ba2de1ba4ee).(result, target); |
| 266 | freecxx . . $ free(5d22bdacc48458e8).(target); |
| 267 | } |
| 268 | |
| 269 | sce_check_result_iterator_freecxx . . $ sce_check_result_iterator_free(80927f24f3dab80a).(it); |
| 270 | } |
| 271 | |
| 272 | struct sce_parameterscxx . . $ sce_parameters# |
| 273 | { |
| 274 | char* xccdf_directorycxx . . $ sce_parameters#xccdf_directory.; |
| 275 | struct sce_sessioncxx . . $ sce_session#* sessioncxx . . $ sce_parameters#session.; |
| 276 | }; |
| 277 | |
| 278 | struct sce_parameterscxx . . $ sce_parameters#* sce_parameters_newcxx . . $ sce_parameters_new(41e602c2677de0c6).(void) |
| 279 | { |
| 280 | struct sce_parameterscxx . . $ sce_parameters# *ret = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct sce_parameterscxx . . $ sce_parameters#)); |
| 281 | ret->xccdf_directorycxx . . $ sce_parameters#xccdf_directory. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 282 | ret->sessioncxx . . $ sce_parameters#session. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 283 | |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | void sce_parameters_freecxx . . $ sce_parameters_free(3951596372db9be1).(struct sce_parameterscxx . . $ sce_parameters#* v) |
| 288 | { |
| 289 | if (!v) |
| 290 | return; |
| 291 | |
| 292 | freecxx . . $ free(5d22bdacc48458e8).(v->xccdf_directorycxx . . $ sce_parameters#xccdf_directory.); |
| 293 | sce_session_freecxx . . $ sce_session_free(74296c8485745771).(v->sessioncxx . . $ sce_parameters#session.); |
| 294 | |
| 295 | freecxx . . $ free(5d22bdacc48458e8).(v); |
| 296 | } |
| 297 | |
| 298 | void sce_parameters_set_xccdf_directorycxx . . $ sce_parameters_set_xccdf_directory(3f4426a8c3afb843).(struct sce_parameterscxx . . $ sce_parameters#* v, const char* value) |
| 299 | { |
| 300 | if (v->xccdf_directorycxx . . $ sce_parameters#xccdf_directory.) |
| 301 | freecxx . . $ free(5d22bdacc48458e8).(v->xccdf_directorycxx . . $ sce_parameters#xccdf_directory.); |
| 302 | |
| 303 | v->xccdf_directorycxx . . $ sce_parameters#xccdf_directory. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(value); |
| 304 | } |
| 305 | |
| 306 | const char* sce_parameters_get_xccdf_directorycxx . . $ sce_parameters_get_xccdf_directory(242b3437fef71b0c).(struct sce_parameterscxx . . $ sce_parameters#* v) |
| 307 | { |
| 308 | return v->xccdf_directorycxx . . $ sce_parameters#xccdf_directory.; |
| 309 | } |
| 310 | |
| 311 | void sce_parameters_set_sessioncxx . . $ sce_parameters_set_session(d48b77f9d6468b6c).(struct sce_parameterscxx . . $ sce_parameters#* v, struct sce_sessioncxx . . $ sce_session#* value) |
| 312 | { |
| 313 | sce_session_freecxx . . $ sce_session_free(74296c8485745771).(v->sessioncxx . . $ sce_parameters#session.); |
| 314 | v->sessioncxx . . $ sce_parameters#session. = value; |
| 315 | } |
| 316 | |
| 317 | struct sce_sessioncxx . . $ sce_session#* sce_parameters_get_sessioncxx . . $ sce_parameters_get_session(a4b1286c3a37b79d).(struct sce_parameterscxx . . $ sce_parameters#* v) |
| 318 | { |
| 319 | return v->sessioncxx . . $ sce_parameters#session.; |
| 320 | } |
| 321 | |
| 322 | void sce_parameters_allocate_sessioncxx . . $ sce_parameters_allocate_session(3951596372db9be1).(struct sce_parameterscxx . . $ sce_parameters#* v) |
| 323 | { |
| 324 | sce_parameters_set_sessioncxx . . $ sce_parameters_set_session(d48b77f9d6468b6c).(v, sce_session_newcxx . . $ sce_session_new(f6756c21b4c547d7).()); |
| 325 | } |
| 326 | |
| 327 | static void _pipe_try_read_into_stringcxx . . $ _pipe_try_read_into_string(314125bd0f8b5e).(int fd, struct oscap_stringcxx . . $ oscap_string# *string, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! *eof) |
| 328 | { |
| 329 | // FIXME: Read by larger chunks in the future |
| 330 | char readbuf; |
| 331 | while (truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!) { |
| 332 | const int read_status = readcxx . . $ read(7e34d0a36f355389).(fd, &readbuf, 1); |
| 333 | if (read_status == 1) { // successful read |
| 334 | if (readbuf == '&') { |
| 335 | // & is a special case, we have to "escape" it manually |
| 336 | // (all else will eventually get handled by libxml) |
| 337 | oscap_string_append_stringcxx . . $ oscap_string_append_string(bdf4962f194308bb).(string, "&"); |
| 338 | } else { |
| 339 | oscap_string_append_charcxx . . $ oscap_string_append_char(10528718cb7e122a).(string, readbuf); |
| 340 | } |
| 341 | } |
| 342 | else if (read_status == 0) { // EOF |
| 343 | *eof = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 344 | break; |
| 345 | } |
| 346 | else { |
| 347 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!) { |
| 348 | // NOOP, we are waiting for more input |
| 349 | break; |
| 350 | } |
| 351 | else { |
| 352 | *eof = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; // signal EOF to exit the loops |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | |
| 360 | static void free_env_valuescxx . . $ free_env_values(170bbbf817437443).(char **env_values, size_t index_of_first_env_value_not_compiled_in, size_t real_env_values_count) { |
| 361 | for (size_t i = index_of_first_env_value_not_compiled_in; i < real_env_values_count; i++) { |
| 362 | freecxx . . $ free(5d22bdacc48458e8).(env_values[i]); |
| 363 | } |
| 364 | freecxx . . $ free(5d22bdacc48458e8).(env_values); |
| 365 | } |
| 366 | |
| 367 | |
| 368 | xccdf_test_result_type_tcxx . . $ xccdf_test_result_type_t# sce_engine_eval_rulecxx . . $ sce_engine_eval_rule(55d5550656449b7).(struct xccdf_policycxx . . $ xccdf_policy# *policy, const char *rule_id, const char *id, const char *href, |
| 369 | struct xccdf_value_binding_iteratorcxx . . $ xccdf_value_binding_iterator# *value_binding_it, |
| 370 | struct xccdf_check_import_iteratorcxx . . $ xccdf_check_import_iterator# *check_import_it, |
| 371 | void *usr) |
| 372 | { |
| 373 | dIcxx . . $ `src/common/debug_priv.h:61:9`!("Executing SCE check '%s'", href); |
| 374 | struct sce_parameterscxx . . $ sce_parameters#* parameters = (struct sce_parameterscxx . . $ sce_parameters#*)usr; |
| 375 | const char* xccdf_directory = parameters->xccdf_directorycxx . . $ sce_parameters#xccdf_directory.; |
| 376 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! use_sce_wrapper = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; // use osca-run-sce-script ? |
| 377 | |
| 378 | char* tmp_href = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%s/%s", xccdf_directory, href); |
| 379 | |
| 380 | if (accesscxx . . $ access(cb7559238bb26814).(tmp_href, F_OKcxx . . $ `<external>/12628407106812493757/unistd.h:284:9`!)) |
| 381 | { |
| 382 | // we only do this check to provide helpful error message |
| 383 | // there is an inherent race condition, the file might |
| 384 | // not exist anymore at the time we execve it! |
| 385 | |
| 386 | // the script hasn't been found, perhaps another sce instance |
| 387 | // with a different XCCDF directory can find it? |
| 388 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_SCEcxx . . $ `src/common/public/oscap_error.h:63:9`!, "SCE couldn't find script file '%s'. " |
| 389 | "Expected location: '%s'.", href, tmp_href); |
| 390 | freecxx . . $ free(5d22bdacc48458e8).(tmp_href); |
| 391 | return XCCDF_RESULT_NOT_CHECKEDcxx . . $ XCCDF_RESULT_NOT_CHECKED.; |
| 392 | } |
| 393 | |
| 394 | if (accesscxx . . $ access(cb7559238bb26814).(tmp_href, F_OKcxx . . $ `<external>/12628407106812493757/unistd.h:284:9`! | X_OKcxx . . $ `<external>/12628407106812493757/unistd.h:283:9`!)) |
| 395 | { |
| 396 | // use the sce wrapper if it's not possible to acquire +x rights |
| 397 | use_sce_wrapper = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 398 | dIcxx . . $ `src/common/debug_priv.h:61:9`!("%s isn't executable, oscap-run-sce-script will be used.", tmp_href); |
| 399 | } |
| 400 | |
| 401 | // all the result codes are shifted by 100, because otherwise syntax errors in scripts |
| 402 | // or even their nonexistence would cause XCCDF_RESULT_PASS to be the result |
| 403 | |
| 404 | char* argvp[3] = { |
| 405 | tmp_href, |
| 406 | tmp_href, // the second tmp_href is added in case we use the wrapper (oscap-run-sce-script) |
| 407 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! // which need the path of the script to eval as first parameter. |
| 408 | }; |
| 409 | |
| 410 | // bound values in KEY=VALUE form, ready to be passed as environment variables |
| 411 | char ** env_values = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(10 * sizeof(char * )); |
| 412 | size_t env_value_count = 10; |
| 413 | const size_t index_of_first_env_value_not_compiled_in = 10; |
| 414 | |
| 415 | env_values[0] = "PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin"; |
| 416 | |
| 417 | env_values[1] = "XCCDF_RESULT_PASS=101"; |
| 418 | env_values[2] = "XCCDF_RESULT_FAIL=102"; |
| 419 | env_values[3] = "XCCDF_RESULT_ERROR=103"; |
| 420 | env_values[4] = "XCCDF_RESULT_UNKNOWN=104"; |
| 421 | env_values[5] = "XCCDF_RESULT_NOT_APPLICABLE=105"; |
| 422 | env_values[6] = "XCCDF_RESULT_NOT_CHECKED=106"; |
| 423 | env_values[7] = "XCCDF_RESULT_NOT_SELECTED=107"; |
| 424 | env_values[8] = "XCCDF_RESULT_INFORMATIONAL=108"; |
| 425 | env_values[9] = "XCCDF_RESULT_FIXED=109"; |
| 426 | |
| 427 | while (xccdf_value_binding_iterator_has_morecxx . . $ xccdf_value_binding_iterator_has_more(300b921b476220ec).(value_binding_it)) |
| 428 | { |
| 429 | struct xccdf_value_bindingcxx . . $ xccdf_value_binding#* binding = xccdf_value_binding_iterator_nextcxx . . $ xccdf_value_binding_iterator_next(c06119a0c6a9a253).(value_binding_it); |
| 430 | |
| 431 | void *new_env_values = realloccxx . . $ realloc(417ab160f6baadc6).(env_values, (env_value_count + 3) * sizeof(char *)); |
| 432 | if (new_env_values == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 433 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Unable to re-allocate memory"); |
| 434 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 435 | return XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 436 | } |
| 437 | env_values = new_env_values; |
| 438 | |
| 439 | char* name = xccdf_value_binding_get_namecxx . . $ xccdf_value_binding_get_name(1ba7d2ab68e2a5ec).(binding); |
| 440 | xccdf_value_type_tcxx . . $ xccdf_value_type_t# type = xccdf_value_binding_get_typecxx . . $ xccdf_value_binding_get_type(d6f6446d0955eb1c).(binding); |
| 441 | char* value = xccdf_value_binding_get_setvaluecxx . . $ xccdf_value_binding_get_setvalue(1ba7d2ab68e2a5ec).(binding); |
| 442 | if (value == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 443 | { |
| 444 | value = xccdf_value_binding_get_valuecxx . . $ xccdf_value_binding_get_value(1ba7d2ab68e2a5ec).(binding); |
| 445 | if (value == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 446 | value = ""; |
| 447 | } |
| 448 | } |
| 449 | xccdf_operator_tcxx . . $ xccdf_operator_t# operator = xccdf_value_binding_get_operatorcxx . . $ xccdf_value_binding_get_operator(74a6762179f6cc73).(binding); |
| 450 | |
| 451 | char* type_str; |
| 452 | switch (type) |
| 453 | { |
| 454 | case XCCDF_TYPE_BOOLEANcxx . . $ XCCDF_TYPE_BOOLEAN.: |
| 455 | type_str = "BOOLEAN"; |
| 456 | break; |
| 457 | case XCCDF_TYPE_NUMBERcxx . . $ XCCDF_TYPE_NUMBER.: |
| 458 | type_str = "NUMBER"; |
| 459 | break; |
| 460 | case XCCDF_TYPE_STRINGcxx . . $ XCCDF_TYPE_STRING.: |
| 461 | type_str = "STRING"; |
| 462 | break; |
| 463 | default: |
| 464 | assertcxx . . $ `/usr/include/assert.h:50:10`!(0); |
| 465 | type_str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 466 | break; |
| 467 | } |
| 468 | |
| 469 | char* env_type_entry = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("XCCDF_TYPE_%s=%s", name, type_str); |
| 470 | char* env_value_entry = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("XCCDF_VALUE_%s=%s", name, value); |
| 471 | |
| 472 | char* operator_str; |
| 473 | switch (operator) |
| 474 | { |
| 475 | case XCCDF_OPERATOR_EQUALScxx . . $ XCCDF_OPERATOR_EQUALS.: |
| 476 | operator_str = "EQUALS"; |
| 477 | break; |
| 478 | case XCCDF_OPERATOR_NOT_EQUALcxx . . $ XCCDF_OPERATOR_NOT_EQUAL.: |
| 479 | operator_str = "NOT_EQUAL"; |
| 480 | break; |
| 481 | case XCCDF_OPERATOR_GREATERcxx . . $ XCCDF_OPERATOR_GREATER.: |
| 482 | operator_str = "GREATER"; |
| 483 | break; |
| 484 | case XCCDF_OPERATOR_GREATER_EQUALcxx . . $ XCCDF_OPERATOR_GREATER_EQUAL.: |
| 485 | operator_str = "GREATER_EQUAL"; |
| 486 | break; |
| 487 | case XCCDF_OPERATOR_LESScxx . . $ XCCDF_OPERATOR_LESS.: |
| 488 | operator_str = "LESS"; |
| 489 | break; |
| 490 | case XCCDF_OPERATOR_LESS_EQUALcxx . . $ XCCDF_OPERATOR_LESS_EQUAL.: |
| 491 | operator_str = "LESS_EQUAL"; |
| 492 | break; |
| 493 | case XCCDF_OPERATOR_PATTERN_MATCHcxx . . $ XCCDF_OPERATOR_PATTERN_MATCH.: |
| 494 | operator_str = "PATTERN_MATCH"; |
| 495 | break; |
| 496 | default: |
| 497 | assertcxx . . $ `/usr/include/assert.h:50:10`!(0); |
| 498 | operator_str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 499 | break; |
| 500 | } |
| 501 | |
| 502 | char* env_operator_entry = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("XCCDF_OPERATOR_%s=%s", name, operator_str); |
| 503 | |
| 504 | env_values[env_value_count] = env_type_entry; |
| 505 | env_value_count++; |
| 506 | env_values[env_value_count] = env_value_entry; |
| 507 | env_value_count++; |
| 508 | env_values[env_value_count] = env_operator_entry; |
| 509 | env_value_count++; |
| 510 | } |
| 511 | |
| 512 | void *new_env_values = realloccxx . . $ realloc(417ab160f6baadc6).(env_values, (env_value_count + 1) * sizeof(char*)); |
| 513 | if (new_env_values == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 514 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Unable to re-allocate memory"); |
| 515 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 516 | return XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 517 | } |
| 518 | env_values = new_env_values; |
| 519 | env_values[env_value_count] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 520 | |
| 521 | // We open a pipe for communication with the forked process |
| 522 | int stdout_pipefd[2]; |
| 523 | int stderr_pipefd[2]; |
| 524 | if (pipecxx . . $ pipe(a5f7824ee4986326).(stdout_pipefd) == -1 || pipecxx . . $ pipe(a5f7824ee4986326).(stderr_pipefd) == -1) |
| 525 | { |
| 526 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Error in pipe"); |
| 527 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 528 | return XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 529 | } |
| 530 | |
| 531 | // FIXME: We definitely want to impose security restrictions in the forked child process in the future. |
| 532 | // This would prevent scripts from writing to files or deleting them. |
| 533 | |
| 534 | int fork_result = forkcxx . . $ fork(b126dc7c1de90089).(); |
| 535 | if (fork_result >= 0) |
| 536 | { |
| 537 | // fork successful |
| 538 | |
| 539 | if (fork_result == 0) |
| 540 | { |
| 541 | // we won't read from the pipes, so close the reading fd |
| 542 | closecxx . . $ close(7864480464b09eea).(stdout_pipefd[0]); |
| 543 | closecxx . . $ close(7864480464b09eea).(stderr_pipefd[0]); |
| 544 | |
| 545 | // forward stdout and stderr to our custom opened pipes |
| 546 | dup2cxx . . $ dup2(9b79fb6aee4c0440).(stdout_pipefd[1], filenocxx . . $ fileno(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!)); |
| 547 | dup2cxx . . $ dup2(9b79fb6aee4c0440).(stderr_pipefd[1], filenocxx . . $ fileno(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!)); |
| 548 | |
| 549 | // we duplicated the file descriptors twice, we can close the original |
| 550 | // ones now, stdout and stderr will be closed properly after the execved |
| 551 | // script/executable finishes |
| 552 | closecxx . . $ close(7864480464b09eea).(stdout_pipefd[1]); |
| 553 | closecxx . . $ close(7864480464b09eea).(stderr_pipefd[1]); |
| 554 | |
| 555 | // before we execute the script, lets make sure we get SIGTERM when |
| 556 | // oscap is killed, crashes or otherwise terminates |
| 557 | #if defined(PR_SET_PDEATHSIGcxx . . $ `<external>/9872755456582759113/prctl.h:9:9`!) |
| 558 | // requires Linux 2.1.57 or later |
| 559 | prctlcxx . . $ prctl(e5daca538bd362ba).(PR_SET_PDEATHSIGcxx . . $ `<external>/9872755456582759113/prctl.h:9:9`!, SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!); |
| 560 | #elif defined(OS_FREEBSD) |
| 561 | int sig = SIGTERM; |
| 562 | procctl(P_PID, getpid(), PROC_PDEATHSIG_CTL, &sig); |
| 563 | #else |
| 564 | // TODO: Please provide alternatives |
| 565 | #endif |
| 566 | |
| 567 | // we are the child process |
| 568 | if(use_sce_wrapper) { |
| 569 | #if defined(OS_FREEBSD) |
| 570 | size_t k; |
| 571 | |
| 572 | // Setup environment beforehand as FreeBSD does not have execvpe() |
| 573 | for (k = 0; k < env_value_count; k++) { |
| 574 | putenv(env_values[k]); |
| 575 | } |
| 576 | |
| 577 | execvp("oscap-run-sce-script", argvp); |
| 578 | #else |
| 579 | execvpecxx . . $ execvpe(181eaca3a689d655).("oscap-run-sce-script", argvp, env_values); |
| 580 | #endif |
| 581 | } else { |
| 582 | execvecxx . . $ execve(181eaca3a689d655).(tmp_href, argvp, env_values); |
| 583 | } |
| 584 | |
| 585 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 586 | |
| 587 | // no need to check the return value of execve, if it returned at all we are in trouble |
| 588 | printfcxx . . $ printf(581fddd72a8db8fc).("Unexpected error when executing script '%s'. Error message follows.\n", href); |
| 589 | perrorcxx . . $ perror(85c52e162fed56f9).("execve"); |
| 590 | |
| 591 | // the parent process considers us a script check, we have to return a value that will mean XCCDF_RESULT_ERROR |
| 592 | exitcxx . . $ exit(3ca292c338df9bb3).(103); |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | // we won't write to the pipes, so close the writing fd |
| 597 | closecxx . . $ close(7864480464b09eea).(stdout_pipefd[1]); |
| 598 | closecxx . . $ close(7864480464b09eea).(stderr_pipefd[1]); |
| 599 | |
| 600 | const int flag_stdout = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(stdout_pipefd[0], F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!, 0); |
| 601 | if (flag_stdout == -1) { |
| 602 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_SCEcxx . . $ `src/common/public/oscap_error.h:63:9`!, "Failed to obtain status of stdout pipe: %s", |
| 603 | strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 604 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 605 | return XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 606 | } |
| 607 | int retval = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(stdout_pipefd[0], F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, flag_stdout | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!); |
| 608 | if (retval == -1) { |
| 609 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_SCEcxx . . $ `src/common/public/oscap_error.h:63:9`!, |
| 610 | "Failed to set nonblocking flag on stdout pipe: %s", |
| 611 | strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 612 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 613 | return XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 614 | } |
| 615 | |
| 616 | const int flag_stderr = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(stderr_pipefd[0], F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!, 0); |
| 617 | if (flag_stderr == -1) { |
| 618 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_SCEcxx . . $ `src/common/public/oscap_error.h:63:9`!, |
| 619 | "Failed to obtain status of stderr pipe: %s", |
| 620 | strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 621 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 622 | return XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 623 | } |
| 624 | retval = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(stderr_pipefd[0], F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, flag_stderr | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!); |
| 625 | if (retval == -1) { |
| 626 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_SCEcxx . . $ `src/common/public/oscap_error.h:63:9`!, |
| 627 | "Failed to set nonblocking flag on stderr pipe: %s", |
| 628 | strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 629 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 630 | return XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 631 | } |
| 632 | |
| 633 | // we have to read from both pipes at the same time to avoid stalling |
| 634 | struct oscap_stringcxx . . $ oscap_string# *stdout_string = oscap_string_newcxx . . $ oscap_string_new(a2a7aea7d1de9315).(); |
| 635 | struct oscap_stringcxx . . $ oscap_string# *stderr_string = oscap_string_newcxx . . $ oscap_string_new(a2a7aea7d1de9315).(); |
| 636 | |
| 637 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! stdout_eof = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 638 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! stderr_eof = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 639 | |
| 640 | while (!stdout_eof || !stderr_eof) { |
| 641 | if (!stdout_eof) |
| 642 | _pipe_try_read_into_stringcxx . . $ _pipe_try_read_into_string(314125bd0f8b5e).(stdout_pipefd[0], stdout_string, &stdout_eof); |
| 643 | |
| 644 | if (!stderr_eof) |
| 645 | _pipe_try_read_into_stringcxx . . $ _pipe_try_read_into_string(314125bd0f8b5e).(stderr_pipefd[0], stderr_string, &stderr_eof); |
| 646 | |
| 647 | // sleep for 10ms to avoid wasting CPU |
| 648 | usleepcxx . . $ usleep(4c679297bf94b9eb).(10 * 1000); |
| 649 | } |
| 650 | |
| 651 | closecxx . . $ close(7864480464b09eea).(stdout_pipefd[0]); |
| 652 | closecxx . . $ close(7864480464b09eea).(stderr_pipefd[0]); |
| 653 | |
| 654 | char *stdout_buffer = oscap_string_bequeathcxx . . $ oscap_string_bequeath(c7f931e995a3a9b8).(stdout_string); |
| 655 | char *stderr_buffer = oscap_string_bequeathcxx . . $ oscap_string_bequeath(c7f931e995a3a9b8).(stderr_string); |
| 656 | |
| 657 | // we are the parent process |
| 658 | int wstatus; |
| 659 | waitpidcxx . . $ waitpid(1df93256b606fe1f).(fork_result, &wstatus, 0); |
| 660 | |
| 661 | // we subtract 100 here to shift the exit code to xccdf_test_result_type_t enum range |
| 662 | int raw_result = WEXITSTATUScxx . . $ `<external>/10696550936717951914/stdlib.h:44:10`!(wstatus) - 100; |
| 663 | if (raw_result <= 0 || raw_result > XCCDF_RESULT_FIXEDcxx . . $ XCCDF_RESULT_FIXED.) |
| 664 | { |
| 665 | // the script returned invalid exit code, we need to safeguard us against that |
| 666 | raw_result = XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 667 | } |
| 668 | |
| 669 | struct sce_sessioncxx . . $ sce_session#* session = sce_parameters_get_sessioncxx . . $ sce_parameters_get_session(a4b1286c3a37b79d).(parameters); |
| 670 | if (session) |
| 671 | { |
| 672 | struct sce_check_resultcxx . . $ sce_check_result#* check_result = sce_check_result_newcxx . . $ sce_check_result_new(322c8399b548b45a).(); |
| 673 | sce_check_result_set_hrefcxx . . $ sce_check_result_set_href(84ed1ba2de1ba4ee).(check_result, tmp_href); |
| 674 | char *base_name = oscap_basenamecxx . . $ oscap_basename(7a9722d75b371431).(tmp_href); |
| 675 | sce_check_result_set_basenamecxx . . $ sce_check_result_set_basename(84ed1ba2de1ba4ee).(check_result, base_name); |
| 676 | freecxx . . $ free(5d22bdacc48458e8).(base_name); |
| 677 | sce_check_result_set_stdoutcxx . . $ sce_check_result_set_stdout(84ed1ba2de1ba4ee).(check_result, stdout_buffer); |
| 678 | sce_check_result_set_stderrcxx . . $ sce_check_result_set_stderr(84ed1ba2de1ba4ee).(check_result, stderr_buffer); |
| 679 | sce_check_result_set_exit_codecxx . . $ sce_check_result_set_exit_code(f11ef7399be4a329).(check_result, WEXITSTATUScxx . . $ `<external>/10696550936717951914/stdlib.h:44:10`!(wstatus)); |
| 680 | sce_check_result_set_xccdf_resultcxx . . $ sce_check_result_set_xccdf_result(c0fb5b9a2a42dcd).(check_result, (xccdf_test_result_type_tcxx . . $ xccdf_test_result_type_t#)raw_result); |
| 681 | |
| 682 | for (size_t i = 0; i < env_value_count; ++i) |
| 683 | { |
| 684 | sce_check_result_add_environment_variablecxx . . $ sce_check_result_add_environment_variable(84ed1ba2de1ba4ee).(check_result, env_values[i]); |
| 685 | } |
| 686 | |
| 687 | sce_session_add_check_resultcxx . . $ sce_session_add_check_result(c66b63514b8ed67a).(session, check_result); |
| 688 | } |
| 689 | |
| 690 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 691 | |
| 692 | // lets interpret the check imports passed to us |
| 693 | xccdf_check_import_iterator_resetcxx . . $ xccdf_check_import_iterator_reset(2ae6b52ef2d5345b).(check_import_it); |
| 694 | while (xccdf_check_import_iterator_has_morecxx . . $ xccdf_check_import_iterator_has_more(30856d67965e03e4).(check_import_it)) |
| 695 | { |
| 696 | struct xccdf_check_importcxx . . $ xccdf_check_import# * check_import = xccdf_check_import_iterator_nextcxx . . $ xccdf_check_import_iterator_next(cde0f316e6bf495c).(check_import_it); |
| 697 | const char *name = xccdf_check_import_get_namecxx . . $ xccdf_check_import_get_name(7e35a7e9d6990138).(check_import); |
| 698 | |
| 699 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, "stdout") == 0) |
| 700 | { |
| 701 | xccdf_check_import_set_contentcxx . . $ xccdf_check_import_set_content(c0da83e738a5bfb6).(check_import, stdout_buffer); |
| 702 | } |
| 703 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, "stderr") == 0) |
| 704 | { |
| 705 | xccdf_check_import_set_contentcxx . . $ xccdf_check_import_set_content(c0da83e738a5bfb6).(check_import, stderr_buffer); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | freecxx . . $ free(5d22bdacc48458e8).(tmp_href); |
| 710 | freecxx . . $ free(5d22bdacc48458e8).(stdout_buffer); |
| 711 | freecxx . . $ free(5d22bdacc48458e8).(stderr_buffer); |
| 712 | |
| 713 | return (xccdf_test_result_type_tcxx . . $ xccdf_test_result_type_t#)raw_result; |
| 714 | } |
| 715 | } |
| 716 | else |
| 717 | { |
| 718 | free_env_valuescxx . . $ free_env_values(170bbbf817437443).(env_values, index_of_first_env_value_not_compiled_in, env_value_count); |
| 719 | |
| 720 | closecxx . . $ close(7864480464b09eea).(stdout_pipefd[0]); |
| 721 | closecxx . . $ close(7864480464b09eea).(stdout_pipefd[1]); |
| 722 | closecxx . . $ close(7864480464b09eea).(stderr_pipefd[0]); |
| 723 | closecxx . . $ close(7864480464b09eea).(stderr_pipefd[1]); |
| 724 | return XCCDF_RESULT_ERRORcxx . . $ XCCDF_RESULT_ERROR.; |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! xccdf_policy_model_register_engine_scecxx . . $ xccdf_policy_model_register_engine_sce(f8237cfb45f8a428).(struct xccdf_policy_modelcxx . . $ xccdf_policy_model# * model, struct sce_parameterscxx . . $ sce_parameters# *parameters) |
| 729 | { |
| 730 | return xccdf_policy_model_register_engine_and_query_callbackcxx . . $ xccdf_policy_model_register_engine_and_query_callback(7fef2e0a0392b6d3).(model, |
| 731 | "http://open-scap.org/page/SCE", sce_engine_eval_rulecxx . . $ sce_engine_eval_rule(55d5550656449b7)., (void*)parameters, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 732 | } |