X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=kernel_hardening_checker%2F__init__.py;h=601619ea9ac321c568fe85c8311c1a5257e58bf6;hb=d91f51e65de03179e7b8eebe538aac71f0ee96fc;hp=7db9e40f812589b48449f2fe881750f3374fdcad;hpb=d7d76b05572c93e89f2ac911cb0790c0140dd3da;p=kconfig-hardened-check.git diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index 7db9e40..601619e 100644 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -19,7 +19,7 @@ import re import json from .__about__ import __version__ from .checks import add_kconfig_checks, add_cmdline_checks, normalize_cmdline_options, add_sysctl_checks -from .engine import StrOrNone, TupleOrNone, print_unknown_options, populate_with_data, perform_checks, override_expected_value +from .engine import StrOrNone, TupleOrNone, ChecklistObjType, print_unknown_options, populate_with_data, perform_checks, override_expected_value def _open(file: str, *args, **kwargs) -> TextIO: @@ -80,7 +80,7 @@ def detect_compiler(fname: str) -> Tuple[StrOrNone, str]: sys.exit(f'[!] ERROR: invalid GCC_VERSION and CLANG_VERSION: {gcc_version} {clang_version}') -def print_checklist(mode: StrOrNone, checklist: List, with_results: bool) -> None: +def print_checklist(mode: StrOrNone, checklist: List[ChecklistObjType], with_results: bool) -> None: if mode == 'json': output = [] for opt in checklist: @@ -100,14 +100,21 @@ def print_checklist(mode: StrOrNone, checklist: List, with_results: bool) -> Non print('=' * sep_line_len) # table contents + ok_count = 0 + fail_count = 0 for opt in checklist: if with_results: - if mode == 'show_ok': - if not opt.result.startswith('OK'): + assert(opt.result), f'unexpected empty result of {opt.name} check' + if opt.result.startswith('OK'): + ok_count += 1 + if mode == 'show_fail': continue - if mode == 'show_fail': - if not opt.result.startswith('FAIL'): + elif opt.result.startswith('FAIL'): + fail_count += 1 + if mode == 'show_ok': continue + else: + assert(False), f'unexpected result "{opt.result}" of {opt.name} check' opt.table_print(mode, with_results) print() if mode == 'verbose': @@ -116,9 +123,7 @@ def print_checklist(mode: StrOrNone, checklist: List, with_results: bool) -> Non # final score if with_results: - fail_count = len(list(filter(lambda opt: opt.result.startswith('FAIL'), checklist))) fail_suppressed = '' - ok_count = len(list(filter(lambda opt: opt.result.startswith('OK'), checklist))) ok_suppressed = '' if mode == 'show_ok': fail_suppressed = ' (suppressed in output)' @@ -234,7 +239,7 @@ def main() -> None: if mode != 'json': print(f'[+] Special report mode: {mode}') - config_checklist = [] # type: List + config_checklist = [] # type: List[ChecklistObjType] if args.config: if args.print: