Skip to content

Commit 05a61f3

Browse files
Merge pull request #1290 from jan-cerny/details_always_in_report
Always show OVAL details in HTML report
2 parents 4ca85d1 + 1abbedf commit 05a61f3

File tree

4 files changed

+85
-56
lines changed

4 files changed

+85
-56
lines changed

src/OVAL/results/oval_resultSystem.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -426,30 +426,32 @@ xmlNode *oval_result_system_to_dom(struct oval_result_system * sys,
426426

427427
struct oval_smc *tstmap = oval_smc_new();
428428

429-
xmlNode *definitions_node = xmlNewTextChild(system_node, ns_results, BAD_CAST "definitions", NULL);
430429
struct oval_definition_model *definition_model = oval_results_model_get_definition_model(results_model);
431430
struct oval_definition_iterator *oval_definitions = oval_definition_model_get_definitions(definition_model);
432-
while(oval_definition_iterator_has_more(oval_definitions)) {
433-
struct oval_definition *oval_definition = oval_definition_iterator_next(oval_definitions);
434-
435-
oval_definition_class_t def_class = oval_definition_get_class(oval_definition);
436-
class_dirs = oval_directives_model_get_classdir(directives_model, def_class);
437-
directives = class_dirs ? class_dirs : def_dirs;
438-
439-
bool exported = false;
440-
struct oval_iterator *rslt_definitions_it = oval_smc_get_all_it(sys->definitions, oval_definition_get_id(oval_definition));
441-
if (rslt_definitions_it != NULL) {
442-
while (oval_collection_iterator_has_more(rslt_definitions_it)) {
443-
struct oval_result_definition *rslt_definition = oval_collection_iterator_next(rslt_definitions_it);
444-
_oval_result_definition_to_dom_based_on_directives(rslt_definition, directives, doc, definitions_node, tstmap);
445-
exported = true;
431+
if(oval_definition_iterator_has_more(oval_definitions)) {
432+
xmlNode *definitions_node = xmlNewTextChild(system_node, ns_results, BAD_CAST "definitions", NULL);
433+
while(oval_definition_iterator_has_more(oval_definitions)) {
434+
struct oval_definition *oval_definition = oval_definition_iterator_next(oval_definitions);
435+
436+
oval_definition_class_t def_class = oval_definition_get_class(oval_definition);
437+
class_dirs = oval_directives_model_get_classdir(directives_model, def_class);
438+
directives = class_dirs ? class_dirs : def_dirs;
439+
440+
bool exported = false;
441+
struct oval_iterator *rslt_definitions_it = oval_smc_get_all_it(sys->definitions, oval_definition_get_id(oval_definition));
442+
if (rslt_definitions_it != NULL) {
443+
while (oval_collection_iterator_has_more(rslt_definitions_it)) {
444+
struct oval_result_definition *rslt_definition = oval_collection_iterator_next(rslt_definitions_it);
445+
_oval_result_definition_to_dom_based_on_directives(rslt_definition, directives, doc, definitions_node, tstmap);
446+
exported = true;
447+
}
448+
oval_collection_iterator_free(rslt_definitions_it);
446449
}
447-
oval_collection_iterator_free(rslt_definitions_it);
448-
}
449-
if (!exported) {
450-
struct oval_result_definition *rslt_definition = oval_result_system_get_new_definition(sys, oval_definition, 1);
451-
if (rslt_definition) {
452-
_oval_result_definition_to_dom_based_on_directives(rslt_definition, directives, doc, definitions_node, tstmap);
450+
if (!exported) {
451+
struct oval_result_definition *rslt_definition = oval_result_system_get_new_definition(sys, oval_definition, 1);
452+
if (rslt_definition) {
453+
_oval_result_definition_to_dom_based_on_directives(rslt_definition, directives, doc, definitions_node, tstmap);
454+
}
453455
}
454456
}
455457
}

src/XCCDF/xccdf_session.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,18 +1325,13 @@ int xccdf_session_export_xccdf(struct xccdf_session *session)
13251325
if (session->export.report_file == NULL)
13261326
return 0;
13271327

1328-
struct oscap_source* results = session->xccdf.result_source;
1329-
struct oscap_source* arf = NULL;
1330-
if (session->export.oval_results || session->export.arf_file) {
1331-
arf = xccdf_session_create_arf_source(session);
1332-
if (arf == NULL) {
1333-
return 1;
1334-
}
1335-
results = arf;
1328+
struct oscap_source* arf = xccdf_session_create_arf_source(session);
1329+
if (arf == NULL) {
1330+
return 1;
13361331
}
13371332

13381333
/* generate report */
1339-
_xccdf_gen_report(results,
1334+
_xccdf_gen_report(arf,
13401335
xccdf_result_get_id(session->xccdf.result),
13411336
session->export.report_file,
13421337
"",
@@ -1530,21 +1525,19 @@ static int _build_oval_result_sources(struct xccdf_session *session)
15301525

15311526
int xccdf_session_export_oval(struct xccdf_session *session)
15321527
{
1533-
if (session->export.oval_results || session->export.arf_file != NULL) {
1534-
if (_build_oval_result_sources(session) != 0) {
1528+
if (_build_oval_result_sources(session) != 0) {
1529+
return 1;
1530+
}
1531+
struct oscap_htable_iterator *hit = oscap_htable_iterator_new(session->oval.result_sources);
1532+
while (oscap_htable_iterator_has_more(hit)) {
1533+
struct oscap_source *source = oscap_htable_iterator_next_value(hit);
1534+
if (oscap_source_save_as(source, NULL) != 0) {
1535+
oscap_seterr(OSCAP_EFAMILY_OSCAP, "Could not save file: %s", oscap_source_readable_origin(source));
1536+
oscap_htable_iterator_free(hit);
15351537
return 1;
15361538
}
1537-
struct oscap_htable_iterator *hit = oscap_htable_iterator_new(session->oval.result_sources);
1538-
while (oscap_htable_iterator_has_more(hit)) {
1539-
struct oscap_source *source = oscap_htable_iterator_next_value(hit);
1540-
if (oscap_source_save_as(source, NULL) != 0) {
1541-
oscap_seterr(OSCAP_EFAMILY_OSCAP, "Could not save file: %s", oscap_source_readable_origin(source));
1542-
oscap_htable_iterator_free(hit);
1543-
return 1;
1544-
}
1545-
}
1546-
oscap_htable_iterator_free(hit);
15471539
}
1540+
oscap_htable_iterator_free(hit);
15481541

15491542
/* Export variables */
15501543
if (session->export.oval_variables && session->oval.agents != NULL) {

tests/oval_details/test_oval_details.sh

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,39 @@ output_dir=`mktemp -d -t oval_details_XXXXXX`
1010

1111
# Test cases.
1212

13-
function test_oval_details {
13+
function test_oval_details_implicit {
14+
# Tests if OVAL Details are present in HTML report by default
15+
# without specifing --oval-results --results (new behavior)
16+
xccdffile=$srcdir/$1.xccdf.xml
17+
reportfile=$output_dir/$1.report.html
18+
resultfile="$1.result.xml"
19+
oval_resultfile="$1.oval.xml.result.xml"
20+
$OSCAP xccdf eval --report $reportfile $xccdffile
21+
[ -f $reportfile ]
22+
[ ! -f $resultfile ]
23+
[ ! -f $output_dir/$resultfile ]
24+
[ ! -f $oval_resultfile ]
25+
[ ! -f $output_dir/$oval_resultfile ]
26+
grep -i $2 $reportfile >/dev/null && grep -i $3 $reportfile >/dev/null
27+
rm $reportfile
28+
}
29+
30+
function test_oval_details_explicit {
31+
# Tests if OVAL details are present in HTML report when options
32+
# --oval-results and --results are explicitely specified
33+
# (backwards-compatible behavior)
1434
xccdffile=$srcdir/$1.xccdf.xml
1535
resultfile=$output_dir/$1.result.xml
1636
reportfile=$output_dir/$1.report.html
37+
oval_resultfile="$1.oval.xml.result.xml"
1738
$OSCAP xccdf eval --results $resultfile --oval-results --report $reportfile $xccdffile
1839
grep -i $2 $reportfile >/dev/null && grep -i $3 $reportfile >/dev/null
19-
rm "$1.oval.xml.result.xml"
40+
[ -f $reportfile ]
41+
[ -f $resultfile ]
42+
[ -f $oval_resultfile ]
43+
rm $reportfile
44+
rm $resultfile
45+
rm $oval_resultfile
2046
}
2147

2248
# Testing.
@@ -29,16 +55,24 @@ if ! [ -f foo.txt ] ; then
2955
cp $srcdir/foo.src.txt ./foo.txt
3056
fi
3157

32-
test_run "test_oval_details_file_object" test_oval_details file "path.*UID.*permissions" "/dev/null"
33-
test_run "test_oval_details_partition_object" test_oval_details partition "mount point.*device.*uuid" "/"
34-
test_run "test_oval_details_rpminfo_object" test_oval_details rpminfo "name.*release.*version" "rpm"
58+
test_run "test_oval_details_file_object_implicit" test_oval_details_implicit file "path.*UID.*permissions" "/dev/null"
59+
test_run "test_oval_details_file_object_explicit" test_oval_details_explicit file "path.*UID.*permissions" "/dev/null"
60+
test_run "test_oval_details_partition_object_implicit" test_oval_details_implicit partition "mount point.*device.*uuid" "/"
61+
test_run "test_oval_details_partition_object_explicit" test_oval_details_explicit partition "mount point.*device.*uuid" "/"
62+
test_run "test_oval_details_rpminfo_object_implicit" test_oval_details_implicit rpminfo "name.*release.*version" "rpm"
63+
test_run "test_oval_details_rpminfo_object_explicit" test_oval_details_explicit rpminfo "name.*release.*version" "rpm"
3564
if ! pidof systemd > /dev/null ; then
36-
test_run "test_oval_details_runlevel_object" test_oval_details runlevel "service name.*runlevel" "smartd"
65+
test_run "test_oval_details_runlevel_object_implicit" test_oval_details_implicit runlevel "service name.*runlevel" "smartd"
66+
test_run "test_oval_details_runlevel_object_explicit" test_oval_details_explicit runlevel "service name.*runlevel" "smartd"
3767
fi
38-
test_run "test_oval_details_sysctl_object" test_oval_details sysctl "name.*value" "net\.ipv4\.ip_forward"
39-
test_run "test_oval_details_textfilecontent54_object" test_oval_details textfilecontent54 "path.*content" "foo\.txt.*Hello"
40-
test_run "test_oval_details_variable_object" test_oval_details variable "var ref.*value" "oval:x:var:1.*42"
41-
test_run "test_oval_details_xmlfilecontent_object" test_oval_details xmlfilecontent "filepath.*xpath.*value of" "countries\.xml.*London"
68+
test_run "test_oval_details_sysctl_object_implicit" test_oval_details_implicit sysctl "name.*value" "net\.ipv4\.ip_forward"
69+
test_run "test_oval_details_sysctl_object_explicit" test_oval_details_explicit sysctl "name.*value" "net\.ipv4\.ip_forward"
70+
test_run "test_oval_details_textfilecontent54_object_implicit" test_oval_details_implicit textfilecontent54 "path.*content" "foo\.txt.*Hello"
71+
test_run "test_oval_details_textfilecontent54_object_explicit" test_oval_details_explicit textfilecontent54 "path.*content" "foo\.txt.*Hello"
72+
test_run "test_oval_details_variable_object_implicit" test_oval_details_implicit variable "var ref.*value" "oval:x:var:1.*42"
73+
test_run "test_oval_details_variable_object_explicit" test_oval_details_explicit variable "var ref.*value" "oval:x:var:1.*42"
74+
test_run "test_oval_details_xmlfilecontent_object_implicit" test_oval_details_implicit xmlfilecontent "filepath.*xpath.*value of" "countries\.xml.*London"
75+
test_run "test_oval_details_xmlfilecontent_object_explicit" test_oval_details_explicit xmlfilecontent "filepath.*xpath.*value of" "countries\.xml.*London"
4276

4377
rm -rf $output_dir
4478
rm -f ./foo.txt ./countries.xml

utils/oscap.8

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ Don't provide system characteristics in OVAL/ARF result files.
147147
.TP
148148
\fB\-\-report FILE\fR
149149
.RS
150-
Write HTML report into FILE. Add \fB\-\-oval-results\fR to enable detailed information in the report.
150+
Write HTML report into FILE.
151151
.RE
152152
.TP
153153
\fB\-\-oval-results\fR
154154
.RS
155-
Generate OVAL Result file for each OVAL session used for evaluation. File with name '\fIoriginal-oval-definitions-filename\fR.result.xml' will be generated for each referenced OVAL file in current working directory. This option (in conjunction with the \fB\-\-report\fR option) also enables inclusion of additional OVAL information in the XCCDF report. To change the directory where OVAL files are generated change the CWD using the `cd` command.
155+
Generate OVAL Result file for each OVAL session used for evaluation. File with name '\fIoriginal-oval-definitions-filename\fR.result.xml' will be generated for each referenced OVAL file in current working directory. To change the directory where OVAL files are generated change the CWD using the `cd` command.
156156
.RE
157157
.TP
158158
\fB\-\-check-engine-results\fR
@@ -238,12 +238,12 @@ This option should be used to generate results for DISA STIG Viewer older than 2
238238
.TP
239239
\fB\-\-report FILE\fR
240240
.RS
241-
Write HTML report into FILE. Add \fB\-\-oval-results\fR to enable detailed information in the report.
241+
Write HTML report into FILE.
242242
.RE
243243
.TP
244244
\fB\-\-oval-results\fR
245245
.RS
246-
Generate OVAL Result file for each OVAL session used for evaluation. File with name '\fIoriginal-oval-definitions-filename\fR.result.xml' will be generated for each referenced OVAL file. This option (with conjunction with the \fB\-\-report\fR option) also enables inclusion of additional OVAL information in the XCCDF report.
246+
Generate OVAL Result file for each OVAL session used for evaluation. File with name '\fIoriginal-oval-definitions-filename\fR.result.xml' will be generated for each referenced OVAL file.
247247
.RE
248248
.TP
249249
\fB\-\-check-engine-results\fR

0 commit comments

Comments
 (0)