Session
XCCDF

## Files

file | xccdf_session.h
| High Level API for OpenSCAP XCCDF operations.

## Data Structures

struct | xccdf_session
| A structure encapsulating the context of XCCDF operations. More...

## Typedefs

typedef void(* | download_progress_calllback_t )(bool warning, const char *format,...)
| Type of the function used to report progress of download. More...

## Functions

int | xccdf_session_load_sce (struct xccdf_session *session)
struct xccdf_session * | xccdf_session::xccdf_session_new (const char *filename)
| Costructor of xccdf_session. More...
void | xccdf_session::xccdf_session_free (struct xccdf_session *session)
| Destructor of xccdf_session. More...
const char * | xccdf_session::xccdf_session_get_filename (const struct xccdf_session *session)
| Retrieves the filename the session was created with.
bool | xccdf_session::xccdf_session_is_sds (const struct xccdf_session *session)
| Query if the session is based on Source DataStream. More...
void | xccdf_session::xccdf_session_set_validation (struct xccdf_session *session, bool validate, bool full_validation)
| Set XSD validation level. More...
void | xccdf_session::xccdf_session_set_datastream_id (struct xccdf_session *session, const char *datastream_id)
| Set requested datastream_id for this session. More...
const char * | xccdf_session::xccdf_session_get_datastream_id (struct xccdf_session *session)
| Retrieves the datastream id. More...
void | xccdf_session::xccdf_session_set_component_id (struct xccdf_session *session, const char *component_id)
| Set requested component_id for this session. More...
const char * | xccdf_session::xccdf_session_get_component_id (struct xccdf_session *session)
| Retrieves the component id. More...
void | xccdf_session::xccdf_session_set_benchmark_id (struct xccdf_session *session, const char *benchmark_id)
| Sets requested benchmark_id for this session. More...
const char * | xccdf_session::xccdf_session_get_benchmark_id (struct xccdf_session *session)
| Retrieves the benchmark_id. More...
void | xccdf_session::xccdf_session_set_user_cpe (struct xccdf_session *session, const char *user_cpe)
| Set path to custom CPE dictionary for the session. More...
void | xccdf_session::xccdf_session_set_user_tailoring_file (struct xccdf_session *session, const char *user_tailoring_file)
| Set path to custom Tailoring file for the session. More...
void | xccdf_session::xccdf_session_set_user_tailoring_cid (struct xccdf_session *session, const char *user_tailoring_cid)
| Set ID of Tailoring component for the session. More...
void | xccdf_session::xccdf_session_set_remote_resources (struct xccdf_session *session, bool allowed, download_progress_calllback_t callback)
| Set properties of remote content. More...
void | xccdf_session::xccdf_session_set_custom_oval_files (struct xccdf_session *session, char **oval_filenames)
| Set custom oval files for this session. More...
void | xccdf_session::xccdf_session_set_custom_oval_eval_fn (struct xccdf_session *session, xccdf_policy_engine_eval_fn eval_fn)
| Set custom OVAL eval function to register with each OVAL session. More...
bool | xccdf_session::xccdf_session_set_product_cpe (struct xccdf_session *session, const char *product_cpe)
| Set custom product CPE name. More...
void | xccdf_session::xccdf_session_set_oval_results_export (struct xccdf_session *session, bool to_export_oval_results)
| Set whether the OVAL result files shall be exported. More...
void | xccdf_session::xccdf_session_set_check_engine_plugins_results_export (struct xccdf_session *session, bool to_export_results)
| Set that check engine plugin's result files shall be exported. More...
void | xccdf_session::xccdf_session_set_sce_results_export (struct xccdf_session *session, bool to_export_sce_results)
| Set that SCE reult files shall be exported. More...
void | xccdf_session::xccdf_session_set_oval_variables_export (struct xccdf_session *session, bool to_export_oval_variables)
| Set whether the OVAL variables files shall be exported. More...
bool | xccdf_session::xccdf_session_set_xccdf_export (struct xccdf_session *session, const char *xccdf_file)
| Set where to export XCCDF file. More...
bool | xccdf_session::xccdf_session_set_arf_export (struct xccdf_session *session, const char *arf_file)
| Set where to export ARF file. More...
bool | xccdf_session::xccdf_session_set_report_export (struct xccdf_session *session, const char *report_file)
| Set where to export HTML Report file. More...
bool | xccdf_session::xccdf_session_set_profile_id (struct xccdf_session *session, const char *profile_id)
| Select XCCDF Profile for evaluation. More...
const char * | xccdf_session::xccdf_session_get_profile_id (struct xccdf_session *session)
| Retrieves ID of the profile that we will evaluate with, or NULL. More...
struct ds_sds_index * | xccdf_session::xccdf_session_get_sds_idx (struct xccdf_session *session)
| Get Source DataStream index of the session. More...
int | xccdf_session::xccdf_session_load (struct xccdf_session *session)
| Load and parse all XCCDF structures needed to evaluate this session. More...
int | xccdf_session::xccdf_session_load_xccdf (struct xccdf_session *session)
| Load and parse XCCDF file. More...
int | xccdf_session::xccdf_session_load_cpe (struct xccdf_session *session)
| Load and parse CPE dictionaries. More...
int | xccdf_session::xccdf_session_load_oval (struct xccdf_session *session)
| Load and parse OVAL definitions files for the XCCDF session. More...
int | xccdf_session::xccdf_session_load_check_engine_plugin (struct xccdf_session *session, const char *plugin_name)
| Load extra check engine from a plugin of given name to the XCCDF session. More...
int | xccdf_session::xccdf_session_load_check_engine_plugins (struct xccdf_session *session)
| Load extra check engines (if any are available) to the XCCDF session. More...
int | xccdf_session::xccdf_session_load_tailoring (struct xccdf_session *session)
| Load Tailoring file (if applicable) to the XCCDF session. More...
int | xccdf_session::xccdf_session_evaluate (struct xccdf_session *session)
| Evaluate XCCDF Policy. More...
int | xccdf_session::xccdf_session_export_xccdf (struct xccdf_session *session)
| Export XCCDF file. More...
int | xccdf_session::xccdf_session_export_oval (struct xccdf_session *session)
| Export OVAL (result and variables) files. More...
int | xccdf_session::xccdf_session_export_check_engine_plugins (struct xccdf_session *session)
| Export results (if any) from any check engine plugins that are loaded. More...
int | xccdf_session::xccdf_session_export_sce (struct xccdf_session *session)
| Export SCE files (if enabled by xccdf_session_set_sce_results_export). More...
int | xccdf_session::xccdf_session_export_arf (struct xccdf_session *session)
| Export ARF (if enabled by xccdf_session_set_arf_export). More...
struct xccdf_policy_model * | xccdf_session::xccdf_session_get_policy_model (const struct xccdf_session *session)
| Get policy_model of the session. More...
struct xccdf_policy * | xccdf_session::xccdf_session_get_xccdf_policy (const struct xccdf_session *session)
| Get xccdf_policy of the session. More...
float | xccdf_session::xccdf_session_get_base_score (const struct xccdf_session *session)
| Get the base score of the latest XCCDF evaluation in the session. More...
unsigned int | xccdf_session::xccdf_session_get_oval_agents_count (const struct xccdf_session *session)
| Get count of OVAL agent sessions not used for CPE in the xccdf_session. More...
unsigned int | xccdf_session::xccdf_session_get_cpe_oval_agents_count (const struct xccdf_session *session)
| Get count of OVAL agent sessions for CPE in the xccdf_session. More...
bool | xccdf_session::xccdf_session_contains_fail_result (const struct xccdf_session *session)
| Query if the result of evaluation contains FAIL, ERROR, or UNKNOWN rule-result elements. More...
int | xccdf_session::xccdf_session_remediate (struct xccdf_session *session)
| Run XCCDF Remediation. More...
int | xccdf_session::xccdf_session_build_policy_from_testresult (struct xccdf_session *session, const char *testresult_id)
| Load xccdf:TestResult to the session from file and prepare session for remediation. More...

## Detailed Description

## Typedef Documentation

typedef void(* download_progress_calllback_t)(bool warning, const char *format,...)

Type of the function used to report progress of download.

Parameters

  warning | indicates whether the message is rather warning or notice
  format | printf-like format string

## Function Documentation

int xccdf_session_build_policy_from_testresult | ( | struct xccdf_session * | session,
|  | const char * | testresult_id
| ) |  |

Load xccdf:TestResult to the session from file and prepare session for remediation.

This function assumes that the session internals has the policy_model prepared, it calculates all the other internals which might be needed for remediation.

Parameters

  session | XCCDF Session
  testresult_id | ID of the TestResult element in the file (the NULL value stands for the last TestResult).

Returns
  zero on success.

bool xccdf_session_contains_fail_result | ( | const struct xccdf_session * | session | ) |

Query if the result of evaluation contains FAIL, ERROR, or UNKNOWN rule-result elements.

Parameters

  session | XCCDF Session

Returns
  Exists such rule-result r . r = FAIL | r = UNKNOWN | r = ERROR

int xccdf_session_evaluate | ( | struct xccdf_session * | session | ) |

Evaluate XCCDF Policy.

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_export_arf | ( | struct xccdf_session * | session | ) |

Export ARF (if enabled by xccdf_session_set_arf_export).

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_export_check_engine_plugins | ( | struct xccdf_session * | session | ) |

Export results (if any) from any check engine plugins that are loaded.

Only applicable if enabled by xccdf_session_set_check_engine_plugins_results_export).

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_export_oval | ( | struct xccdf_session * | session | ) |

Export OVAL (result and variables) files.

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_export_sce | ( | struct xccdf_session * | session | ) |

Export SCE files (if enabled by xccdf_session_set_sce_results_export).

Deprecated:
  Please use xccdf_session_export_check_engine_plugins instead.

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_export_xccdf | ( | struct xccdf_session * | session | ) |

Export XCCDF file.

Parameters

  session | XCCDF Session

Returns
  zero on success

void xccdf_session_free | ( | struct xccdf_session * | session | ) |

Destructor of xccdf_session.

Parameters

  session | to destroy.

float xccdf_session_get_base_score | ( | const struct xccdf_session * | session | ) |

Get the base score of the latest XCCDF evaluation in the session.

Parameters

  session | XCCDF Session

Returns
  the score

const char * xccdf_session_get_benchmark_id | ( | struct xccdf_session * | session | ) |

Retrieves the benchmark_id.

See Also
  xccdf_session_set_benchmark_id

const char * xccdf_session_get_component_id | ( | struct xccdf_session * | session | ) |

Retrieves the component id.

See Also
  xccdf_session_set_component_id

unsigned int xccdf_session_get_cpe_oval_agents_count | ( | const struct xccdf_session * | session | ) |

Get count of OVAL agent sessions for CPE in the xccdf_session.

CPE uses OVAL on demand, we do not count OVAL agents that were referenced but weren't used.

Parameters

  session | XCCDF Session

Returns
  number of OVAL agents for CPE.

const char * xccdf_session_get_datastream_id | ( | struct xccdf_session * | session | ) |

Retrieves the datastream id.

See Also
  xccdf_session_set_datastream_id

unsigned int xccdf_session_get_oval_agents_count | ( | const struct xccdf_session * | session | ) |

Get count of OVAL agent sessions not used for CPE in the xccdf_session.

Parameters

  session | XCCDF Session

Returns
  number of OVAL agents.

struct xccdf_policy_model * xccdf_session_get_policy_model | ( | const struct xccdf_session * | session | ) |

read

Get policy_model of the session.

The xccdf_session_load_xccdf shall be run before this to parse XCCDF file to the policy_model.

Parameters

  session | XCCDF Session

Returns
  XCCDF Policy Model or NULL in case of failure.

const char * xccdf_session_get_profile_id | ( | struct xccdf_session * | session | ) |

Retrieves ID of the profile that we will evaluate with, or NULL.

Parameters

  session | XCCDF Session

struct ds_sds_index * xccdf_session_get_sds_idx | ( | struct xccdf_session * | session | ) |

read

Get Source DataStream index of the session.

Warning
  This is applicable only on sessions which are SDS. NULL is returned otherwise.

Returns
  sds index

Warning
  This is applicable only on sessions which are SDS.

Returns
  sds index

struct xccdf_policy * xccdf_session_get_xccdf_policy | ( | const struct xccdf_session * | session | ) |

read

Get xccdf_policy of the session.

Parameters

  session | XCCDF Session

Returns
  XCCDF Policy or NULL in case of failure.

bool xccdf_session_is_sds | ( | const struct xccdf_session * | session | ) |

Query if the session is based on Source DataStream.

Parameters

  session | XCCDF Session

Returns
  true if the session is based on Source Datastream

int xccdf_session_load | ( | struct xccdf_session * | session | ) |

Load and parse all XCCDF structures needed to evaluate this session.

This is only a placeholder for load_xccdf, load_cpe, load_oval and load_check_engine_plugins functions.

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_load_check_engine_plugin | ( | struct xccdf_session * | session,
|  | const char * | plugin_name
| ) |  |

Load extra check engine from a plugin of given name to the XCCDF session.

Extra check engines are in loadable shared objects. This function is designed to be called !after! xccdf_session_load has been called. XCCDF has to have already been loaded for this to work because the callbacks are registered as part of this function!

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_load_check_engine_plugins | ( | struct xccdf_session * | session | ) |

Load extra check engines (if any are available) to the XCCDF session.

Extra check engines are in loadable shared objects and this function searches if any such are available and loads them if they are.

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_load_cpe | ( | struct xccdf_session * | session | ) |

Load and parse CPE dictionaries.

Function xccdf_session_set_user_cpe might be called before this to set custom CPE dictionary.

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_load_oval | ( | struct xccdf_session * | session | ) |

Load and parse OVAL definitions files for the XCCDF session.

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_load_sce | ( | struct xccdf_session * | session | ) |

Deprecated:
  SCE is no longer part of the main openscap library, use xccdf_session_load_check_engine_plugins instead.

int xccdf_session_load_tailoring | ( | struct xccdf_session * | session | ) |

Load Tailoring file (if applicable) to the XCCDF session.

Parameters

  session | XCCDF Session

Returns
  zero on success

int xccdf_session_load_xccdf | ( | struct xccdf_session * | session | ) |

Load and parse XCCDF file.

If the file upon which is based this session is Source DataStream use functions xccdf_session_set_datastream_id and xccdf_session_set_component_id to select particular component within that DataStream to parse. This function is reentrant meaning that it allows user to change i.e. component_id and load_xccdf again in the very same session. However in such case, previous xccdf structures will be deallocated from session and pointers to it become invalid.

Parameters

  session | XCCDF Session

Returns
  zero on success

struct xccdf_session * xccdf_session_new | ( | const char * | filename | ) |

read

Costructor of xccdf_session.

It attempts to recognize type of the filename.

Parameters

  filename | path to XCCDF or DS file.

Returns
  newly created xccdf_session.

Return values

  NULL | is returned in case of error. Details might be found through oscap_err_desc()

int xccdf_session_remediate | ( | struct xccdf_session * | session | ) |

Run XCCDF Remediation.

It uses XCCDF Policy and XCCDF TestResult from the session and modifies the TestResult. This also drops and recreate OVAL Agent Session, thus users are advised to run xccdf_session_export_oval first.

Parameters

  session | XCCDF Session

Returns
  zero on success

bool xccdf_session_set_arf_export | ( | struct xccdf_session * | session,
|  | const char * | arf_file
| ) |  |

Set where to export ARF file.

NULL value means to not export at all.

Parameters

  session | XCCDF Session
  arf_file | path to ARF file

Returns
  true on success

void xccdf_session_set_benchmark_id | ( | struct xccdf_session * | session,
|  | const char * | benchmark_id
| ) |  |

Sets requested benchmark_id for this session.

It is only used when no component_id and no datastream_id are requested. Benchmark ID selects the attribute of Benchmark element inside a component that is referenced with a checklist component-ref.

void xccdf_session_set_check_engine_plugins_results_export | ( | struct xccdf_session * | session,
|  | bool | to_export_results
| ) |  |

Set that check engine plugin's result files shall be exported.

Parameters

  session | XCCDF Session
  to_export_results | whether to export results from check engine plugins or not.

void xccdf_session_set_component_id | ( | struct xccdf_session * | session,
|  | const char * | component_id
| ) |  |

Set requested component_id for this session.

This component_id is later pased down to ds_sds_index_select_checklist to determine target component. This function is applicable only for sessions based on a DataStream.

Parameters

  session | XCCDF Session
  component_id | requested component_id for this session.

void xccdf_session_set_custom_oval_eval_fn | ( | struct xccdf_session * | session,
|  | xccdf_policy_engine_eval_fn | eval_fn
| ) |  |

Set custom OVAL eval function to register with each OVAL session.

This function shall be called before OVAL files are parsed.

Parameters

  session | XCCDF Session.
  eval_fn | Callback - pointer to function called by XCCDF Policy for each evaluated rule.

void xccdf_session_set_custom_oval_files | ( | struct xccdf_session * | session,
|  | char ** | oval_filenames
| ) |  |

Set custom oval files for this session.

Parameters

  session | XCCDF Session
  oval_filenames | - Array of paths to custom OVAL files. If the array is empty no OVAL file will be used for the session. If this parameter is NULL then OVAL files will be find automatically, as defined in XCCDF (which is default).

void xccdf_session_set_datastream_id | ( | struct xccdf_session * | session,
|  | const char * | datastream_id
| ) |  |

Set requested datastream_id for this session.

This datastream_id is later passed down to ds_sds_index_select_checklist to determine target component. This function is applicable only for sessions based on a DataStream.

Parameters

  session | XCCDF Session
  datastream_id | requested datastream_id for this session.

void xccdf_session_set_oval_results_export | ( | struct xccdf_session * | session,
|  | bool | to_export_oval_results
| ) |  |

Set whether the OVAL result files shall be exported.

Parameters

  session | XCCDF Session
  to_export_oval_results | whether to export results or not.

void xccdf_session_set_oval_variables_export | ( | struct xccdf_session * | session,
|  | bool | to_export_oval_variables
| ) |  |

Set whether the OVAL variables files shall be exported.

Parameters

  session | XCCDF Session
  to_export_oval_variables | whether to export results or not.

bool xccdf_session_set_product_cpe | ( | struct xccdf_session * | session,
|  | const char * | product_cpe
| ) |  |

Set custom product CPE name.

Parameters

  session | XCCDF Session.
  product_cpe | Name of the scanner product.

Returns
  true on success

bool xccdf_session_set_profile_id | ( | struct xccdf_session * | session,
|  | const char * | profile_id
| ) |  |

Select XCCDF Profile for evaluation.

Parameters

  session | XCCDF Session
  profile_id | ID of profile to set

Returns
  true on success

void xccdf_session_set_remote_resources | ( | struct xccdf_session * | session,
|  | bool | allowed,
|  | download_progress_calllback_t | callback
| ) |  |

Set properties of remote content.

Parameters

  session | XCCDF Session
  allowed | Whether is download od remote resources allowed in this session (defaults to false)
  callback | used to notify user about download proceeds. This might be safely set to NULL – ignoring user notification.

bool xccdf_session_set_report_export | ( | struct xccdf_session * | session,
|  | const char * | report_file
| ) |  |

Set where to export HTML Report file.

NULL value means to not export at all.

Parameters

  session | XCCDF Session
  report_file |

Returns
  true on success

void xccdf_session_set_sce_results_export | ( | struct xccdf_session * | session,
|  | bool | to_export_sce_results
| ) |  |

Set that SCE reult files shall be exported.

Parameters

  session | XCCDF Session
  to_export_sce_results | whether to export SCE results or not.

void xccdf_session_set_user_cpe | ( | struct xccdf_session * | session,
|  | const char * | user_cpe
| ) |  |

Set path to custom CPE dictionary for the session.

This function is applicable only before session loads. It has no effect if run afterwards.

Parameters

  session | XCCDF Session
  user_cpe | File path to user defined cpe dictionary.

void xccdf_session_set_user_tailoring_cid | ( | struct xccdf_session * | session,
|  | const char * | user_tailoring_cid
| ) |  |

Set ID of Tailoring component for the session.

This function is applicable only before session loads. It has no effect if run afterwards.

Parameters

  session | XCCDF Session
  user_tailoring_cid | ID of component with a tailoring file.

void xccdf_session_set_user_tailoring_file | ( | struct xccdf_session * | session,
|  | const char * | user_tailoring_file
| ) |  |

Set path to custom Tailoring file for the session.

This function is applicable only before session loads. It has no effect if run afterwards.

Parameters

  session | XCCDF Session
  user_tailoring_file | File path to user defined tailoring file.

void xccdf_session_set_validation | ( | struct xccdf_session * | session,
|  | bool | validate,
|  | bool | full_validation
| ) |  |

Set XSD validation level.

Parameters

  session | XCCDF Session
  validate | False value indicates to skip any XSD validation.
  full_validation | True value indicates that every possible step will be validated by XSD.

bool xccdf_session_set_xccdf_export | ( | struct xccdf_session * | session,
|  | const char * | xccdf_file
| ) |  |

Set where to export XCCDF file.

NULL value means to not export at all.

Parameters

  session | XCCDF Session
  xccdf_file | path to XCCDF file

Returns
  true on success