Skip to content

Commit

Permalink
Don't alter result and benchmark when policy is being exported. Fixes…
Browse files Browse the repository at this point in the history
… scap-workbench tailoring bug.
  • Loading branch information
Martin Preisler authored and pvrabec committed Feb 7, 2012
1 parent 92e3da3 commit 2aae78b
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions swig/openscap_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,25 +674,34 @@ def policy_export(self, result=None, title=None, filename=None, prefix=None, pat
"""Export all files for given policy.
"""

if self.object != "xccdf_policy": raise TypeError("Wrong call of \"export\" function. Should be xccdf_policy (have %s)" %(self.object,))

result.benchmark_uri = path or "benchmark.xml"
if self.object != "xccdf_policy":
raise TypeError("Wrong call of \"export\" function. Should be xccdf_policy (have %s)" %(self.object,))

# FIXME: We clone both benchmark and the result to avoid changing them when just export is requested
# Although this is the right behavior, it is potentially wasteful, result.clone() and benchmark.clone()
# could potentially take a lot of time to complete.
# A better solution would be to add the result, export and then remove the result
# (with appropriate exception safety of course) or even better, allow export with custom result list.

result_clone = result.clone()
result_clone.benchmark_uri = path or "benchmark.xml"
o_title = common.text()
o_title.text = title
result.title = o_title

dirname = os.path.dirname(filename)

OSCAP.xccdf_result_fill_sysinfo(result.instance)
result_clone.title = o_title
result_clone.fill_sysinfo()

files = [filename]

for model in self.model.benchmark.models:
result.score = self.score(result, model.system)
benchmark_clone = self.model.benchmark.clone()

self.model.benchmark.result = result.clone()
for model in benchmark_clone.models:
result_clone.score = self.score(result_clone, model.system)

OSCAP.xccdf_benchmark_export(self.model.benchmark.instance, filename)
benchmark_clone.add_result(result_clone)

benchmark_clone.export(filename)

dirname = os.path.dirname(filename)
for path in sessions.keys():
sess = sessions[path]
rmodel = oval.agent_get_results_model(sess)
Expand Down

0 comments on commit 2aae78b

Please sign in to comment.