Skip to content

Commit

Permalink
Merge pull request #2020 from 0intro/session-result-reset
Browse files Browse the repository at this point in the history
Implement xccdf_session_result_reset function in XCCDF session API
  • Loading branch information
jan-cerny authored Sep 25, 2023
2 parents 1c8f16d + 194995d commit e0baa0e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/OVAL/oval_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ int oval_agent_reset_session(oval_agent_session_t * ag_sess) {
return 0;
}

void oval_agent_reset_syschar(oval_agent_session_t * ag_sess) {
oval_syschar_model_reset(ag_sess->sys_model);
}

void oval_agent_reset_results(oval_agent_session_t * ag_sess) {
#if defined(OVAL_PROBES_ENABLED)
if (ag_sess != NULL) {
oval_results_model_free(ag_sess->res_model);
ag_sess->res_model = oval_results_model_new_with_probe_session(
ag_sess->def_model, ag_sess->sys_models, ag_sess->psess);
oval_probe_session_reinit(ag_sess->psess, ag_sess->sys_model);
}
#endif
}

int oval_agent_abort_session(oval_agent_session_t *ag_sess)
{
if (ag_sess == NULL) {
Expand Down
10 changes: 10 additions & 0 deletions src/OVAL/public/oval_agent_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ OSCAP_API struct oval_result_definition * oval_agent_get_result_definition(oval_
*/
OSCAP_API int oval_agent_reset_session(oval_agent_session_t * ag_sess);

/**
* Clean system characteristics that were generated in this agent session
*/
OSCAP_API void oval_agent_reset_syschar(oval_agent_session_t * ag_sess);

/**
* Clean results that were generated in this agent session
*/
OSCAP_API void oval_agent_reset_results(oval_agent_session_t * ag_sess);

/**
* Abort a running probe session
*/
Expand Down
8 changes: 8 additions & 0 deletions src/XCCDF/public/xccdf_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ OSCAP_API struct xccdf_session *xccdf_session_new_from_source(struct oscap_sourc
*/
OSCAP_API void xccdf_session_free(struct xccdf_session *session);

/**
* Reset xccdf_session results.
* This function resets XCCDF policies, session rules, skipped rules, OVAL system characteristics and OVAL results.
* @memberof xccdf_session
* @param session to reset results from.
*/
OSCAP_API void xccdf_session_result_reset(struct xccdf_session *session);

/**
* Retrieves the filename the session was created with
* @memberof xccdf_session
Expand Down
34 changes: 34 additions & 0 deletions src/XCCDF/xccdf_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,40 @@ void xccdf_session_free(struct xccdf_session *session)
free(session);
}

static void _xccdf_session_reset_oval_agents_syschar(struct xccdf_session *session)
{
if (session->oval.agents != NULL) {
for (int i=0; session->oval.agents[i]; i++) {
oval_agent_reset_syschar(session->oval.agents[i]);
}
}
}

static void _xccdf_session_reset_oval_agents_results(struct xccdf_session *session)
{
if (session->oval.agents != NULL) {
for (int i=0; session->oval.agents[i]; i++) {
oval_agent_reset_results(session->oval.agents[i]);
}
}
}

void xccdf_session_result_reset(struct xccdf_session *session)
{
if (session->xccdf.policy_model != NULL) {
oscap_list_free(session->xccdf.policy_model->policies, (oscap_destruct_func) xccdf_policy_free);
session->xccdf.policy_model->policies = oscap_list_new();
}

oscap_list_free(session->rules, (oscap_destruct_func) free);
session->rules = oscap_list_new();
oscap_list_free(session->skip_rules, (oscap_destruct_func) free);
session->skip_rules = oscap_list_new();

_xccdf_session_reset_oval_agents_syschar(session);
_xccdf_session_reset_oval_agents_results(session);
}

const char *xccdf_session_get_filename(const struct xccdf_session *session)
{
return oscap_source_readable_origin(session->source);
Expand Down

0 comments on commit e0baa0e

Please sign in to comment.