Fixes bug #7948 --- src/secstate/main.py | 47 ++++++++++++++++++++++++++++------------------- 1 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/src/secstate/main.py b/src/secstate/main.py index 20a8eaf..707ddd0 100644 --- a/src/secstate/main.py +++ b/src/secstate/main.py @@ -280,8 +280,14 @@ class Secstate: if store_path == None: if self.content.has_key(benchmark.id): puppet_files = map(lambda x: os.path.join(self.config.get('secstate', 'puppet_dir'), x), puppet_files) - else: - puppet_files = map(lambda x: os.path.join(os.path.dirname(benchmark_file), x), puppet_files) + else: + puppet_files = map(lambda x: os.path.join(os.path.dirname(benchmark_file), x), puppet_files) + + for pup in puppet_files: + if not os.path.isfile(pup): + self.log.error("Error loading associated puppet content: '%(file)s'" % {'file':pup}) + return False + benchmark.__dict__['puppet'] = puppet_files benchmark.config.set(benchmark.id, 'puppet', json.dumps(list(puppet_files)))
@@ -302,30 +308,33 @@ class Secstate: shutil.copy(benchmark_file, directory) benchmark.config.set(id, 'file', os.path.join(directory, os.path.basename(benchmark_file))) benchmark.config.set(id, 'selected', True) - conf_file = open(os.path.join(self.config.get('secstate', 'conf_dir'), id + ".cfg"), 'w') - benchmark.config.write(conf_file) - conf_file.close()
for oval in list(set(oval_files)): shutil.copy(os.path.join(oval_path, oval), directory)
- for puppet in benchmark.puppet: - new_puppet = os.path.join(os.path.dirname(benchmark_file), puppet) - puppet_dir = self.config.get('secstate', 'puppet_dir') - if not os.path.isdir(puppet_dir): - os.makedirs(puppet_dir) + puppet_dir = self.config.get('secstate', 'puppet_dir') + if not os.path.isdir(puppet_dir): + os.makedirs(puppet_dir)
+ for puppet in benchmark.puppet: if os.path.isfile(os.path.join(puppet_dir, puppet)): - old = open(os.path.join(puppet_dir, puppet)) - new = open(new_puppet) + old_file = os.path.join(puppet_dir, os.path.basename(puppet)) + old = open(old_file) + new = open(puppet) if old.read() != new.read(): self.log.info("A puppet file named '%(name)s' has already been imported. Moving old file to '%(name)s.old'" % {'name':puppet}) - os.rename(os.path.join(puppet_dir, puppet), os.path.join(puppet_dir, puppet + '.old')) + os.rename(old_file, old_file + '.old') else: continue
- shutil.copy(os.path.join(os.path.dirname(benchmark_file), puppet), self.config.get('secstate', 'puppet_dir')) - puppet = os.path.join(puppet_dir, puppet) + shutil.copy(os.path.join(os.path.dirname(benchmark_file), os.path.basename(puppet)), self.config.get('secstate', 'puppet_dir')) + + benchmark.__dict__['puppet'] = map(lambda x: os.path.join(self.config.get('secstate', 'puppet_dir'), os.path.basename(x)), benchmark.puppet) + benchmark.config.set(benchmark.id, 'puppet', json.dumps(benchmark.puppet)) + + conf_file = open(os.path.join(self.config.get('secstate', 'conf_dir'), id + ".cfg"), 'w') + benchmark.config.write(conf_file) + conf_file.close()
except (IOError, OSError), e: self.log.error("Error importing content: %(error)s" % {'error':e}) @@ -334,7 +343,7 @@ class Secstate:
return benchmark
- def import_zipped_content(self, zip, type, store_path, puppet, changes=False, active_profile=NONE_PROFILE): + def import_zipped_content(self, zip, type, store_path, changes=False, active_profile=NONE_PROFILE): """ Function: Validate and copy content from zipped file to repository Input: Zipped file contating content and bool whether it contains puppet content @@ -404,7 +413,7 @@ class Secstate: return benchmark
- def import_content(self, content, puppet=False, changes=True, save=False, active_profile=NONE_PROFILE): + def import_content(self, content, changes=True, save=False, active_profile=NONE_PROFILE): """ Function: Validates XCCDF/OVAL content and optionally saves it to the data store Input: File containing content @@ -424,7 +433,7 @@ class Secstate: return None
if self.content.has_key(content): - return self.import_content(self.content[content], puppet, changes, active_profile=active_profile) + return self.import_content(self.content[content], changes, active_profile=active_profile)
if save: store_path = self.config.get('secstate', 'benchmark_dir') @@ -449,7 +458,7 @@ class Secstate: return self.import_benchmark(content, store_path=store_path, oval_path=os.path.dirname(content), changes=changes, active_profile=active_profile)
else: - return self.import_zipped_content(content, file_type, store_path=store_path, puppet=puppet, changes=changes, active_profile=active_profile) + return self.import_zipped_content(content, file_type, store_path=store_path, changes=changes, active_profile=active_profile)
def export(self, benchmark_id, new_file, original=False): if not self.content.has_key(benchmark_id):
secstate-devel@lists.fedorahosted.org