Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building on Windows #11406

Merged
merged 6 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions build-scripts/generate_guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,33 @@
BenchmarkData = collections.namedtuple(
"BenchmarkData", ["title", "profiles", "product"])

XSLT_PREFIX = os.getenv('XSLT_PREFIX', default='/usr')
XSLT_PATH = os.path.join(XSLT_PREFIX, "share/openscap/xsl/xccdf-guide.xsl")
OPENSCAP_POSSIBLE_ROOT_DIRS = [
os.getenv("OPENSCAP_ROOT_DIR"),
os.getenv("ProgramFiles"),
os.getenv("XSLT_PREFIX"),
"/usr",
"/usr/bin",
"/usr/sbin",
"/usr/local",
"/usr/share/",
"/usr/local/share",
"/opt",
"/opt/local",
]

for root_dir in OPENSCAP_POSSIBLE_ROOT_DIRS:
if root_dir is None:
continue
for subpath in [os.path.join("share", "openscap", "xsl"), "xsl"]:
file_path = os.path.join(root_dir, subpath, "xccdf-guide.xsl")
if os.path.exists(file_path):
XCCDF_GUIDE_XSL = file_path
break
else:
continue
break
else:
XCCDF_GUIDE_XSL = None
Comment on lines +14 to +40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to do things correctly, the path should be found by CMake and then passed to the script as a parameter.



def get_benchmarks(ds, product):
Expand Down Expand Up @@ -45,7 +70,7 @@ def parse_args():
help="Path to a SCAP source data stream, eg. 'ssg-rhel9-ds.xml'")
parser.add_argument(
"--oscap-version", required=True,
help=f"Version of OpenSCAP that owns {XSLT_PATH}, eg. 1.3.8")
help=f"Version of OpenSCAP that owns {XCCDF_GUIDE_XSL}, eg. 1.3.8")
parser.add_argument(
"--product", required=True,
help="Product ID, eg. rhel9")
Expand Down Expand Up @@ -136,7 +161,7 @@ def generate_html_index(benchmarks, data_stream, output_dir):


def generate_html_guides(ds, benchmarks, oscap_version, output_dir):
xslt = ET.parse(XSLT_PATH)
xslt = ET.parse(XCCDF_GUIDE_XSL)
transform = ET.XSLT(xslt)
for benchmark_id, benchmark_data in benchmarks.items():
for profile_id in benchmark_data.profiles:
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindOpenSCAP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(OPENSCAP_POSSIBLE_ROOT_DIRS
foreach(NAME ${OPENSCAP_POSSIBLE_ROOT_DIRS})
find_file(OPENSCAP_XCCDF_XSL_1_2 NAMES xccdf_1.1_to_1.2.xsl
PATHS "${NAME}"
PATH_SUFFIXES "share/openscap/xsl/"
PATH_SUFFIXES "share/openscap/xsl/" "xsl/"
)
endforeach()

Expand Down
5 changes: 4 additions & 1 deletion utils/gen_stig_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def get_stats(root, ns):
stats["total"] = total
stats["missing"] = missing
stats["implemented"] = implemented
stats["coverage"] = implemented / total * 100
if total != 0:
stats["coverage"] = implemented / total * 100
else:
stats["coverage"] = 0
stats["missing_rules"] = missing_rules
return stats

Expand Down
Loading