Repository navigation
Conversation
|
jan-cerny
left a comment
There was a problem hiding this comment.
This is a great feature idea. I think it's useful for many users who use oscap in terminal and don't have the easy access to the HTML guides.
| } | ||
|
|
||
| } else if (action->rule_id) { | ||
| const struct xccdf_item *rule_item = xccdf_benchmark_get_item(bench, action->rule_id); |
There was a problem hiding this comment.
Non-rule IDs cause a segmentation fault because xccdf_benchmark_get_item() also returns Values and Groups, but the result is passed to rule-specific getters without checking its type.
Reproduced by:
jcerny@jcerny-thinkpadt14gen4:~/git/openscap/build (pr/2486)$ ./oscap_wrapper info --rule xccdf_com.example.www_value_V1 ../tests/oscap_info_rules/test_tailoring_benchmark.xml
Document type: XCCDF Checklist
Title Value V1
Severity unknown
./oscap_wrapper: line 31: 90735 Segmentation fault (core dumped) "$b/run" "$b/utils/oscap" "$@"
Check for XCCDF_RULE before printing. The data-stream lookup at line 904 needs the same guard.
| struct oscap_text_iterator *description_it = xccdf_item_get_description(item); | ||
| struct oscap_text *oscap_description = oscap_textlist_get_preferred_text(description_it, NULL); | ||
| if (oscap_description !=NULL) { | ||
| const char *description = oscap_text_get_text(oscap_description); |
There was a problem hiding this comment.
This function returns the description element as-is. We need to remove the HTML/XHTML tags from the description text. Moreover, we need to resolve the substitutions of XCCDF Values (variables) to the text.
| struct oscap_string_iterator *warnings_it = oscap_stringlist_get_strings(warnings); | ||
| while (oscap_string_iterator_has_more(warnings_it)) { | ||
| const char *warning = oscap_string_iterator_next(warnings_it); | ||
| printf("\n\033[1mWarnings\033[0;0m\n--------\n%s\n", warning); |
There was a problem hiding this comment.
When there are multiple warnings in the rule (eg. in rule xccdf_org.ssgproject.content_rule_audit_rules_privileged_commands) it prints 2 headers "Warnings", one for each warning. Either print only a single header or print just "Warning" before each.
| static const char* _severity_to_string(xccdf_level_t severity){ | ||
|
|
||
| switch (severity) { | ||
| case XCCDF_LOW: |
There was a problem hiding this comment.
Missing the informational severity. Add XCCDF_INFO.
| struct oscap_text_iterator *rat_it = xccdf_item_get_rationale(item); | ||
| struct oscap_text *oscap_rationale = oscap_textlist_get_preferred_text(rat_it, NULL); | ||
| if (oscap_rationale != NULL) { | ||
| const char *rationale = oscap_text_get_text(oscap_rationale); |
There was a problem hiding this comment.
Dtto for rationale, the text needs to be processed to remove child tags but not their text.



Hello all,
Features added in this pull request:
A new
--ruleoption foroscap info, this command line option (for a specified rule) prints:I was inspired by my desire to have such a feature when troubleshooting openscap in headless environments.
Usage:
oscap info --rule [rule-id] [XCCDF-or-Datastream file]Example:
oscap info --rule xccdf_com.example.www_rule_R6 test_tailoring_benchmark.xmlLet me know what you think!
Thanks
Alex