Skip to content

Commit 26b4b81

Browse files
committed
Clarify the '--local-files' option
- Document that the '--local-files' option works only with SCAP 1.3 source data streams. - Add a warning if users use '--local-files' with different versions of SCAP source data streams. - Add a simple upstream test for the added warning. Resolves: https://issues.redhat.com/browse/RHEL-74343
1 parent 061e9ca commit 26b4b81

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

docs/manual/manual.adoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,11 +1655,13 @@ Also, OpenSCAP uses `libcurl` library which also can be configured using environ
16551655

16561656
== Using external or remote resources
16571657

1658-
Some SCAP content references external resources. For example SCAP Security Guide
1659-
uses external OVAL file to check that the system is up to date and has no known
1658+
Some SCAP content references external resources. For example, older versions of SCAP Security Guide (prior to version 0.1.73)
1659+
used external OVAL file to check that the system is up to date and has no known
16601660
security vulnerabilities. However, other content can use external resources for
16611661
other purposes.
16621662

1663+
NOTE: Starting with version 0.1.73, SCAP Security Guide content doesn't use external resources anymore.
1664+
16631665
When you are evaluating SCAP content with external resources the `oscap` tool
16641666
will warn you:
16651667

@@ -1708,6 +1710,8 @@ $ wget -O ~/scap-files/security-data-oval-com.redhat.rhsa-RHEL8.xml https://www.
17081710
$ oscap xccdf eval --local-files ~/scap-files --profile ospp ssg-rhel8-ds.xml
17091711
----
17101712

1713+
NOTE: The `--local-files` option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
1714+
17111715
== Practical Examples
17121716
This section demonstrates practical usage of certain security content provided
17131717
for Red Hat products.
@@ -2297,4 +2301,5 @@ You can find the ID of the customized profile with `oscap info <your_tailoring_f
22972301

22982302
Yes, it's possible, you can download the file on other computer that is connected to the internet and then copy the file to the system where you run `oscap`.
22992303
Instead of the `--fetch-remote-resources` option you will use the `--local-files` option.
2304+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
23002305
For more information, please refer to section <<_using_external_or_remote_resources,Using external or remote resources>>.

src/DS/ds_sds_session.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,25 @@ void ds_sds_session_configure_remote_resources(struct ds_sds_session *session, b
343343
session->fetch_remote_resources = allowed;
344344
session->local_files = local_files;
345345
session->progress = (callback != NULL) ? callback : download_progress_empty_calllback;
346+
if (local_files != NULL) {
347+
struct ds_sds_index *idx = ds_sds_session_get_sds_idx(session);
348+
struct ds_stream_index_iterator *streams = ds_sds_index_get_streams(idx);
349+
while (ds_stream_index_iterator_has_more(streams)) {
350+
struct ds_stream_index *stream = ds_stream_index_iterator_next(streams);
351+
const char *version = ds_stream_index_get_version(stream);
352+
if (strcmp(version, "1.3")) {
353+
ds_sds_session_remote_resources_progress(session)(
354+
true,
355+
"WARNING: The '--local-files' option can be used only with "
356+
"SCAP 1.3 source data streams, but the provided data stream "
357+
"is version '%s'. No local files will be used.\n",
358+
version);
359+
break;
360+
}
361+
362+
}
363+
ds_stream_index_iterator_free(streams);
364+
}
346365
}
347366

348367
void ds_sds_session_set_remote_resources(struct ds_sds_session *session, bool allowed, download_progress_calllback_t callback)

tests/DS/test_ds_use_local_remote_resources.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Jan Černý <jcerny@redhat.com>
55

66
set -e -o pipefail
7-
set -x
87

98
. $builddir/tests/test_common.sh
109

@@ -81,3 +80,13 @@ assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-pass2"]/r
8180
popd
8281
rm -f "$result" "$stderr"
8382
rm -rf "$tmpdir1" "$tmpdir2" "$tmpdir3"
83+
84+
85+
# test that a warning is shown when --local-files is provided with SCAP 1.2 DS
86+
result=$(mktemp)
87+
stderr=$(mktemp)
88+
tmpdir=$(mktemp -d)
89+
$OSCAP xccdf eval --local-files "$tmpdir" --profile "$PROFILE" --results "$result" "${srcdir}/ds_continue_without_remote_resources/remote_content_1.2.ds.xml" 2>"$stderr" || ret=$?
90+
[ "$ret" = 2 ]
91+
grep -q "WARNING: The '--local-files' option can be used only with SCAP 1.3 source data streams, but the provided data stream is version '1.2'. No local files will be used." "$stderr"
92+
rm -rf "$result" "$stderr" "$tmpdir"

utils/oscap.8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Allow download of remote components referenced from data stream.
7575
\fB\-\-local-files DIRECTORY\fR
7676
.RS
7777
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
78+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
7879
.RE
7980
.TP
8081
\fB\-\-profile PROFILE\fR
@@ -225,6 +226,7 @@ Allow download of remote OVAL content referenced from XCCDF by check-content-ref
225226
\fB\-\-local-files DIRECTORY\fR
226227
.RS
227228
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
229+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
228230
.RE
229231
.TP
230232
\fB\-\-remediate\fR
@@ -255,6 +257,7 @@ Allow download of remote OVAL content referenced from XCCDF by check-content-ref
255257
\fB\-\-local-files DIRECTORY\fR
256258
.RS
257259
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
260+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
258261
.RE
259262
.TP
260263
\fB\-\-cpe CPE_FILE\fR
@@ -342,6 +345,7 @@ Allow download of remote OVAL content referenced from XCCDF by check-content-ref
342345
\fB\-\-local-files DIRECTORY\fR
343346
.RS
344347
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
348+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
345349
.RE
346350
.TP
347351
\fB\-\-skip-valid\fR, \fB\-\-skip-validation\fR
@@ -518,6 +522,7 @@ Allow download of remote components referenced from data stream.
518522
.TP
519523
\fB\-\-local-files DIRECTORY\fR
520524
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
525+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
521526
.RE
522527

523528
.TP
@@ -682,6 +687,7 @@ Allow download of remote components referenced from data stream.
682687
.TP
683688
\fB\-\-local-files DIRECTORY\fR
684689
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
690+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
685691
.RE
686692
.TP
687693
.B \fBsds-validate\fR SOURCE_DS

0 commit comments

Comments
 (0)