Skip to content

Commit c8fe6c6

Browse files
committed
Resolve unknown profile in tailoring
If someone provides a tailoring file and a profile ID that isn't present in the tailoring file, it will print an error message.
1 parent dff5eeb commit c8fe6c6

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

tests/oscap_info_profiles/test_list_rules.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,18 @@ grep -q "xccdf_com.example.www_rule_R2" $stdout
8181
:> $stdout
8282
rm -rf "$temp_dir"
8383

84+
# Test 7: --list-rules with tailoring referencing SDS via file: prefix, no cref,
85+
# providing the original profile instead of the customized one
86+
temp_dir="$(mktemp -d)"
87+
cp "$srcdir/test_reference_ds.xml" $temp_dir
88+
tailoring_sds_nf="test_tailoring_file_sds.xml"
89+
sed "s;TEMP_DIRECTORY_PLACEHOLDER;$temp_dir;" "$srcdir/$tailoring_sds_nf" > "$temp_dir/$tailoring_sds_nf"
90+
$OSCAP info --profile "xccdf_com.example.www_profile_P1" --list-rules "$temp_dir/$tailoring_sds_nf" > $stdout 2> $stderr
91+
[[ -f $stdout ]]; [[ ! -s $stdout ]]; :> $stdout
92+
grep -q "Profile 'xccdf_com.example.www_profile_P1' not found in the tailoring file. Provide the customized profile ID. Get available profiles using:" "$stderr"
93+
grep -q "$ oscap info $temp_dir/$tailoring_sds_nf" "$stderr"
94+
[[ "$(wc -l < $stderr)" -eq 2 ]]
95+
:> $stderr
96+
rm -rf "$temp_dir"
97+
8498
rm -f $stdout $stderr

utils/oscap-info.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,11 @@ static int app_info(const struct oscap_action *action)
10061006
}
10071007
xccdf_policy_model_set_tailoring(policy_model, tailoring);
10081008
const char *profile_id = tailoring_get_profile_or_report_multiple_ids(tailoring, action->profile, action->file);
1009-
if (profile_id != NULL) {
1009+
if (profile_id == NULL) {
1010+
fprintf(stderr,
1011+
"Profile '%s' not found in the tailoring file. Provide the customized profile ID. "
1012+
"Get available profiles using:\n$ oscap info %s\n", action->profile, action->file);
1013+
} else {
10101014
if (action->list_rules) {
10111015
_print_rules_for_profile(policy_model, profile_id);
10121016
} else {

0 commit comments

Comments
 (0)