|
|
c5477d |
From 03734db97a920a742375ad162b95d08b78866036 Mon Sep 17 00:00:00 2001
|
|
|
c5477d |
From: Vratislav Podzimek <vpodzime@redhat.com>
|
|
|
c5477d |
Date: Tue, 13 Sep 2016 17:23:37 +0200
|
|
|
c5477d |
Subject: [PATCH] Properly handle tailoring files for datastreams
|
|
|
c5477d |
|
|
|
c5477d |
We need to load the tailoring file and iterate over tailoring profiles like we
|
|
|
c5477d |
do for Benchmark+tailoring.
|
|
|
c5477d |
|
|
|
c5477d |
Resolves: rhbz#1364929
|
|
|
c5477d |
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
|
|
|
c5477d |
---
|
|
|
c5477d |
org_fedora_oscap/content_handling.py | 25 +++++++++++++++++++++----
|
|
|
c5477d |
1 file changed, 21 insertions(+), 4 deletions(-)
|
|
|
c5477d |
|
|
|
c5477d |
diff --git a/org_fedora_oscap/content_handling.py b/org_fedora_oscap/content_handling.py
|
|
|
c5477d |
index 0921ad9..fa4266b 100644
|
|
|
c5477d |
--- a/org_fedora_oscap/content_handling.py
|
|
|
c5477d |
+++ b/org_fedora_oscap/content_handling.py
|
|
|
c5477d |
@@ -151,6 +151,9 @@ class DataStreamHandler(object):
|
|
|
c5477d |
# is used to speed up getting lists of profiles
|
|
|
c5477d |
self._profiles_cache = dict()
|
|
|
c5477d |
|
|
|
c5477d |
+ # store the tailoring file path (if any) for later use
|
|
|
c5477d |
+ self._tailoring_file_path = tailoring_file_path
|
|
|
c5477d |
+
|
|
|
c5477d |
if not os.path.exists(dsc_file_path):
|
|
|
c5477d |
msg = "Invalid file path: '%s'" % dsc_file_path
|
|
|
c5477d |
raise DataStreamHandlingError(msg)
|
|
|
c5477d |
@@ -165,10 +168,6 @@ class DataStreamHandler(object):
|
|
|
c5477d |
if OSCAP.xccdf_session_load(self._session) != 0:
|
|
|
c5477d |
raise DataStreamHandlingError(OSCAP.oscap_err_desc())
|
|
|
c5477d |
|
|
|
c5477d |
- if tailoring_file_path:
|
|
|
c5477d |
- OSCAP.xccdf_session_set_user_tailoring_file(self._session,
|
|
|
c5477d |
- tailoring_file_path)
|
|
|
c5477d |
-
|
|
|
c5477d |
if not OSCAP.xccdf_session_is_sds(self._session):
|
|
|
c5477d |
msg = "'%s' is not a data stream collection" % dsc_file_path
|
|
|
c5477d |
raise DataStreamHandlingError(msg)
|
|
|
c5477d |
@@ -282,6 +281,11 @@ class DataStreamHandler(object):
|
|
|
c5477d |
|
|
|
c5477d |
OSCAP.xccdf_session_set_datastream_id(self._session, data_stream_id)
|
|
|
c5477d |
OSCAP.xccdf_session_set_component_id(self._session, checklist_id)
|
|
|
c5477d |
+
|
|
|
c5477d |
+ if self._tailoring_file_path:
|
|
|
c5477d |
+ OSCAP.xccdf_session_set_user_tailoring_file(self._session,
|
|
|
c5477d |
+ self._tailoring_file_path)
|
|
|
c5477d |
+
|
|
|
c5477d |
if OSCAP.xccdf_session_load(self._session) != 0:
|
|
|
c5477d |
raise DataStreamHandlingError(OSCAP.oscap_err_desc())
|
|
|
c5477d |
|
|
|
c5477d |
@@ -305,6 +309,19 @@ class DataStreamHandler(object):
|
|
|
c5477d |
|
|
|
c5477d |
profiles.append(info)
|
|
|
c5477d |
|
|
|
c5477d |
+ if self._tailoring_file_path:
|
|
|
c5477d |
+ tailoring = OSCAP.xccdf_policy_model_get_tailoring(policy_model)
|
|
|
c5477d |
+ profile_itr = OSCAP.xccdf_tailoring_get_profiles(tailoring)
|
|
|
c5477d |
+ while OSCAP.xccdf_profile_iterator_has_more(profile_itr):
|
|
|
c5477d |
+ profile = OSCAP.xccdf_profile_iterator_next(profile_itr)
|
|
|
c5477d |
+
|
|
|
c5477d |
+ id_ = OSCAP.xccdf_profile_get_id(profile)
|
|
|
c5477d |
+ title = oscap_text_itr_get_text(OSCAP.xccdf_profile_get_title(profile))
|
|
|
c5477d |
+ desc = oscap_text_itr_get_text(OSCAP.xccdf_profile_get_description(profile))
|
|
|
c5477d |
+ info = ProfileInfo(id_, title, desc)
|
|
|
c5477d |
+
|
|
|
c5477d |
+ profiles.append(info)
|
|
|
c5477d |
+
|
|
|
c5477d |
OSCAP.xccdf_profile_iterator_free(profile_itr)
|
|
|
c5477d |
|
|
|
c5477d |
# cache the result
|
|
|
c5477d |
--
|
|
|
c5477d |
2.7.4
|
|
|
c5477d |
|