| 1 | /** |
| 2 | * @addtogroup XCCDF |
| 3 | * @{ |
| 4 | * @addtogroup Session |
| 5 | * @{ |
| 6 | * |
| 7 | * @file xccdf_session.h |
| 8 | * High Level API for OpenSCAP XCCDF operations. |
| 9 | * @author Simon Lukasik <[email protected]> |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Copyright 2013 Red Hat Inc., Durham, North Carolina. |
| 14 | * All Rights Reserved. |
| 15 | * |
| 16 | * This library is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU Lesser General Public |
| 18 | * License as published by the Free Software Foundation; either |
| 19 | * version 2.1 of the License, or (at your option) any later version. |
| 20 | * |
| 21 | * This library is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 24 | * Lesser General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU Lesser General Public |
| 27 | * License along with this library; if not, write to the Free Software |
| 28 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 | * |
| 30 | */ |
| 31 | |
| 32 | #ifndef XCCDF_SESSION_H_ |
| 33 | #define XCCDF_SESSION_H_ |
| 34 | |
| 35 | #include "xccdf_policy.h" |
| 36 | #include "oscap_download_cb.h" |
| 37 | #include "oscap_export.h" |
| 38 | |
| 39 | /** |
| 40 | * @struct xccdf_session |
| 41 | * A structure encapsulating the context of XCCDF operations. |
| 42 | */ |
| 43 | struct xccdf_session; |
| 44 | |
| 45 | /** |
| 46 | * Loading flags for XCCDF session |
| 47 | * @memberof xccdf_session |
| 48 | * The flags set which components will be loaded in XCCDF session. |
| 49 | */ |
| 50 | typedef enum { |
| 51 | XCCDF_SESSION_LOAD_NONE = 0, |
| 52 | XCCDF_SESSION_LOAD_XCCDF = 1 << 0, |
| 53 | XCCDF_SESSION_LOAD_CPE = 1 << 1, |
| 54 | XCCDF_SESSION_LOAD_OVAL = 1 << 2, |
| 55 | XCCDF_SESSION_LOAD_CHECK_ENGINE_PLUGINS = 1 << 3, |
| 56 | XCCDF_SESSION_LOAD_ALL = XCCDF_SESSION_LOAD_XCCDF | XCCDF_SESSION_LOAD_CPE | XCCDF_SESSION_LOAD_OVAL | XCCDF_SESSION_LOAD_CHECK_ENGINE_PLUGINS |
| 57 | } xccdf_session_loading_flags_t; |
| 58 | |
| 59 | /** |
| 60 | * Costructor of xccdf_session. It attempts to recognize type of the filename. |
| 61 | * @memberof xccdf_session |
| 62 | * @param filename path to XCCDF or DS file. |
| 63 | * @returns newly created \ref xccdf_session. |
| 64 | * @retval NULL is returned in case of error. Details might be found through \ref oscap_err_desc() |
| 65 | */ |
| 66 | OSCAP_API struct xccdf_session *xccdf_session_new(const char *filename); |
| 67 | |
| 68 | /** |
| 69 | * Costructor of xccdf_session. It creates a new xccdf_session from an oscap_source structure. |
| 70 | * @memberof xccdf_session |
| 71 | * @param source oscap_source which can represent a DS or XCCDF file. |
| 72 | * @returns newly created \ref xccdf_session. |
| 73 | * @retval NULL is returned in case of error. Details might be found through \ref oscap_err_desc() |
| 74 | */ |
| 75 | OSCAP_API struct xccdf_session *xccdf_session_new_from_source(struct oscap_source *source); |
| 76 | |
| 77 | /** |
| 78 | * Destructor of xccdf_session. |
| 79 | * @memberof xccdf_session |
| 80 | * @param session to destroy. |
| 81 | */ |
| 82 | OSCAP_API void xccdf_session_free(struct xccdf_session *session); |
| 83 | |
| 84 | /** |
| 85 | * Reset xccdf_session results. |
| 86 | * This function resets XCCDF policies, session rules, skipped rules, OVAL system characteristics and OVAL results. |
| 87 | * @memberof xccdf_session |
| 88 | * @param session to reset results from. |
| 89 | */ |
| 90 | OSCAP_API void xccdf_session_result_reset(struct xccdf_session *session); |
| 91 | |
| 92 | /** |
| 93 | * Retrieves the filename the session was created with |
| 94 | * @memberof xccdf_session |
| 95 | */ |
| 96 | OSCAP_API const char *xccdf_session_get_filename(const struct xccdf_session *session); |
| 97 | |
| 98 | /** |
| 99 | * Query if the session is based on Source DataStream. |
| 100 | * @memberof xccdf_session |
| 101 | * @param session XCCDF Session |
| 102 | * @returns true if the session is based on Source Datastream |
| 103 | */ |
| 104 | OSCAP_API bool xccdf_session_is_sds(const struct xccdf_session *session); |
| 105 | |
| 106 | /** |
| 107 | * Set rule for session - if rule is not NULL, session will use only this |
| 108 | * one rule. |
| 109 | * @memberof xccdf_session |
| 110 | * @param session XCCDF Session |
| 111 | * @param rule If not NULL, session will use only this rule |
| 112 | */ |
| 113 | OSCAP_DEPRECATED(OSCAP_API void xccdf_session_set_rule(struct xccdf_session *session, const char *rule)); |
| 114 | |
| 115 | /** |
| 116 | * Add specific rule for session - if at least one rule is added to the session, |
| 117 | * only the added rules will be evaluated |
| 118 | * @memberof xccdf_session |
| 119 | * @param session XCCDF Session |
| 120 | * @param rule rule ID |
| 121 | */ |
| 122 | OSCAP_API void xccdf_session_add_rule(struct xccdf_session *session, const char *rule); |
| 123 | |
| 124 | /** |
| 125 | * Skip rule during evaluation of the session |
| 126 | * @memberof xccdf_session |
| 127 | * @param session XCCDF Session |
| 128 | * @param rule rule ID |
| 129 | */ |
| 130 | OSCAP_API void xccdf_session_skip_rule(struct xccdf_session *session, const char *rule); |
| 131 | |
| 132 | /** |
| 133 | * Set XSD validation level to one of three possibilities: |
| 134 | * - None: All XSD validations will be skipped. |
| 135 | * - Default: Partial (input) XSD validations will be done. |
| 136 | * - Full Valid.: Every possible (input & output) XSD validation will be done. |
| 137 | * @memberof xccdf_session |
| 138 | * @param session XCCDF Session |
| 139 | * @param validate False value indicates to skip any XSD validation. |
| 140 | * @param full_validation True value indicates that every possible step will be validated by XSD. |
| 141 | */ |
| 142 | OSCAP_API void xccdf_session_set_validation(struct xccdf_session *session, bool validate, bool full_validation); |
| 143 | |
| 144 | /** |
| 145 | * Set XML signature validation |
| 146 | * @memberof xccdf_session |
| 147 | * @param session XCCDF Session |
| 148 | * @param validate False value indicates to skip any XML signature validation. |
| 149 | */ |
| 150 | OSCAP_API void xccdf_session_set_signature_validation(struct xccdf_session *session, bool validate); |
| 151 | |
| 152 | /** |
| 153 | * Set XML signature enforcement |
| 154 | * @memberof xccdf_session |
| 155 | * @param session XCCDF Session |
| 156 | * @param enforce True value renders all unsigned XMLs invalid. |
| 157 | */ |
| 158 | OSCAP_API void xccdf_session_set_signature_enforcement(struct xccdf_session *session, bool enforce); |
| 159 | |
| 160 | /** |
| 161 | * Set whether the thin results override is enabled. |
| 162 | * If true the OVAL results put in ARF or separate files will have thin results. |
| 163 | * Thin results do not contain details about the evaluated criteria, only |
| 164 | * minimal OVAL results. |
| 165 | * @memberof xccdf_session |
| 166 | * @param thin_results true to enable thin_results, default is false |
| 167 | */ |
| 168 | OSCAP_API void xccdf_session_set_thin_results(struct xccdf_session *session, bool thin_result); |
| 169 | |
| 170 | /** |
| 171 | * Set requested datastream_id for this session. This datastream_id is later |
| 172 | * passed down to @ref ds_sds_index_select_checklist to determine target component. |
| 173 | * This function is applicable only for sessions based on a DataStream. |
| 174 | * @memberof xccdf_session |
| 175 | * @param session XCCDF Session |
| 176 | * @param datastream_id requested datastream_id for this session. |
| 177 | */ |
| 178 | OSCAP_API void xccdf_session_set_datastream_id(struct xccdf_session *session, const char *datastream_id); |
| 179 | |
| 180 | /** |
| 181 | * Retrieves the datastream id |
| 182 | * @see xccdf_session_set_datastream_id |
| 183 | * @memberof xccdf_session |
| 184 | */ |
| 185 | OSCAP_API const char *xccdf_session_get_datastream_id(struct xccdf_session *session); |
| 186 | |
| 187 | /** |
| 188 | * Set requested component_id for this session. This component_id is later |
| 189 | * pased down to @ref ds_sds_index_select_checklist to determine target component. |
| 190 | * This function is applicable only for sessions based on a DataStream. |
| 191 | * @memberof xccdf_session |
| 192 | * @param session XCCDF Session |
| 193 | * @param component_id requested component_id for this session. |
| 194 | */ |
| 195 | OSCAP_API void xccdf_session_set_component_id(struct xccdf_session *session, const char *component_id); |
| 196 | |
| 197 | /** |
| 198 | * Retrieves the component id |
| 199 | * @see xccdf_session_set_component_id |
| 200 | * @memberof xccdf_session |
| 201 | */ |
| 202 | OSCAP_API const char *xccdf_session_get_component_id(struct xccdf_session *session); |
| 203 | |
| 204 | /** |
| 205 | * Sets requested benchmark_id for this session. It is only used when no component_id |
| 206 | * and no datastream_id are requested. Benchmark ID selects the @id attribute of Benchmark |
| 207 | * element inside a component that is referenced with a checklist component-ref. |
| 208 | * @memberof xccdf_session |
| 209 | */ |
| 210 | OSCAP_API void xccdf_session_set_benchmark_id(struct xccdf_session *session, const char *benchmark_id); |
| 211 | |
| 212 | /** |
| 213 | * Retrieves the benchmark_id |
| 214 | * @see xccdf_session_set_benchmark_id |
| 215 | * @memberof xccdf_session |
| 216 | */ |
| 217 | OSCAP_API const char *xccdf_session_get_benchmark_id(struct xccdf_session *session); |
| 218 | |
| 219 | /** |
| 220 | * Retrieves the result id |
| 221 | * @memberof xccdf_session |
| 222 | */ |
| 223 | OSCAP_API const char *xccdf_session_get_result_id(struct xccdf_session *session); |
| 224 | |
| 225 | /** |
| 226 | * Set path to custom CPE dictionary for the session. This function is applicable |
| 227 | * only before session loads. It has no effect if run afterwards. |
| 228 | * @memberof xccdf_session |
| 229 | * @param session XCCDF Session |
| 230 | * @param user_cpe File path to user defined cpe dictionary. |
| 231 | */ |
| 232 | OSCAP_API void xccdf_session_set_user_cpe(struct xccdf_session *session, const char *user_cpe); |
| 233 | |
| 234 | /** |
| 235 | * Set path to custom Tailoring file for the session. This function is applicable |
| 236 | * only before session loads. It has no effect if run afterwards. |
| 237 | * @memberof xccdf_session |
| 238 | * @param session XCCDF Session |
| 239 | * @param user_tailoring_file File path to user defined tailoring file. |
| 240 | */ |
| 241 | OSCAP_API void xccdf_session_set_user_tailoring_file(struct xccdf_session *session, const char *user_tailoring_file); |
| 242 | |
| 243 | OSCAP_API struct oscap_source *xccdf_session_get_user_tailoring_file(struct xccdf_session *session); |
| 244 | |
| 245 | /** |
| 246 | * Set ID of Tailoring component for the session. This function is applicable |
| 247 | * only before session loads. It has no effect if run afterwards. |
| 248 | * @memberof xccdf_session |
| 249 | * @param session XCCDF Session |
| 250 | * @param user_tailoring_cid ID of component with a tailoring file. |
| 251 | */ |
| 252 | OSCAP_API void xccdf_session_set_user_tailoring_cid(struct xccdf_session *session, const char *user_tailoring_cid); |
| 253 | |
| 254 | /** |
| 255 | * Set properties of remote content. |
| 256 | * @memberof xccdf_session |
| 257 | * @param session XCCDF Session |
| 258 | * @param allowed Whether is download od remote resources allowed in this session (defaults to false) |
| 259 | * @param callback used to notify user about download proceeds. This might be safely set |
| 260 | * to NULL -- ignoring user notification. |
| 261 | */ |
| 262 | OSCAP_API OSCAP_DEPRECATED(void xccdf_session_set_remote_resources(struct xccdf_session *session, bool allowed, download_progress_calllback_t callback)); |
| 263 | |
| 264 | /** |
| 265 | * Set properties of remote content. |
| 266 | * @memberof xccdf_session |
| 267 | * @param session XCCDF Session |
| 268 | * @param allowed Whether is download od remote resources allowed in this |
| 269 | * session (defaults to false) |
| 270 | * @param local_files Allows to use a locally downloaded copy of the remote |
| 271 | * resources. Contains a path to a directory where the files are stored |
| 272 | * (defaults to NULL). |
| 273 | * @param callback used to notify user about download proceeds. This might be |
| 274 | * safely set to NULL -- ignoring user notification. |
| 275 | */ |
| 276 | OSCAP_API void xccdf_session_configure_remote_resources(struct xccdf_session *session, bool allowed, const char *local_files, download_progress_calllback_t callback); |
| 277 | |
| 278 | /** |
| 279 | * Disable or allow loading of depending content (OVAL, SCE, CPE) |
| 280 | * @memberof xccdf_session |
| 281 | * @param session XCCDF Session |
| 282 | * @param flags Bit mask that sets loading of other content in the session. |
| 283 | */ |
| 284 | OSCAP_API void xccdf_session_set_loading_flags(struct xccdf_session *session, xccdf_session_loading_flags_t flags); |
| 285 | |
| 286 | /** |
| 287 | * Set custom oval files for this session |
| 288 | * @memberof xccdf_session |
| 289 | * @param session XCCDF Session |
| 290 | * @param oval_filenames - Array of paths to custom OVAL files. If the array is empty |
| 291 | * no OVAL file will be used for the session. If this parameter is NULL then OVAL |
| 292 | * files will be find automatically, as defined in XCCDF (which is default). |
| 293 | */ |
| 294 | OSCAP_API void xccdf_session_set_custom_oval_files(struct xccdf_session *session, char **oval_filenames); |
| 295 | |
| 296 | /** |
| 297 | * Set custom OVAL eval function to register with each OVAL session. This function shall |
| 298 | * be called before OVAL files are parsed. |
| 299 | * @memberof xccdf_session |
| 300 | * @param session XCCDF Session. |
| 301 | * @param eval_fn Callback - pointer to function called by XCCDF Policy for each evaluated rule. |
| 302 | */ |
| 303 | OSCAP_API void xccdf_session_set_custom_oval_eval_fn(struct xccdf_session *session, xccdf_policy_engine_eval_fn eval_fn); |
| 304 | |
| 305 | /** |
| 306 | * Set custom product CPE name. |
| 307 | * @memberof xccdf_session |
| 308 | * @param session XCCDF Session. |
| 309 | * @param product_cpe Name of the scanner product. |
| 310 | * @returns true on success |
| 311 | */ |
| 312 | OSCAP_API bool xccdf_session_set_product_cpe(struct xccdf_session *session, const char *product_cpe); |
| 313 | |
| 314 | /** |
| 315 | * Set whether the System Characteristics shall be exported in result files. |
| 316 | * @memberof xccdf_session |
| 317 | * @param session XCCDF Session |
| 318 | * @param without_sys_chars whether to export System Characteristics or not. |
| 319 | */ |
| 320 | OSCAP_API void xccdf_session_set_without_sys_chars_export(struct xccdf_session *session, bool without_sys_chars); |
| 321 | |
| 322 | /** |
| 323 | * Set whether the OVAL result files shall be exported. |
| 324 | * @memberof xccdf_session |
| 325 | * @param session XCCDF Session |
| 326 | * @param to_export_oval_results whether to export results or not. |
| 327 | */ |
| 328 | OSCAP_API void xccdf_session_set_oval_results_export(struct xccdf_session *session, bool to_export_oval_results); |
| 329 | |
| 330 | /** |
| 331 | * Set that check engine plugin's result files shall be exported. |
| 332 | * @memberof xccdf_session |
| 333 | * @param session XCCDF Session |
| 334 | * @param to_export_results whether to export results from check engine plugins or not. |
| 335 | */ |
| 336 | OSCAP_API void xccdf_session_set_check_engine_plugins_results_export(struct xccdf_session *session, bool to_export_results); |
| 337 | |
| 338 | /** |
| 339 | * Set whether the OVAL variables files shall be exported. |
| 340 | * @memberof xccdf_session |
| 341 | * @param session XCCDF Session |
| 342 | * @param to_export_oval_variables whether to export results or not. |
| 343 | */ |
| 344 | OSCAP_API void xccdf_session_set_oval_variables_export(struct xccdf_session *session, bool to_export_oval_variables); |
| 345 | |
| 346 | /** |
| 347 | * Set where to export XCCDF file. NULL value means to not export at all. |
| 348 | * @memberof xccdf_session |
| 349 | * @param session XCCDF Session |
| 350 | * @param xccdf_file path to XCCDF file |
| 351 | * @returns true on success |
| 352 | */ |
| 353 | OSCAP_API bool xccdf_session_set_xccdf_export(struct xccdf_session *session, const char *xccdf_file); |
| 354 | |
| 355 | /** |
| 356 | * Set where to export STIG Viewer XCCDF file. NULL value means to not export at all. |
| 357 | * @memberof xccdf_session |
| 358 | * @param session XCCDF Session |
| 359 | * @param xccdf_file path to STIG Viewer file |
| 360 | * @returns true on success |
| 361 | */ |
| 362 | OSCAP_API bool xccdf_session_set_xccdf_stig_viewer_export(struct xccdf_session *session, const char *xccdf_stig_viewer_file); |
| 363 | |
| 364 | /** |
| 365 | * Set where to export ARF file. NULL value means to not export at all. |
| 366 | * @memberof xccdf_session |
| 367 | * @param session XCCDF Session |
| 368 | * @param arf_file path to ARF file |
| 369 | * @returns true on success |
| 370 | */ |
| 371 | OSCAP_API bool xccdf_session_set_arf_export(struct xccdf_session *session, const char *arf_file); |
| 372 | |
| 373 | /** |
| 374 | * Set where to export HTML Report file. NULL value means to not export at all. |
| 375 | * @memberof xccdf_session |
| 376 | * @param session XCCDF Session |
| 377 | * @param report_file |
| 378 | * @returns true on success |
| 379 | */ |
| 380 | OSCAP_API bool xccdf_session_set_report_export(struct xccdf_session *session, const char *report_file); |
| 381 | |
| 382 | /** |
| 383 | * Select XCCDF Profile for evaluation. |
| 384 | * @memberof xccdf_session |
| 385 | * @param session XCCDF Session |
| 386 | * @param profile_id ID of profile to set |
| 387 | * @returns true on success |
| 388 | */ |
| 389 | OSCAP_API bool xccdf_session_set_profile_id(struct xccdf_session *session, const char *profile_id); |
| 390 | |
| 391 | /** |
| 392 | *Select XCCDF Profile for evaluation with only profile suffix as input. Reports error |
| 393 | *if multiple profiles match the suffix. |
| 394 | *@memberof xccdf_session |
| 395 | *@param session XCCDF Session |
| 396 | *@param profile_suffix unique profile ID or suffix of the ID of the profile to set |
| 397 | *@returns 0 on success, 1 if profile is not found, and 2 if multiple matches are found. |
| 398 | */ |
| 399 | OSCAP_API int xccdf_session_set_profile_id_by_suffix(struct xccdf_session *session, const char *profile_suffix); |
| 400 | |
| 401 | /** |
| 402 | * Retrieves ID of the profile that we will evaluate with, or NULL. |
| 403 | * @memberof xccdf_session |
| 404 | * @param session XCCDF Session |
| 405 | */ |
| 406 | OSCAP_API const char *xccdf_session_get_profile_id(struct xccdf_session *session); |
| 407 | |
| 408 | /** |
| 409 | * Get Source DataStream index of the session. |
| 410 | * @memberof xccdf_session |
| 411 | * @warning This is applicable only on sessions which are SDS. NULL is returned |
| 412 | * otherwise. |
| 413 | * @return sds index |
| 414 | */ |
| 415 | OSCAP_API struct ds_sds_index *xccdf_session_get_sds_idx(struct xccdf_session *session); |
| 416 | |
| 417 | /** |
| 418 | * Load and parse all XCCDF structures needed to evaluate this session. This is |
| 419 | * only a placeholder for load_xccdf, load_cpe, load_oval and load_check_engine_plugins functions. |
| 420 | * @memberof xccdf_session |
| 421 | * @param session XCCDF Session |
| 422 | * @returns zero on success |
| 423 | */ |
| 424 | OSCAP_API int xccdf_session_load(struct xccdf_session *session); |
| 425 | |
| 426 | /** |
| 427 | * Load and parse XCCDF file. If the file upon which is based this session is |
| 428 | * Source DataStream use functions @ref xccdf_session_set_datastream_id and |
| 429 | * @ref xccdf_session_set_component_id to select particular component within |
| 430 | * that DataStream to parse. This function is reentrant meaning that it allows |
| 431 | * user to change i.e. component_id and load_xccdf again in the very same session. |
| 432 | * However in such case, previous xccdf structures will be deallocated from session |
| 433 | * and pointers to it become invalid. |
| 434 | * @memberof xccdf_session |
| 435 | * @param session XCCDF Session |
| 436 | * @returns zero on success |
| 437 | */ |
| 438 | OSCAP_API int xccdf_session_load_xccdf(struct xccdf_session *session); |
| 439 | |
| 440 | /** |
| 441 | * Load and parse CPE dictionaries. Function xccdf_session_set_user_cpe |
| 442 | * might be called before this to set custom CPE dictionary. |
| 443 | * @memberof xccdf_session |
| 444 | * @param session XCCDF Session |
| 445 | * @returns zero on success |
| 446 | */ |
| 447 | OSCAP_API int xccdf_session_load_cpe(struct xccdf_session *session); |
| 448 | |
| 449 | /** |
| 450 | * Load and parse OVAL definitions files for the XCCDF session. |
| 451 | * @memberof xccdf_session |
| 452 | * @param session XCCDF Session |
| 453 | * @returns zero on success |
| 454 | */ |
| 455 | OSCAP_API int xccdf_session_load_oval(struct xccdf_session *session); |
| 456 | |
| 457 | /** |
| 458 | * Load extra check engine from a plugin of given name to the XCCDF session. |
| 459 | * |
| 460 | * Extra check engines are in loadable shared objects. This function is |
| 461 | * designed to be called !after! xccdf_session_load has been called. |
| 462 | * XCCDF has to have already been loaded for this to work because the callbacks |
| 463 | * are registered as part of this function! |
| 464 | * |
| 465 | * @memberof xccdf_session |
| 466 | * @param session XCCDF Session |
| 467 | * @param plugin_name Name of the plugin to load |
| 468 | * @param quiet If true we will not output errors if loading fails |
| 469 | * @returns zero on success |
| 470 | */ |
| 471 | OSCAP_API int xccdf_session_load_check_engine_plugin2(struct xccdf_session *session, const char* plugin_name, bool quiet); |
| 472 | OSCAP_API int xccdf_session_load_check_engine_plugin(struct xccdf_session *session, const char* plugin_name); |
| 473 | |
| 474 | /** |
| 475 | * Load extra check engines (if any are available) to the XCCDF session. |
| 476 | * |
| 477 | * Extra check engines are in loadable shared objects and this function |
| 478 | * searches if any such are available and loads them if they are. |
| 479 | * |
| 480 | * @memberof xccdf_session |
| 481 | * @param session XCCDF Session |
| 482 | * @returns zero on success |
| 483 | */ |
| 484 | OSCAP_API int xccdf_session_load_check_engine_plugins(struct xccdf_session *session); |
| 485 | |
| 486 | /** |
| 487 | * Load Tailoring file (if applicable) to the XCCDF session. |
| 488 | * @memberof xccdf_session |
| 489 | * @param session XCCDF Session |
| 490 | * @returns zero on success |
| 491 | */ |
| 492 | OSCAP_API int xccdf_session_load_tailoring(struct xccdf_session *session); |
| 493 | |
| 494 | /** |
| 495 | * Evaluate XCCDF Policy. |
| 496 | * @memberof xccdf_session |
| 497 | * @param session XCCDF Session |
| 498 | * @returns zero on success |
| 499 | */ |
| 500 | OSCAP_API int xccdf_session_evaluate(struct xccdf_session *session); |
| 501 | |
| 502 | /** |
| 503 | * Export XCCDF file. |
| 504 | * @memberof xccdf_session |
| 505 | * @param session XCCDF Session |
| 506 | * @returns zero on success |
| 507 | */ |
| 508 | OSCAP_API int xccdf_session_export_xccdf(struct xccdf_session *session); |
| 509 | |
| 510 | /** |
| 511 | * Export OVAL (result and variables) files. |
| 512 | * @memberof xccdf_session |
| 513 | * @param session XCCDF Session |
| 514 | * @returns zero on success |
| 515 | */ |
| 516 | OSCAP_API int xccdf_session_export_oval(struct xccdf_session *session); |
| 517 | |
| 518 | /** |
| 519 | * Export results (if any) from any check engine plugins that are loaded |
| 520 | * |
| 521 | * Only applicable if enabled by @ref xccdf_session_set_check_engine_plugins_results_export). |
| 522 | * @memberof xccdf_session |
| 523 | * @param session XCCDF Session |
| 524 | * @returns zero on success |
| 525 | */ |
| 526 | OSCAP_API int xccdf_session_export_check_engine_plugins(struct xccdf_session *session); |
| 527 | |
| 528 | /** |
| 529 | * Export ARF (if enabled by @ref xccdf_session_set_arf_export). |
| 530 | * @memberof xccdf_session |
| 531 | * @param session XCCDF Session |
| 532 | * @returns zero on success |
| 533 | */ |
| 534 | OSCAP_API int xccdf_session_export_arf(struct xccdf_session *session); |
| 535 | |
| 536 | /** |
| 537 | * Get policy_model of the session. The @ref xccdf_session_load_xccdf shall be run |
| 538 | * before this to parse XCCDF file to the policy_model. |
| 539 | * @memberof xccdf_session |
| 540 | * @param session XCCDF Session |
| 541 | * @returns XCCDF Policy Model or NULL in case of failure. |
| 542 | */ |
| 543 | OSCAP_API struct xccdf_policy_model *xccdf_session_get_policy_model(const struct xccdf_session *session); |
| 544 | |
| 545 | /** |
| 546 | * Get xccdf_policy of the session. |
| 547 | * @memberof xccdf_session |
| 548 | * @param session XCCDF Session |
| 549 | * @returns XCCDF Policy or NULL in case of failure. |
| 550 | */ |
| 551 | OSCAP_API struct xccdf_policy *xccdf_session_get_xccdf_policy(const struct xccdf_session *session); |
| 552 | |
| 553 | /** |
| 554 | * Get the base score of the latest XCCDF evaluation in the session. |
| 555 | * @memberof xccdf_session |
| 556 | * @param session XCCDF Session |
| 557 | * @returns the score |
| 558 | */ |
| 559 | OSCAP_API float xccdf_session_get_base_score(const struct xccdf_session *session); |
| 560 | |
| 561 | /** |
| 562 | * Get count of OVAL agent sessions not used for CPE in the xccdf_session. |
| 563 | * @memberof xccdf_session |
| 564 | * @param session XCCDF Session |
| 565 | * @returns number of OVAL agents. |
| 566 | */ |
| 567 | OSCAP_API unsigned int xccdf_session_get_oval_agents_count(const struct xccdf_session *session); |
| 568 | |
| 569 | /** |
| 570 | * Get count of OVAL agent sessions for CPE in the xccdf_session. |
| 571 | * CPE uses OVAL on demand, we do not count OVAL agents that were referenced |
| 572 | * but weren't used. |
| 573 | * @memberof xccdf_session |
| 574 | * @param session XCCDF Session |
| 575 | * @returns number of OVAL agents for CPE. |
| 576 | */ |
| 577 | OSCAP_API unsigned int xccdf_session_get_cpe_oval_agents_count(const struct xccdf_session *session); |
| 578 | |
| 579 | /** |
| 580 | * Query if the result of evaluation contains FAIL, ERROR, or UNKNOWN rule-result elements. |
| 581 | * @memberof xccdf_session |
| 582 | * @param session XCCDF Session |
| 583 | * @returns Exists such rule-result r . r = FAIL | r = UNKNOWN | r = ERROR |
| 584 | */ |
| 585 | OSCAP_API bool xccdf_session_contains_fail_result(const struct xccdf_session *session); |
| 586 | |
| 587 | /** |
| 588 | * @struct xccdf_rule_result_iterator |
| 589 | */ |
| 590 | struct xccdf_rule_result_iterator; |
| 591 | |
| 592 | /** |
| 593 | * Get rule results. |
| 594 | * @memberof xccdf_session |
| 595 | * @param session XCCDF Session |
| 596 | */ |
| 597 | OSCAP_API struct xccdf_rule_result_iterator *xccdf_session_get_rule_results(const struct xccdf_session *session); |
| 598 | |
| 599 | /** |
| 600 | * Run XCCDF Remediation. It uses XCCDF Policy and XCCDF TestResult from the session |
| 601 | * and modifies the TestResult. This also drops and recreate OVAL Agent Session, thus |
| 602 | * users are advised to run @ref xccdf_session_export_oval first. |
| 603 | * @memberof xccdf_session |
| 604 | * @param session XCCDF Session |
| 605 | * @returns zero on success |
| 606 | */ |
| 607 | OSCAP_API int xccdf_session_remediate(struct xccdf_session *session); |
| 608 | |
| 609 | /** |
| 610 | * Load xccdf:TestResult to the session from file and prepare session for remediation. |
| 611 | * This function assumes that the session internals has the policy_model prepared, |
| 612 | * it calculates all the other internals which might be needed for remediation. |
| 613 | * @memberof xccdf_session |
| 614 | * @param session XCCDF Session |
| 615 | * @param testresult_id ID of the TestResult element in the file (the NULL value stands |
| 616 | * for the last TestResult). Suffix match is attempted if exact match is not found. |
| 617 | * @returns zero on success. |
| 618 | */ |
| 619 | OSCAP_API int xccdf_session_build_policy_from_testresult(struct xccdf_session *session, const char *testresult_id); |
| 620 | |
| 621 | /** |
| 622 | * Load xccdf:TestResult to the session from oscap_source |
| 623 | * @memberof xccdf_session |
| 624 | * @param session XCCDF Session |
| 625 | * @param report_source Structure conataining oscap_source of the test results |
| 626 | * @returns zero on success. |
| 627 | */ |
| 628 | OSCAP_API int xccdf_session_add_report_from_source(struct xccdf_session *session, struct oscap_source *report_source); |
| 629 | |
| 630 | /** |
| 631 | * Generate HTML guide form a loaded XCCDF session |
| 632 | * @param session XCCDF Session |
| 633 | * @param outfile path to the output file |
| 634 | * @returns zero on success |
| 635 | */ |
| 636 | OSCAP_API int xccdf_session_generate_guide(struct xccdf_session *session, const char *outfile); |
| 637 | |
| 638 | /** |
| 639 | * Export XCCDF results, ARF results and HTML report from the given XCCDF |
| 640 | * session based on values set in the XCCDF session. This is a destructive |
| 641 | * operation that modifies the oscap_source structures, specifically the XML |
| 642 | * trees. Callers must not perform any operation with the session after this |
| 643 | * call and they must free the session immediately. |
| 644 | * @param session XCCDF Session |
| 645 | * @returns zero on success |
| 646 | */ |
| 647 | OSCAP_API int xccdf_session_export_all(struct xccdf_session *session); |
| 648 | |
| 649 | /** |
| 650 | * Set reference filter to the XCCDF session. If this filter is set, |
| 651 | * the XCCDF session will evaluate only rules that conform to the filter. |
| 652 | * @param session XCCDF session |
| 653 | * @param reference_filter a string in a form "key:identifier" |
| 654 | */ |
| 655 | OSCAP_API void xccdf_session_set_reference_filter(struct xccdf_session *session, const char *reference_filter); |
| 656 | |
| 657 | /** |
| 658 | * Enable or disable showing rule details such as description or rationale in command line output. |
| 659 | * @param session XCCDF session |
| 660 | * @param show_rule_details whether to show rule details in command line output |
| 661 | */ |
| 662 | OSCAP_API void xccdf_session_set_show_rule_details(struct xccdf_session *session, bool show_rule_details); |
| 663 | |
| 664 | /// @} |
| 665 | /// @} |
| 666 | #endif |