Skip to content

New oscap info option to inspect rules via command line - #2486

Open
aje220 wants to merge 12 commits into
OpenSCAP:mainfrom
aje220:info_item_detail
Open

aje220 wants to merge 12 commits into
OpenSCAP:mainfrom
aje220:info_item_detail

Conversation

@aje220

@aje220 aje220 commented Nov 15, 2026

Copy link
Copy Markdown

Hello all,

Features added in this pull request:

A new --rule option for oscap info, this command line option (for a specified rule) prints:

  • Rule title and severity
  • Description
  • Rationale
  • Warnings
  • Fixtexts
  • Checktexts

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.xml

Let me know what you think!
Thanks

Alex

@sonarqubecloud

Copy link
Copy Markdown

@jan-cerny jan-cerny self-assigned this Dec 2, 2026

@jan-cerny jan-cerny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread utils/oscap-info.c
}

} else if (action->rule_id) {
const struct xccdf_item *rule_item = xccdf_benchmark_get_item(bench, action->rule_id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread utils/oscap-info.c
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread utils/oscap-info.c
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread utils/oscap-info.c
static const char* _severity_to_string(xccdf_level_t severity){

switch (severity) {
case XCCDF_LOW:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the informational severity. Add XCCDF_INFO.

Comment thread utils/oscap-info.c
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dtto for rationale, the text needs to be processed to remove child tags but not their text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants