Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Build XCCDF only from module.ini and group.ini files
Browse files Browse the repository at this point in the history
Previously building of module set has been corrupted when directory
with the module contained more than one file with the ".ini"
extentions. Build of the module set shouldn't be affected by various
INI files, that are not related to the module set structure.

So the scan is now read only group.ini and module.ini files whose
names are reserved for PA purposes. In addition we expect only one
of those files in each directory, so the ModuleSetFormatError
exception is raised when both are detected in the same directory.

- removed unused import of ModuleSetUtils

Resolves #310
  • Loading branch information
pirat89 committed Feb 11, 2018
1 parent c4b00e0 commit 9580c7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions preupg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
# file with module set meta info
properties_ini = "properties.ini"
module_ini = "module.ini"
group_ini = "group.ini"

solution_txt = "solution.txt"
check_script = "check"
Expand Down
20 changes: 15 additions & 5 deletions preupg/xmlgen/oscap_group_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import ConfigParser as configparser

from preupg.xmlgen.xml_utils import XmlUtils
from preupg.utils import FileHelper, ModuleSetUtils
from preupg.utils import FileHelper
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
from preupg import settings
from preupg import settings, exception

try:
from xml.etree.ElementTree import ParseError
Expand Down Expand Up @@ -56,9 +56,19 @@ def find_all_ini(self):
self.loded dict:
self.loaded[ini_file_path] = {option1: value, option2: value, ...}
"""
for dir_name in os.listdir(self.dirname):
if dir_name.endswith(".ini"):
self.lists.append(os.path.join(self.dirname, dir_name))
found = 0
for file_name in os.listdir(self.dirname):
if file_name not in [settings.module_ini, settings.group_ini]:
continue
if found == 0:
self.lists.append(os.path.join(self.dirname, file_name))
found = 1
else:
raise exception.ModuleSetFormatError(
"Cannot prepare XCCDF for OpenSCAP",
"group.ini and module.ini are in the same directory %s"
% self.dirname
)
for file_name in self.lists:
if FileHelper.check_file(file_name, "r") is False:
continue
Expand Down

0 comments on commit 9580c7f

Please sign in to comment.