From ec1523373ee676d385bb1aecd80e856aff4e5f8b Mon Sep 17 00:00:00 2001 From: Commandcracker <49335821+Commandcracker@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:44:46 +0100 Subject: [PATCH 1/6] Find xccdf_1.1_to_1.2.xsl on Windows --- cmake/FindOpenSCAP.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindOpenSCAP.cmake b/cmake/FindOpenSCAP.cmake index f65d21510bc..c70fd5628b2 100644 --- a/cmake/FindOpenSCAP.cmake +++ b/cmake/FindOpenSCAP.cmake @@ -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() From 6e71e37e01426fa1b6e5639a0d57c673a22fa5a0 Mon Sep 17 00:00:00 2001 From: Commandcracker Date: Fri, 22 Dec 2023 23:14:46 +0100 Subject: [PATCH 2/6] Account for division by zero --- utils/gen_stig_table.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/gen_stig_table.py b/utils/gen_stig_table.py index 13ffa884df0..06107dd32bc 100644 --- a/utils/gen_stig_table.py +++ b/utils/gen_stig_table.py @@ -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 From acf2e0fd7c9a1deba67e278dcd88dcda5f7b2965 Mon Sep 17 00:00:00 2001 From: Commandcracker Date: Fri, 22 Dec 2023 23:19:01 +0100 Subject: [PATCH 3/6] Find xccdf-guide.xsl by pssible openscap root dirs (adds Windows support) --- build-scripts/generate_guides.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/build-scripts/generate_guides.py b/build-scripts/generate_guides.py index 131035ad8c3..de1d6ced0f8 100755 --- a/build-scripts/generate_guides.py +++ b/build-scripts/generate_guides.py @@ -11,9 +11,30 @@ 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"), + "/usr", + "/usr/bin", + "/usr/sbin", + "/usr/local", + "/usr/share/", + "/usr/local/share", + "/opt", + "/opt/local", +] + +for name in OPENSCAP_POSSIBLE_ROOT_DIRS: + for subpath in [os.path.join("share", "openscap", "xsl"), "xsl"]: + file_path = os.path.join(name, subpath, "xccdf-guide.xsl") + if os.path.exists(file_path): + XCCDF_GUIDE_XSL = file_path + break + else: + continue + break +else: + exit("ERROR: The OPENSCAP XSL XCCDF GUIDE file was not found. Please specify the OPENSCAP ROOT DIR with the OPENSCAP_ROOT_DIR environment variable.") def get_benchmarks(ds, product): benchmarks = {} @@ -45,7 +66,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") @@ -136,7 +157,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: From 68d2d3ac0bbd53b880d2c5c32c96fae1cdcc0ce8 Mon Sep 17 00:00:00 2001 From: Commandcracker Date: Sat, 23 Dec 2023 01:05:10 +0100 Subject: [PATCH 4/6] Use XSLT_PREFIX --- build-scripts/generate_guides.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build-scripts/generate_guides.py b/build-scripts/generate_guides.py index de1d6ced0f8..ab20b39ecfe 100755 --- a/build-scripts/generate_guides.py +++ b/build-scripts/generate_guides.py @@ -14,6 +14,7 @@ OPENSCAP_POSSIBLE_ROOT_DIRS = [ os.getenv("OPENSCAP_ROOT_DIR"), os.getenv("ProgramFiles"), + os.getenv("XSLT_PREFIX"), "/usr", "/usr/bin", "/usr/sbin", @@ -34,7 +35,10 @@ continue break else: - exit("ERROR: The OPENSCAP XSL XCCDF GUIDE file was not found. Please specify the OPENSCAP ROOT DIR with the OPENSCAP_ROOT_DIR environment variable.") + exit("ERROR: The OPENSCAP XSL XCCDF GUIDE file was not found. " + "Please specify the OPENSCAP ROOT DIR with the " + "OPENSCAP_ROOT_DIR environment variable.") + def get_benchmarks(ds, product): benchmarks = {} From 86a2a52decc457c270c9f42ef7da7ffcdd527844 Mon Sep 17 00:00:00 2001 From: Commandcracker Date: Sat, 23 Dec 2023 01:10:46 +0100 Subject: [PATCH 5/6] adapt styling --- build-scripts/generate_guides.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build-scripts/generate_guides.py b/build-scripts/generate_guides.py index ab20b39ecfe..f03fe5be579 100755 --- a/build-scripts/generate_guides.py +++ b/build-scripts/generate_guides.py @@ -35,9 +35,7 @@ continue break else: - exit("ERROR: The OPENSCAP XSL XCCDF GUIDE file was not found. " - "Please specify the OPENSCAP ROOT DIR with the " - "OPENSCAP_ROOT_DIR environment variable.") + XCCDF_GUIDE_XSL = None def get_benchmarks(ds, product): From e3f471bcebfb1a4d79e61acb3a38dc1cea4ff07b Mon Sep 17 00:00:00 2001 From: Commandcracker Date: Fri, 29 Dec 2023 17:01:07 +0100 Subject: [PATCH 6/6] Ignore none as possible root dir --- build-scripts/generate_guides.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build-scripts/generate_guides.py b/build-scripts/generate_guides.py index f03fe5be579..a422ca164f0 100755 --- a/build-scripts/generate_guides.py +++ b/build-scripts/generate_guides.py @@ -25,9 +25,11 @@ "/opt/local", ] -for name in OPENSCAP_POSSIBLE_ROOT_DIRS: +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(name, subpath, "xccdf-guide.xsl") + file_path = os.path.join(root_dir, subpath, "xccdf-guide.xsl") if os.path.exists(file_path): XCCDF_GUIDE_XSL = file_path break