Skip to content

Commit e0baa0e

Browse files
authored
Merge pull request #2020 from 0intro/session-result-reset
Implement xccdf_session_result_reset function in XCCDF session API
2 parents 1c8f16d + 194995d commit e0baa0e

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

src/OVAL/oval_agent.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,21 @@ int oval_agent_reset_session(oval_agent_session_t * ag_sess) {
255255
return 0;
256256
}
257257

258+
void oval_agent_reset_syschar(oval_agent_session_t * ag_sess) {
259+
oval_syschar_model_reset(ag_sess->sys_model);
260+
}
261+
262+
void oval_agent_reset_results(oval_agent_session_t * ag_sess) {
263+
#if defined(OVAL_PROBES_ENABLED)
264+
if (ag_sess != NULL) {
265+
oval_results_model_free(ag_sess->res_model);
266+
ag_sess->res_model = oval_results_model_new_with_probe_session(
267+
ag_sess->def_model, ag_sess->sys_models, ag_sess->psess);
268+
oval_probe_session_reinit(ag_sess->psess, ag_sess->sys_model);
269+
}
270+
#endif
271+
}
272+
258273
int oval_agent_abort_session(oval_agent_session_t *ag_sess)
259274
{
260275
if (ag_sess == NULL) {

src/OVAL/public/oval_agent_api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ OSCAP_API struct oval_result_definition * oval_agent_get_result_definition(oval_
9696
*/
9797
OSCAP_API int oval_agent_reset_session(oval_agent_session_t * ag_sess);
9898

99+
/**
100+
* Clean system characteristics that were generated in this agent session
101+
*/
102+
OSCAP_API void oval_agent_reset_syschar(oval_agent_session_t * ag_sess);
103+
104+
/**
105+
* Clean results that were generated in this agent session
106+
*/
107+
OSCAP_API void oval_agent_reset_results(oval_agent_session_t * ag_sess);
108+
99109
/**
100110
* Abort a running probe session
101111
*/

src/XCCDF/public/xccdf_session.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ OSCAP_API struct xccdf_session *xccdf_session_new_from_source(struct oscap_sourc
8181
*/
8282
OSCAP_API void xccdf_session_free(struct xccdf_session *session);
8383

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+
8492
/**
8593
* Retrieves the filename the session was created with
8694
* @memberof xccdf_session

src/XCCDF/xccdf_session.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,40 @@ void xccdf_session_free(struct xccdf_session *session)
362362
free(session);
363363
}
364364

365+
static void _xccdf_session_reset_oval_agents_syschar(struct xccdf_session *session)
366+
{
367+
if (session->oval.agents != NULL) {
368+
for (int i=0; session->oval.agents[i]; i++) {
369+
oval_agent_reset_syschar(session->oval.agents[i]);
370+
}
371+
}
372+
}
373+
374+
static void _xccdf_session_reset_oval_agents_results(struct xccdf_session *session)
375+
{
376+
if (session->oval.agents != NULL) {
377+
for (int i=0; session->oval.agents[i]; i++) {
378+
oval_agent_reset_results(session->oval.agents[i]);
379+
}
380+
}
381+
}
382+
383+
void xccdf_session_result_reset(struct xccdf_session *session)
384+
{
385+
if (session->xccdf.policy_model != NULL) {
386+
oscap_list_free(session->xccdf.policy_model->policies, (oscap_destruct_func) xccdf_policy_free);
387+
session->xccdf.policy_model->policies = oscap_list_new();
388+
}
389+
390+
oscap_list_free(session->rules, (oscap_destruct_func) free);
391+
session->rules = oscap_list_new();
392+
oscap_list_free(session->skip_rules, (oscap_destruct_func) free);
393+
session->skip_rules = oscap_list_new();
394+
395+
_xccdf_session_reset_oval_agents_syschar(session);
396+
_xccdf_session_reset_oval_agents_results(session);
397+
}
398+
365399
const char *xccdf_session_get_filename(const struct xccdf_session *session)
366400
{
367401
return oscap_source_readable_origin(session->source);

0 commit comments

Comments
 (0)