X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=kernel_hardening_checker%2Fengine.py;h=f52c446294f147dd00fd7934bcb1a7eb3f78d91e;hb=cf03f175c0ddfd45f8967b217791bb945dcac910;hp=4fdc222e7e8ac3d9fec6a2cf0a3c60c411f8c918;hpb=c49734db6223320fa19f1501560bd5cc513d0832;p=kconfig-hardened-check.git diff --git a/kernel_hardening_checker/engine.py b/kernel_hardening_checker/engine.py index 4fdc222..f52c446 100644 --- a/kernel_hardening_checker/engine.py +++ b/kernel_hardening_checker/engine.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 """ This tool is for checking the security hardening options of the Linux kernel. @@ -20,10 +20,9 @@ def colorize_result(input_text): return input_text if input_text.startswith('OK'): color = GREEN_COLOR - elif input_text.startswith('FAIL:'): - color = RED_COLOR else: - assert(False), f'unexpected result "{input_text}"' + assert(input_text.startswith('FAIL:')), f'unexpected result "{input_text}"' + color = RED_COLOR return f'{color}{input_text}{COLOR_END}' @@ -58,6 +57,10 @@ class OptCheck: self.state = None self.result = None + @property + def type(self): + return None + def check(self): # handle the 'is present' check if self.expected == 'is present': @@ -105,7 +108,7 @@ class OptCheck: class KconfigCheck(OptCheck): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.name = 'CONFIG_' + self.name + self.name = f'CONFIG_{self.name}' @property def type(self): @@ -126,7 +129,7 @@ class SysctlCheck(OptCheck): class VersionCheck: def __init__(self, ver_expected): - assert(ver_expected and isinstance(ver_expected, tuple) and len(ver_expected) == 2), \ + assert(ver_expected and isinstance(ver_expected, tuple) and len(ver_expected) == 3), \ f'invalid version "{ver_expected}" for VersionCheck' self.ver_expected = ver_expected self.ver = () @@ -180,7 +183,8 @@ class ComplexOptCheck: def table_print(self, mode, with_results): if mode == 'verbose': - print(f' {"<<< " + self.__class__.__name__ + " >>>":87}', end='') + class_name = f'<<< {self.__class__.__name__} >>>' + print(f' {class_name:87}', end='') if with_results: print(f'| {colorize_result(self.result)}', end='') for o in self.opts: