| 1 | /* |
| 2 | * Copyright 2010 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * Lukas Kuklinek <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`! |
| 24 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 25 | #endif |
| 26 | |
| 27 | #include "oscap-tool.h"cxx . . $ `<file>/utils/oscap-tool.h`/ |
| 28 | #include <assert.h> |
| 29 | #ifdef HAVE_GETOPT_Hcxx . . $ `build/config.h:79:9`! |
| 30 | #include <getopt.h> |
| 31 | #endif |
| 32 | #include <string.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/stat.h> |
| 35 | #ifdef OS_WINDOWS |
| 36 | #include <io.h> |
| 37 | #else |
| 38 | #include <unistd.h> |
| 39 | #endif |
| 40 | #include <stdarg.h> |
| 41 | #include <errno.h> |
| 42 | #include <limits.h> |
| 43 | #include <oscap_debug.h>cxx . . $ `<file>/src/common/public/oscap_debug.h`/ |
| 44 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 45 | |
| 46 | #ifndef PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`! |
| 47 | # define PATH_MAX 1024 |
| 48 | #else |
| 49 | # if PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`! < 1 || PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`! > 4096 |
| 50 | # undef PATH_MAX |
| 51 | # define PATH_MAX 2048 |
| 52 | # endif |
| 53 | #endif /* PATH_MAX */ |
| 54 | |
| 55 | static void oscap_action_initcxx . . $ oscap_action_init(3f4a7b4be2b5da8e).(struct oscap_actioncxx . . $ oscap_action# *action) |
| 56 | { |
| 57 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(action != NULL); |
| 58 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(action, 0, sizeof(*action)); |
| 59 | action->validatecxx . . $ oscap_action#validate. = 1; |
| 60 | action->schematroncxx . . $ oscap_action#schematron. = 1; |
| 61 | action->validate_signaturecxx . . $ oscap_action#validate_signature. = 1; |
| 62 | action->rulescxx . . $ oscap_action#rules. = oscap_stringlist_newcxx . . $ oscap_stringlist_new(22a991cfbca9a1c).(); |
| 63 | action->skip_rulescxx . . $ oscap_action#skip_rules. = oscap_stringlist_newcxx . . $ oscap_stringlist_new(22a991cfbca9a1c).(); |
| 64 | } |
| 65 | |
| 66 | static void oscap_action_releasecxx . . $ oscap_action_release(3f4a7b4be2b5da8e).(struct oscap_actioncxx . . $ oscap_action# *action) |
| 67 | { |
| 68 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(action != NULL); |
| 69 | freecxx . . $ free(5d22bdacc48458e8).(action->f_ovalscxx . . $ oscap_action#f_ovals.); |
| 70 | oscap_stringlist_freecxx . . $ oscap_stringlist_free(7df8e35292df4dfb).(action->rulescxx . . $ oscap_action#rules.); |
| 71 | oscap_stringlist_freecxx . . $ oscap_stringlist_free(7df8e35292df4dfb).(action->skip_rulescxx . . $ oscap_action#skip_rules.); |
| 72 | } |
| 73 | |
| 74 | static size_t paramlist_sizecxx . . $ paramlist_size(53fcf07ba53ffee5).(const char **p) { size_t s = 0; if (!p) return s; while (p[s]) s += 2; return s; } |
| 75 | |
| 76 | static size_t paramlist_cpycxx . . $ paramlist_cpy(95190fbbb843de08).(const char **to, const char **p) { |
| 77 | size_t s = 0; |
| 78 | if (!to || !p) |
| 79 | return s; |
| 80 | for (;p && p[s]; s += 2) to[s] = p[s], to[s+1] = p[s+1]; |
| 81 | to[s] = p[s]; |
| 82 | return s; |
| 83 | } |
| 84 | |
| 85 | int app_xsltcxx . . $ app_xslt(94a5cfe74efaac1c).(const char *infile, const char *xsltfile, const char *outfile, const char **params) |
| 86 | { |
| 87 | char pwd[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 88 | |
| 89 | if (getcwdcxx . . $ getcwd(dff97f9eb74e1544).(pwd, sizeof(pwd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 90 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 91 | return OSCAP_ERRORcxx . . $ OSCAP_ERROR.; |
| 92 | } |
| 93 | |
| 94 | /* add params oscap-version & pwd */ |
| 95 | const char *stdparams[] = { "oscap-version", oscap_get_versioncxx . . $ oscap_get_version(33a1f659e94feb42).(), "pwd", pwd, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! }; |
| 96 | const size_t par_size = paramlist_sizecxx . . $ paramlist_size(53fcf07ba53ffee5).(params) + paramlist_sizecxx . . $ paramlist_size(53fcf07ba53ffee5).(stdparams) + 1; |
| 97 | const char **par = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(par_size * sizeof(const char *)); |
| 98 | size_t s = paramlist_cpycxx . . $ paramlist_cpy(95190fbbb843de08).(par , params); |
| 99 | paramlist_cpycxx . . $ paramlist_cpy(95190fbbb843de08).(par + s, stdparams); |
| 100 | |
| 101 | if (oscap_apply_xsltcxx . . $ oscap_apply_xslt(94a5cfe74efaac1c).(infile, xsltfile, outfile, par)==-1) { |
| 102 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: %s\n", OSCAP_ERR_MSGcxx . . $ `utils/oscap-tool.h:50:9`!, oscap_err_desccxx . . $ oscap_err_desc(33a1f659e94feb42).()); |
| 103 | freecxx . . $ free(5d22bdacc48458e8).(par); |
| 104 | return OSCAP_ERRORcxx . . $ OSCAP_ERROR.; |
| 105 | } |
| 106 | |
| 107 | freecxx . . $ free(5d22bdacc48458e8).(par); |
| 108 | return OSCAP_OKcxx . . $ OSCAP_OK.; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | static void check_modulecxx . . $ check_module(e70de9e31b5c8d76).(struct oscap_modulecxx . . $ oscap_module# *module) |
| 113 | { |
| 114 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module != NULL); |
| 115 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module->name != NULL); |
| 116 | if (module != &OSCAP_ROOT_MODULEcxx . . $ OSCAP_ROOT_MODULE.) |
| 117 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module->parent != NULL); |
| 118 | if (module->submodulescxx . . $ oscap_module#submodules.) |
| 119 | for (struct oscap_modulecxx . . $ oscap_module#** sub = module->submodulescxx . . $ oscap_module#submodules.; *sub != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; ++(sub)) |
| 120 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!((*sub)->parent == module); |
| 121 | } |
| 122 | |
| 123 | static void oscap_module_backtracecxx . . $ oscap_module_backtrace(f414ea799e823914).(struct oscap_modulecxx . . $ oscap_module# *module, FILEcxx . . $ FILE# *out, const char *delim) |
| 124 | { |
| 125 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module != NULL); |
| 126 | if (module->parentcxx . . $ oscap_module#parent.) { |
| 127 | oscap_module_backtracecxx . . $ oscap_module_backtrace(f414ea799e823914).(module->parentcxx . . $ oscap_module#parent., out, delim); |
| 128 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "%s", delim); |
| 129 | } |
| 130 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "%s", module->namecxx . . $ oscap_module#name.); |
| 131 | } |
| 132 | |
| 133 | static void oscap_module_print_usagecxx . . $ oscap_module_print_usage(b46b814ab5ce09e3).(struct oscap_modulecxx . . $ oscap_module# *module, FILEcxx . . $ FILE# *out, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! full) |
| 134 | { |
| 135 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module != NULL); |
| 136 | if (module->parentcxx . . $ oscap_module#parent. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 137 | oscap_module_print_usagecxx . . $ oscap_module_print_usage(b46b814ab5ce09e3).(module->parentcxx . . $ oscap_module#parent., out, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); |
| 138 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, " "); |
| 139 | } |
| 140 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "%s", module->namecxx . . $ oscap_module#name.); |
| 141 | if (module->usagecxx . . $ oscap_module#usage.) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, " %s", module->usagecxx . . $ oscap_module#usage.); |
| 142 | if (full) { |
| 143 | if (module->usage_extracxx . . $ oscap_module#usage_extra.) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, " %s", module->usage_extracxx . . $ oscap_module#usage_extra.); |
| 144 | else if (module->submodulescxx . . $ oscap_module#submodules.) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, " command"); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | static inline void oscap_module_print_summarycxx . . $ oscap_module_print_summary(bc577543115c4105).(struct oscap_modulecxx . . $ oscap_module# *module, FILEcxx . . $ FILE# *out) |
| 149 | { |
| 150 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module != NULL); |
| 151 | if (!module->hiddencxx . . $ oscap_module#hidden.) { |
| 152 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, " %s", module->namecxx . . $ oscap_module#name.); |
| 153 | if (module->summarycxx . . $ oscap_module#summary.) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, " - %s", module->summarycxx . . $ oscap_module#summary.); |
| 154 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "\n"); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | static int oscap_print_submodulescxx . . $ oscap_print_submodules(1cbfe158f145560c).(struct oscap_modulecxx . . $ oscap_module# *module, FILEcxx . . $ FILE# *out, const char *delim, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! all) |
| 159 | { |
| 160 | if (module->submodulescxx . . $ oscap_module#submodules.) { |
| 161 | for (struct oscap_modulecxx . . $ oscap_module#** sub = module->submodulescxx . . $ oscap_module#submodules.; *sub != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; ++(sub)) |
| 162 | if (all || !(*sub)->hiddencxx . . $ oscap_module#hidden.) |
| 163 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "%s%s", (*sub)->namecxx . . $ oscap_module#name., delim); |
| 164 | return OSCAP_OKcxx . . $ OSCAP_OK.; |
| 165 | } |
| 166 | return OSCAP_BADMODULEcxx . . $ OSCAP_BADMODULE.; |
| 167 | } |
| 168 | |
| 169 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! oscap_module_usagecxx . . $ oscap_module_usage(8d148a6468c518c9).(struct oscap_modulecxx . . $ oscap_module# *module, FILEcxx . . $ FILE# *out, const char *err, ...) |
| 170 | { |
| 171 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module != NULL); |
| 172 | |
| 173 | if (err) { |
| 174 | va_listcxx . . $ va_list# ap; |
| 175 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "ERROR: "); |
| 176 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(ap, err); |
| 177 | vfprintfcxx . . $ vfprintf(bded311e54d67f9c).(out, err, ap); |
| 178 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap); |
| 179 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "\n"); |
| 180 | } |
| 181 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "Usage: "); |
| 182 | oscap_module_print_usagecxx . . $ oscap_module_print_usage(b46b814ab5ce09e3).(module, out, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 183 | if (module->submodulescxx . . $ oscap_module#submodules.) { fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "\nCommands: "); oscap_print_submodulescxx . . $ oscap_print_submodules(1cbfe158f145560c).(module, out, " ", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); } |
| 184 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "\nHelp: "); |
| 185 | oscap_module_backtracecxx . . $ oscap_module_backtrace(f414ea799e823914).(module, out, " "); |
| 186 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, " -h\n"); |
| 187 | return (out != stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!); |
| 188 | } |
| 189 | |
| 190 | static void oscap_module_print_helpcxx . . $ oscap_module_print_help(bc577543115c4105).(struct oscap_modulecxx . . $ oscap_module# *module, FILEcxx . . $ FILE# *out) |
| 191 | { |
| 192 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module != NULL); |
| 193 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(out != NULL); |
| 194 | |
| 195 | oscap_module_backtracecxx . . $ oscap_module_backtrace(f414ea799e823914).(module, out, " -> "); |
| 196 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "\n\n"); |
| 197 | |
| 198 | if (module->summarycxx . . $ oscap_module#summary.) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "%s\n\n", module->summarycxx . . $ oscap_module#summary.); |
| 199 | |
| 200 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "Usage: "); |
| 201 | oscap_module_print_usagecxx . . $ oscap_module_print_usage(b46b814ab5ce09e3).(module, out, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 202 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "\n\n"); |
| 203 | |
| 204 | if (module->helpcxx . . $ oscap_module#help.) |
| 205 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "%s\n\n", module->helpcxx . . $ oscap_module#help.); |
| 206 | |
| 207 | if (module->submodulescxx . . $ oscap_module#submodules.) { |
| 208 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "Commands:\n"); |
| 209 | for (struct oscap_modulecxx . . $ oscap_module#** sub = module->submodulescxx . . $ oscap_module#submodules.; *sub != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; ++(sub)) |
| 210 | oscap_module_print_summarycxx . . $ oscap_module_print_summary(bc577543115c4105).(*sub, out); |
| 211 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "\n"); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | static void oscap_module_treecxx . . $ oscap_module_tree(8b5b296c0408e453).(struct oscap_modulecxx . . $ oscap_module# *module, FILEcxx . . $ FILE#* out, int indent) |
| 216 | { |
| 217 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module); |
| 218 | if (module->hiddencxx . . $ oscap_module#hidden.) return; |
| 219 | for (int i = 0; i < indent; ++i) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, " "); |
| 220 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(out, "%s - %s\n", module->namecxx . . $ oscap_module#name., module->summarycxx . . $ oscap_module#summary.); |
| 221 | if (module->submodulescxx . . $ oscap_module#submodules.) { |
| 222 | for (struct oscap_modulecxx . . $ oscap_module#** sub = module->submodulescxx . . $ oscap_module#submodules.; *sub != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; ++(sub)) |
| 223 | oscap_module_treecxx . . $ oscap_module_tree(8b5b296c0408e453).(*sub, out, indent + 1); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | static struct oscap_modulecxx . . $ oscap_module# *oscap_module_findcxx . . $ oscap_module_find(3db515ec50beb6f0).(struct oscap_modulecxx . . $ oscap_module# **list, const char *name) |
| 228 | { |
| 229 | if (name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 230 | if (list == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 231 | while (*list != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && strcmpcxx . . $ strcmp(5ae29d726ae57f88).((*list)->namecxx . . $ oscap_module#name., name) != 0) ++list; |
| 232 | return *list; |
| 233 | } |
| 234 | |
| 235 | enum oscap_common_optscxx . . $ oscap_common_opts# { |
| 236 | OPT_NONEcxx . . $ OPT_NONE., |
| 237 | OPT_LISTMODScxx . . $ OPT_LISTMODS., |
| 238 | OPT_LISTALLMODScxx . . $ OPT_LISTALLMODS., |
| 239 | OPT_MODTREEcxx . . $ OPT_MODTREE., |
| 240 | OPT_HELPcxx . . $ OPT_HELP. = 'h', |
| 241 | OPT_VERBOSEcxx . . $ OPT_VERBOSE., |
| 242 | OPT_VERBOSE_LOG_FILEcxx . . $ OPT_VERBOSE_LOG_FILE. |
| 243 | }; |
| 244 | |
| 245 | static enum oscap_common_optscxx . . $ oscap_common_opts# oscap_parse_common_optscxx . . $ oscap_parse_common_opts(3eb1a92499a9ba24).(int argc, char **argv, struct oscap_actioncxx . . $ oscap_action# *action) |
| 246 | { |
| 247 | static const struct optioncxx . . $ option# opts[] = { |
| 248 | { "help", 0, 0, OPT_HELPcxx . . $ OPT_HELP. }, |
| 249 | { "list-submodules", 0, 0, OPT_LISTMODScxx . . $ OPT_LISTMODS. }, |
| 250 | { "list-all-submodules", 0, 0, OPT_LISTALLMODScxx . . $ OPT_LISTALLMODS. }, |
| 251 | { "module-tree", 0, 0, OPT_MODTREEcxx . . $ OPT_MODTREE. }, |
| 252 | { 0, 0, 0, 0 } |
| 253 | }; |
| 254 | |
| 255 | int r; |
| 256 | opterrcxx . . $ opterr. = 0; |
| 257 | while ((r = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "+h", opts, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) != -1) { |
| 258 | switch (r) { |
| 259 | case 0: |
| 260 | break; |
| 261 | case '?': |
| 262 | optindcxx . . $ optind.--; |
| 263 | opterrcxx . . $ opterr.--; |
| 264 | return OPT_NONEcxx . . $ OPT_NONE.; |
| 265 | default: |
| 266 | return r; |
| 267 | } |
| 268 | } |
| 269 | return OPT_NONEcxx . . $ OPT_NONE.; |
| 270 | } |
| 271 | |
| 272 | int oscap_module_callcxx . . $ oscap_module_call(862350c5cd0b6b18).(struct oscap_actioncxx . . $ oscap_action# *action) |
| 273 | { |
| 274 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(action != NULL); |
| 275 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(action->module != NULL); |
| 276 | |
| 277 | if (action->modulecxx . . $ oscap_action#module.->funccxx . . $ oscap_module#func.) { |
| 278 | return action->modulecxx . . $ oscap_action#module.->funccxx . . $ oscap_module#func.(action); |
| 279 | } |
| 280 | return OSCAP_UNIMPL_MODcxx . . $ OSCAP_UNIMPL_MOD.; |
| 281 | } |
| 282 | |
| 283 | static void getopt_parse_envcxx . . $ getopt_parse_env(ca82907883981316).(struct oscap_modulecxx . . $ oscap_module# *module, int *argc, char ***argv) |
| 284 | { |
| 285 | int ofs, nargc, eargc; |
| 286 | char *opt, *opts, *state, **nargv, **eargv; |
| 287 | const char *delim = ","; |
| 288 | |
| 289 | if (!module->parentcxx . . $ oscap_module#parent. |
| 290 | || strcmpcxx . . $ strcmp(5ae29d726ae57f88).(module->parentcxx . . $ oscap_module#parent.->namecxx . . $ oscap_module#name., "oval")) |
| 291 | return; |
| 292 | |
| 293 | opts = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_OVAL_COMMAND_OPTIONS"); |
| 294 | if (opts == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 295 | return; |
| 296 | |
| 297 | /* parse the args supplied from the env var */ |
| 298 | eargv = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 299 | eargc = 0; |
| 300 | opts = strdupcxx . . $ strdup(a8b8e32347182212).(opts); |
| 301 | opt = oscap_strtok_rcxx . . $ oscap_strtok_r(a42394c85d6397dd).(opts, delim, &state); |
| 302 | while (opt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 303 | eargc++; |
| 304 | void *new_eargv = realloccxx . . $ realloc(417ab160f6baadc6).(eargv, eargc * sizeof(char *)); |
| 305 | if (new_eargv == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 306 | goto exit; |
| 307 | eargv = new_eargv; |
| 308 | eargv[eargc - 1] = strdupcxx . . $ strdup(a8b8e32347182212).(opt); |
| 309 | opt = oscap_strtok_rcxx . . $ oscap_strtok_r(a42394c85d6397dd).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, delim, &state); |
| 310 | } |
| 311 | |
| 312 | nargc = *argc + eargc; |
| 313 | nargv = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nargc + 1) * sizeof(char *)); |
| 314 | /* copy main args up to the command name */ |
| 315 | for (ofs = 0; strcmpcxx . . $ strcmp(5ae29d726ae57f88).((*argv)[ofs], OSCAP_OVAL_MODULEcxx . . $ OSCAP_OVAL_MODULE..namecxx . . $ oscap_module#name.); ofs++); |
| 316 | ofs += 2; |
| 317 | memcpycxx . . $ memcpy(cc817cb175f282d).(nargv, *argv, ofs * sizeof(char *)); |
| 318 | /* copy env args */ |
| 319 | memcpycxx . . $ memcpy(cc817cb175f282d).(nargv + ofs, eargv, eargc * sizeof(char *)); |
| 320 | /* copy rest of the main args */ |
| 321 | memcpycxx . . $ memcpy(cc817cb175f282d).(nargv + ofs + eargc, *argv + ofs, (*argc - ofs) * sizeof(char *)); |
| 322 | nargv[nargc] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 323 | |
| 324 | *argc = nargc; |
| 325 | *argv = nargv; |
| 326 | exit: |
| 327 | freecxx . . $ free(5d22bdacc48458e8).(opts); |
| 328 | freecxx . . $ free(5d22bdacc48458e8).(eargv); |
| 329 | } |
| 330 | |
| 331 | int oscap_module_processcxx . . $ oscap_module_process(844605f188a3c36c).(struct oscap_modulecxx . . $ oscap_module# *module, int argc, char **argv) |
| 332 | { |
| 333 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(module != NULL); |
| 334 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(argv != NULL); |
| 335 | |
| 336 | int ret = OSCAP_OKcxx . . $ OSCAP_OK.; |
| 337 | struct oscap_actioncxx . . $ oscap_action# action; |
| 338 | oscap_action_initcxx . . $ oscap_action_init(3f4a7b4be2b5da8e).(&action); |
| 339 | optindcxx . . $ optind. = 0; |
| 340 | |
| 341 | while (module) { |
| 342 | check_modulecxx . . $ check_module(e70de9e31b5c8d76).(module); |
| 343 | |
| 344 | ++optindcxx . . $ optind.; // skip current module key index |
| 345 | action.modulecxx . . $ oscap_action#module. = module; // update current module |
| 346 | |
| 347 | getopt_parse_envcxx . . $ getopt_parse_env(ca82907883981316).(module, &argc, &argv); |
| 348 | |
| 349 | switch (oscap_parse_common_optscxx . . $ oscap_parse_common_opts(3eb1a92499a9ba24).(argc, argv, &action)) { |
| 350 | case OPT_HELPcxx . . $ OPT_HELP.: oscap_module_print_helpcxx . . $ oscap_module_print_help(bc577543115c4105).(module, stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); goto cleanup; |
| 351 | case OPT_LISTMODScxx . . $ OPT_LISTMODS.: oscap_print_submodulescxx . . $ oscap_print_submodules(1cbfe158f145560c).(module, stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\n", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); goto cleanup; |
| 352 | case OPT_LISTALLMODScxx . . $ OPT_LISTALLMODS.: oscap_print_submodulescxx . . $ oscap_print_submodules(1cbfe158f145560c).(module, stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\n", truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); goto cleanup; |
| 353 | case OPT_MODTREEcxx . . $ OPT_MODTREE.: oscap_module_treecxx . . $ oscap_module_tree(8b5b296c0408e453).(module, stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, 0); goto cleanup; |
| 354 | default: break; |
| 355 | } |
| 356 | |
| 357 | if (module->opt_parsercxx . . $ oscap_module#opt_parser.) { |
| 358 | if (!module->opt_parsercxx . . $ oscap_module#opt_parser.(argc, argv, &action)) { |
| 359 | ret = OSCAP_BADARGScxx . . $ OSCAP_BADARGS.; |
| 360 | goto cleanup; |
| 361 | } |
| 362 | module = action.modulecxx . . $ oscap_action#module.; // module might have changed |
| 363 | } |
| 364 | |
| 365 | if (module->funccxx . . $ oscap_module#func.) { |
| 366 | if (!check_verbose_optionscxx . . $ check_verbose_options(47ff121b0a12a6e).(&action)) { |
| 367 | goto cleanup; |
| 368 | } |
| 369 | if (!oscap_set_verbosecxx . . $ oscap_set_verbose(b7a7aa4a824b7595).(action.verbosity_levelcxx . . $ oscap_action#verbosity_level., action.f_verbose_logcxx . . $ oscap_action#f_verbose_log.)) { |
| 370 | goto cleanup; |
| 371 | } |
| 372 | oscap_print_env_varscxx . . $ oscap_print_env_vars(49f6e7a06ebc5aa8).(); |
| 373 | ret = oscap_module_callcxx . . $ oscap_module_call(862350c5cd0b6b18).(&action); |
| 374 | goto cleanup; |
| 375 | } |
| 376 | else if (module->submodulescxx . . $ oscap_module#submodules.) { |
| 377 | struct oscap_modulecxx . . $ oscap_module# *old_mod = module; |
| 378 | module = oscap_module_findcxx . . $ oscap_module_find(3db515ec50beb6f0).(module->submodulescxx . . $ oscap_module#submodules., argv[optindcxx . . $ optind.]); |
| 379 | if (module == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 380 | if (argv[optindcxx . . $ optind.] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 381 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "No such module: %s\n", argv[optindcxx . . $ optind.]); |
| 382 | else oscap_module_usagecxx . . $ oscap_module_usage(8d148a6468c518c9).(old_mod, stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 383 | ret = OSCAP_BADMODULEcxx . . $ OSCAP_BADMODULE.; |
| 384 | } |
| 385 | } |
| 386 | else { |
| 387 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Module %s does not do anything\n", module->namecxx . . $ oscap_module#name.); |
| 388 | ret = OSCAP_UNIMPL_MODcxx . . $ OSCAP_UNIMPL_MOD.; |
| 389 | goto cleanup; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | cleanup: |
| 394 | oscap_action_releasecxx . . $ oscap_action_release(3f4a7b4be2b5da8e).(&action); |
| 395 | return ret; |
| 396 | } |
| 397 | |
| 398 | void oscap_print_errorcxx . . $ oscap_print_error(49f6e7a06ebc5aa8).(void) |
| 399 | { |
| 400 | if (oscap_errcxx . . $ oscap_err(c9857a73d68e59ba).()) { |
| 401 | char *err = oscap_err_get_full_errorcxx . . $ oscap_err_get_full_error(41208ce6ca65dd58).(); |
| 402 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s %s\n", OSCAP_ERR_MSGcxx . . $ `utils/oscap-tool.h:50:9`!, err); |
| 403 | freecxx . . $ free(5d22bdacc48458e8).(err); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! check_verbose_optionscxx . . $ check_verbose_options(47ff121b0a12a6e).(struct oscap_actioncxx . . $ oscap_action# *action) |
| 408 | { |
| 409 | if (action->verbosity_levelcxx . . $ oscap_action#verbosity_level. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && action->f_verbose_logcxx . . $ oscap_action#f_verbose_log. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 410 | oscap_module_usagecxx . . $ oscap_module_usage(8d148a6468c518c9).(action->modulecxx . . $ oscap_action#module., stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, |
| 411 | "Verbosity level is not specified! Please provide --verbose VERBOSITY_LEVEL option together with --verbose-log-file."); |
| 412 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 413 | } |
| 414 | if (action->verbosity_levelcxx . . $ oscap_action#verbosity_level. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && oscap_verbosity_level_from_cstrcxx . . $ oscap_verbosity_level_from_cstr(d17a359e3ebc1c52).(action->verbosity_levelcxx . . $ oscap_action#verbosity_level.) == -1) { |
| 415 | oscap_module_usagecxx . . $ oscap_module_usage(8d148a6468c518c9).(action->modulecxx . . $ oscap_action#module., stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, |
| 416 | "Invalid verbosity level! Verbosity level must be one of: DEVEL, INFO, WARNING, ERROR."); |
| 417 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 418 | } |
| 419 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 420 | } |
| 421 | |
| 422 | void download_reporting_callbackcxx . . $ download_reporting_callback(3ca54e6407cd3d15).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! warning, const char *format, ...) |
| 423 | { |
| 424 | FILEcxx . . $ FILE# *dest = stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!; |
| 425 | va_listcxx . . $ va_list# argptr; |
| 426 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(argptr, format); |
| 427 | vfprintfcxx . . $ vfprintf(bded311e54d67f9c).(dest, format, argptr); |
| 428 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(argptr); |
| 429 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(dest); |
| 430 | } |