Debian Codegraph @

utils/oscap.c

raw symbols SCIP
1 /*
2 * Copyright 2010--2017 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 * Maros Barabas <[email protected]>
21 * Peter Vrabec <[email protected]>
22 */
23
24 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
25 #include <config.h>cxx . . $ `<file>/build/config.h`/
26 #endif
27
28 /* Standard header files */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #ifdef HAVE_GETOPT_Hcxx . . $ `build/config.h:79:9`!
33 #include <getopt.h>
34 #endif
35 #include <errno.h>
36 #include <limits.h>
37
38 #include <oscap.h>cxx . . $ `<file>/src/common/public/oscap.h`/
39 #include <oscap_error.h>cxx . . $ `<file>/src/common/public/oscap_error.h`/
40 #include "oscap-tool.h"cxx . . $ `<file>/utils/oscap-tool.h`/
41 #include "check_engine_plugin.h"cxx . . $ `<file>/src/XCCDF_POLICY/public/check_engine_plugin.h`/
42 #include "oscap_source.h"cxx . . $ `<file>/src/source/public/oscap_source.h`/
43 #if defined(OVAL_PROBES_ENABLEDcxx . . $ `build/config.h:67:9`!)
44 # include "probe-table.h"cxx . . $ `<file>/src/OVAL/probes/public/probe-table.h`/
45 #endif
46
47 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! getopt_rootcxx . . $ getopt_root(93e8ba72609212ff).(int argc, char **argv, struct oscap_actioncxx . . $ oscap_action# *action);
48 static int print_versionscxx . . $ print_versions(d99c68634f61e371).(const struct oscap_actioncxx . . $ oscap_action#*);
49 extern struct oscap_modulecxx . . $ oscap_module# OSCAP_VERSION_MODULEcxx . . $ OSCAP_VERSION_MODULE.;
50
51 struct oscap_modulecxx . . $ oscap_module#* OSCAP_ROOT_SUBMODULEScxx . . $ OSCAP_ROOT_SUBMODULES.[] = {
52 &OSCAP_DS_MODULEcxx . . $ OSCAP_DS_MODULE.,
53 &OSCAP_OVAL_MODULEcxx . . $ OSCAP_OVAL_MODULE.,
54 &OSCAP_XCCDF_MODULEcxx . . $ OSCAP_XCCDF_MODULE.,
55 &OSCAP_CPE_MODULEcxx . . $ OSCAP_CPE_MODULE.,
56 &OSCAP_VERSION_MODULEcxx . . $ OSCAP_VERSION_MODULE.,
57 &OSCAP_INFO_MODULEcxx . . $ OSCAP_INFO_MODULE.,
58 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!
59 };
60
61 struct oscap_modulecxx . . $ oscap_module# OSCAP_ROOT_MODULEcxx . . $ OSCAP_ROOT_MODULE. = {
62 .name = "oscap",
63 .usage = "[options]",
64 .usage_extra = "module operation [operation-options-and-arguments]",
65 .summary = "OpenSCAP command-line tool",
66 .help =
67 "oscap options:\n"
68 " -h --help - show this help\n"
69 " -q --quiet - quiet mode\n"
70 " -V --version - print info about supported SCAP versions",
71 .opt_parser = getopt_rootcxx . . $ getopt_root(93e8ba72609212ff).,
72 .submodules = OSCAP_ROOT_SUBMODULEScxx . . $ OSCAP_ROOT_SUBMODULES.
73 };
74
75 struct oscap_modulecxx . . $ oscap_module# OSCAP_VERSION_MODULEcxx . . $ OSCAP_VERSION_MODULE. = {
76 .name = "version",
77 .hidden = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!,
78 .parent = &OSCAP_ROOT_MODULEcxx . . $ OSCAP_ROOT_MODULE.,
79 .func = print_versionscxx . . $ print_versions(d99c68634f61e371).
80 };
81
82 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
83 {
84 oscap_initcxx . . $ oscap_init(49f6e7a06ebc5aa8).();
85 int ret = oscap_module_processcxx . . $ oscap_module_process(844605f188a3c36c).(&OSCAP_ROOT_MODULEcxx . . $ OSCAP_ROOT_MODULE., argc, argv);
86 oscap_cleanupcxx . . $ oscap_cleanup(49f6e7a06ebc5aa8).();
87 return ret;
88 }
89
90 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! getopt_rootcxx . . $ getopt_root(93e8ba72609212ff).(int argc, char **argv, struct oscap_actioncxx . . $ oscap_action# *action)
91 {
92 while (1) {
93 static struct optioncxx . . $ option# long_options[] = {
94 {"quiet", 0, 0, 'q'},
95 {"version", 0, 0, 'V'},
96 {0, 0, 0, 0}
97 };
98
99 int c = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "+qV", long_options, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
100 if (c == -1) break;
101
102 switch (c) {
103 case 'q':
104 printfcxx . . $ printf(581fddd72a8db8fc).("Warning: '-q' is obsoleted option, please use '#oscap ... >/dev/null 2>&1' instead\n");
105 break;
106 case 'V': action->modulecxx . . $ oscap_action#module. = &OSCAP_VERSION_MODULEcxx . . $ OSCAP_VERSION_MODULE.; break;
107 case '?': return oscap_module_usagecxx . . $ oscap_module_usage(8d148a6468c518c9).(action->modulecxx . . $ oscap_action#module., stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
108 }
109 }
110 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
111 }
112
113
114 static int print_versionscxx . . $ print_versions(d99c68634f61e371).(const struct oscap_actioncxx . . $ oscap_action# *action)
115 {
116 printfcxx . . $ printf(581fddd72a8db8fc).("OpenSCAP command line tool (oscap) %s\n" "Copyright 2009--2023 Red Hat Inc., Durham, North Carolina.\n\n",
117 oscap_get_versioncxx . . $ oscap_get_version(33a1f659e94feb42).());
118
119 printfcxx . . $ printf(581fddd72a8db8fc).("==== Supported specifications ====\n");
120 printfcxx . . $ printf(581fddd72a8db8fc).("SCAP Version: 1.3\n");
121 printfcxx . . $ printf(581fddd72a8db8fc).("XCCDF Version: %s\n", xccdf_benchmark_supportedcxx . . $ xccdf_benchmark_supported(33a1f659e94feb42).());
122 printfcxx . . $ printf(581fddd72a8db8fc).("OVAL Version: %s\n", oval_definition_model_supportedcxx . . $ oval_definition_model_supported(33a1f659e94feb42).());
123 printfcxx . . $ printf(581fddd72a8db8fc).("CPE Version: %s\n", cpe_dict_model_supportedcxx . . $ cpe_dict_model_supported(33a1f659e94feb42).());
124 printfcxx . . $ printf(581fddd72a8db8fc).("Asset Identification Version: %s\n", "1.1");
125 printfcxx . . $ printf(581fddd72a8db8fc).("Asset Reporting Format Version: %s\n", "1.1");
126 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
127
128 printfcxx . . $ printf(581fddd72a8db8fc).("==== Capabilities added by auto-loaded plugins ====\n");
129
130 const char * const *known_plugins = check_engine_plugin_get_known_pluginscxx . . $ check_engine_plugin_get_known_plugins(93405d8a1d31001f).();
131 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! known_plugin_found = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
132 while (*known_plugins) {
133 // try to load the plugin but output no errors if it fails (quiet=true)
134 struct check_engine_plugin_defcxx . . $ check_engine_plugin_def# *plugin = check_engine_plugin_load2cxx . . $ check_engine_plugin_load2(9071ba705b7532d3).(*known_plugins, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
135 if (plugin) {
136 printfcxx . . $ printf(581fddd72a8db8fc).("%s (from %s)\n", check_engine_plugin_get_capabilitiescxx . . $ check_engine_plugin_get_capabilities(8ffb468a72dc1f09).(plugin), *known_plugins);
137 check_engine_plugin_unloadcxx . . $ check_engine_plugin_unload(be78ae89c758d8d0).(plugin);
138 known_plugin_found = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
139 }
140 known_plugins++;
141 }
142
143 if (!known_plugin_found)
144 printfcxx . . $ printf(581fddd72a8db8fc).("No plugins have been auto-loaded...\n");
145
146 // We do not report failure when a known plugin doesn't load properly, that's because they
147 // are optional and we don't know if it's not there or if it just failed to load.
148 oscap_clearerrcxx . . $ oscap_clearerr(49f6e7a06ebc5aa8).();
149
150 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
151
152 printfcxx . . $ printf(581fddd72a8db8fc).("==== Paths ====\n");
153 printfcxx . . $ printf(581fddd72a8db8fc).("Schema files: %s\n", oscap_path_to_schemascxx . . $ oscap_path_to_schemas(33a1f659e94feb42).());
154 printfcxx . . $ printf(581fddd72a8db8fc).("Default CPE files: %s\n", oscap_path_to_cpecxx . . $ oscap_path_to_cpe(33a1f659e94feb42).());
155 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
156
157 printfcxx . . $ printf(581fddd72a8db8fc).("==== Inbuilt CPE names ====\n");
158 char default_cpe_path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
159 snprintfcxx . . $ snprintf(ea502d73e74c754c).(default_cpe_path, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!, "%s/openscap-cpe-dict.xml", oscap_path_to_cpecxx . . $ oscap_path_to_cpe(33a1f659e94feb42).());
160 struct oscap_sourcecxx . . $ oscap_source# *source = oscap_source_new_from_filecxx . . $ oscap_source_new_from_file(987f8b70a317ffb9).(default_cpe_path);
161 struct cpe_dict_modelcxx . . $ cpe_dict_model#* cpe_dict = cpe_dict_model_import_sourcecxx . . $ cpe_dict_model_import_source(855462c7c482ecd).(source);
162 oscap_source_freecxx . . $ oscap_source_free(1a322e80279420f6).(source);
163 if (cpe_dict != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
164
165 struct cpe_item_iteratorcxx . . $ cpe_item_iterator#* cpe_items = cpe_dict_model_get_itemscxx . . $ cpe_dict_model_get_items(5cb21604d6b88b36).(cpe_dict);
166 while (cpe_item_iterator_has_morecxx . . $ cpe_item_iterator_has_more(7dc86bb14a5a3233).(cpe_items))
167 {
168 struct cpe_itemcxx . . $ cpe_item#* cpe_item = cpe_item_iterator_nextcxx . . $ cpe_item_iterator_next(94b1c680ffbf1664).(cpe_items);
169
170 struct oscap_text_iteratorcxx . . $ oscap_text_iterator#* titles = cpe_item_get_titlescxx . . $ cpe_item_get_titles(5c0ba1dfe0c35092).(cpe_item);
171 char* str_title = oscap_textlist_get_preferred_plaintextcxx . . $ oscap_textlist_get_preferred_plaintext(9be0225be21606c3).(titles, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
172 oscap_text_iterator_freecxx . . $ oscap_text_iterator_free(f60c6cfdbf1f29d7).(titles);
173
174 struct cpe_namecxx . . $ cpe_name#* name = cpe_item_get_namecxx . . $ cpe_item_get_name(24587e6e1062bef5).(cpe_item);
175 char * str_name = cpe_name_get_as_formatcxx . . $ cpe_name_get_as_format(d944afa77bbd3357).(name, CPE_FORMAT_URIcxx . . $ CPE_FORMAT_URI.);
176
177 printfcxx . . $ printf(581fddd72a8db8fc).("%s - %s\n", str_title, str_name);
178
179 freecxx . . $ free(5d22bdacc48458e8).(str_name);
180 freecxx . . $ free(5d22bdacc48458e8).(str_title);
181 }
182 cpe_item_iterator_freecxx . . $ cpe_item_iterator_free(8056d2d460529853).(cpe_items);
183 cpe_dict_model_freecxx . . $ cpe_dict_model_free(99656294ab2c75d7).(cpe_dict);
184 }
185 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
186 #if defined(OVAL_PROBES_ENABLEDcxx . . $ `build/config.h:67:9`!)
187 printfcxx . . $ printf(581fddd72a8db8fc).("==== Supported OVAL objects and associated OpenSCAP probes ====\n");
188 printfcxx . . $ printf(581fddd72a8db8fc).("%-14s%-28s %-28s\n", "OVAL family", "OVAL object", "OpenSCAP probe");
189 printfcxx . . $ printf(581fddd72a8db8fc).("%-14s%-28s %-28s\n", "----------", "----------", "----------");
190 probe_table_listcxx . . $ probe_table_list(8d4262d45fc644ab).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
191 #endif
192
193 return OSCAP_OKcxx . . $ OSCAP_OK.;
194 }
195
196 int reportercxx . . $ reporter(710d628f83af7da6).(const char *file, int line, const char *msg, void *arg) {
197 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "File '%s' line %d: %s", file, line, msg);
198 return 0;
199 }
200