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