| 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 | * Maros Barabas <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | #ifndef OSCAP_TOOL_H_ |
| 25 | #define OSCAP_TOOL_H_ |
| 26 | |
| 27 | /* Standard header files */ |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | #ifdef HAVE_GETOPT_H |
| 32 | #include <getopt.h> |
| 33 | #endif |
| 34 | |
| 35 | /* openscap common */ |
| 36 | #include <oscap.h> |
| 37 | #include <oscap_error.h> |
| 38 | #include <oscap_text.h> |
| 39 | |
| 40 | #include <oval_definitions.h> |
| 41 | #if defined(OVAL_PROBES_ENABLED) |
| 42 | # include <oval_probe.h> |
| 43 | #endif |
| 44 | #include <xccdf_benchmark.h> |
| 45 | #include <xccdf_session.h> |
| 46 | #include <cpe_dict.h> |
| 47 | #include <cpe_name.h> |
| 48 | |
| 49 | #define OSCAP_PRODUCTNAME "cpe:/a:open-scap:oscap" |
| 50 | #define OSCAP_ERR_MSG "OpenSCAP Error:" |
| 51 | |
| 52 | struct oscap_action; |
| 53 | struct oscap_module; |
| 54 | |
| 55 | typedef int(*oscap_tool_func)(const struct oscap_action* action); |
| 56 | typedef bool(*oscap_option_func)(int argc, char **argv, struct oscap_action* action); |
| 57 | |
| 58 | struct oscap_module { |
| 59 | const char *name; |
| 60 | const char *usage; |
| 61 | const char *usage_extra; |
| 62 | const char *summary; |
| 63 | const char *help; |
| 64 | bool hidden; |
| 65 | struct oscap_module *parent; |
| 66 | struct oscap_module **submodules; |
| 67 | oscap_tool_func func; |
| 68 | oscap_option_func opt_parser; |
| 69 | void *user; |
| 70 | }; |
| 71 | |
| 72 | // standard oscap CLI exit statuses |
| 73 | enum oscap_exitcode { |
| 74 | OSCAP_OK = 0, // successful exit |
| 75 | OSCAP_ERROR = 1, // an error occurred |
| 76 | OSCAP_FAIL = 2, // a process (e.g. scan or validation) failed |
| 77 | OSCAP_ERR_FETCH = 1, // cold not fetch input file (same as error for now) |
| 78 | OSCAP_BADARGS = 100, // bad commandline arguments |
| 79 | OSCAP_BADMODULE = 101, // unrecognized module |
| 80 | OSCAP_UNIMPL_MOD = 110, // module functionality not implemented |
| 81 | OSCAP_UNIMPL = 111, // functionality not implemented |
| 82 | // end of list |
| 83 | OSCAP_EXITCODES_END_ = 120 // any code returned shall not be higher than this |
| 84 | }; |
| 85 | |
| 86 | struct ds_action { |
| 87 | char* file; |
| 88 | char* target; |
| 89 | char* xccdf_result; |
| 90 | char** oval_results; |
| 91 | size_t oval_result_count; |
| 92 | }; |
| 93 | |
| 94 | struct cpe_action { |
| 95 | char * name; |
| 96 | char * dict; |
| 97 | }; |
| 98 | |
| 99 | struct cve_action { |
| 100 | char * file; |
| 101 | char * cve; |
| 102 | }; |
| 103 | |
| 104 | struct oscap_action { |
| 105 | struct oscap_module *module; |
| 106 | /* files */ |
| 107 | char *f_xccdf; |
| 108 | char *f_datastream_id; |
| 109 | char *f_xccdf_id; |
| 110 | char *f_oval_id; |
| 111 | char *f_benchmark_id; |
| 112 | char *f_report_id; |
| 113 | char *f_oval; |
| 114 | char **f_ovals; |
| 115 | char *f_syschar; |
| 116 | char *f_directives; |
| 117 | char *f_results; |
| 118 | char *f_results_stig; |
| 119 | char *f_results_arf; |
| 120 | char *f_report; |
| 121 | char *f_variables; |
| 122 | char *f_verbose_log; |
| 123 | /* others */ |
| 124 | char *profile; |
| 125 | struct oscap_stringlist *rules; |
| 126 | struct oscap_stringlist *skip_rules; |
| 127 | char *format; |
| 128 | char *id; |
| 129 | int hide_profile_info; |
| 130 | char *stylesheet; |
| 131 | char *tailoring_file; |
| 132 | char *tailoring_id; |
| 133 | char *cpe; |
| 134 | |
| 135 | struct ds_action* ds_action; |
| 136 | struct cpe_action * cpe_action; |
| 137 | struct cve_action * cve_action; |
| 138 | struct cvrf_action * cvrf_action; |
| 139 | char *file; |
| 140 | |
| 141 | int verbosity; |
| 142 | int show_profiles_only; |
| 143 | int provide_machine_readable_output; |
| 144 | int doctype; |
| 145 | int force; |
| 146 | int validate; |
| 147 | int validate_signature; |
| 148 | int enforce_signature; |
| 149 | int schematron; |
| 150 | int remote_resources; |
| 151 | int progress; |
| 152 | int oval_results; |
| 153 | int without_sys_chars; |
| 154 | int thin_results; |
| 155 | int remediate; |
| 156 | int check_engine_results; |
| 157 | int export_variables; |
| 158 | int list_dynamic; |
| 159 | char *verbosity_level; |
| 160 | char *fix_type; |
| 161 | char *local_files; |
| 162 | char *reference; |
| 163 | int references; |
| 164 | int raw; |
| 165 | int show_rule_details; |
| 166 | int list_rules; |
| 167 | int list_vars; |
| 168 | }; |
| 169 | |
| 170 | int app_xslt(const char *infile, const char *xsltfile, const char *outfile, const char **params); |
| 171 | int reporter(const char *file, int line, const char *msg, void *arg); |
| 172 | |
| 173 | int oscap_module_process(struct oscap_module *module, int argc, char **argv); |
| 174 | bool oscap_module_usage(struct oscap_module *module, FILE *out, const char *err, ...); |
| 175 | int oscap_module_call(struct oscap_action *action); |
| 176 | |
| 177 | void oscap_print_error(void); |
| 178 | bool check_verbose_options(struct oscap_action *action); |
| 179 | void download_reporting_callback(bool warning, const char *format, ...); |
| 180 | |
| 181 | void report_missing_profile(const char *profile_suffix, const char *source_file); |
| 182 | void report_multiple_profile_matches(const char *profile_suffix, const char *source_file); |
| 183 | |
| 184 | int xccdf_set_profile_or_report_bad_id(struct xccdf_session *session, const char *profile_id, const char *source_file); |
| 185 | int evaluate_suffix_match_result_with_custom_reports(int suffix_match_result, const char *profile_suffix, const char *source_file, void (* report_missing)(const char *, const char *), void (* report_multiple)(const char *, const char *)); |
| 186 | int evaluate_suffix_match_result(int suffix_match_result, const char *profile_suffix, const char *source_file); |
| 187 | |
| 188 | extern struct oscap_module OSCAP_ROOT_MODULE; |
| 189 | extern struct oscap_module OSCAP_DS_MODULE; |
| 190 | extern struct oscap_module OSCAP_XCCDF_MODULE; |
| 191 | extern struct oscap_module OSCAP_OVAL_MODULE; |
| 192 | extern struct oscap_module OSCAP_CVE_MODULE; |
| 193 | extern struct oscap_module OSCAP_CPE_MODULE; |
| 194 | extern struct oscap_module OSCAP_INFO_MODULE; |
| 195 | |
| 196 | #ifndef HAVE_GETOPT_H |
| 197 | |
| 198 | #define __getopt_argv_const const |
| 199 | #define no_argument 0 |
| 200 | #define required_argument 1 |
| 201 | #define optional_argument 2 |
| 202 | |
| 203 | extern char *optarg; |
| 204 | extern int optind; |
| 205 | extern int opterr; |
| 206 | extern int optopt; |
| 207 | |
| 208 | struct option |
| 209 | { |
| 210 | const char *name; |
| 211 | int has_arg; |
| 212 | int *flag; |
| 213 | int val; |
| 214 | }; |
| 215 | |
| 216 | getopt_long(int ___argc, char *__getopt_argv_const *___argv, |
| 217 | const char *__shortopts, |
| 218 | const struct option *__longopts, int *__longind); |
| 219 | |
| 220 | #endif |
| 221 | |
| 222 | #endif //OSCAP_TOOL_H_ |