From: Alexander Popov Date: Wed, 25 Mar 2020 23:13:36 +0000 (+0300) Subject: Add main() and clean up working with globals X-Git-Tag: v0.5.7~53 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=52216da1b9606d102192d6f6adaa855eabaea0d0;p=kconfig-hardened-check.git Add main() and clean up working with globals --- diff --git a/kconfig-hardened-check/__init__.py b/kconfig-hardened-check/__init__.py index 5df4997..27f0072 100755 --- a/kconfig-hardened-check/__init__.py +++ b/kconfig-hardened-check/__init__.py @@ -69,7 +69,7 @@ debug_mode = False json_mode = False supported_archs = [ 'X86_64', 'X86_32', 'ARM64', 'ARM' ] -config_checklist = [] + kernel_version = None @@ -525,7 +525,7 @@ def perform_checks(checklist, parsed_options): opt.check() -def check_config_file(checklist, fname): +def check_config_file(checklist, fname, arch): with open(fname, 'r') as f: parsed_options = OrderedDict() opt_is_on = re.compile("CONFIG_[a-zA-Z0-9_]*=[a-zA-Z0-9_\"]*") @@ -568,8 +568,13 @@ def check_config_file(checklist, fname): print_checklist(checklist, True) +def main(): + global debug_mode + global json_mode + global kernel_version + + config_checklist = [] -if __name__ == '__main__': parser = ArgumentParser(description='Checks the hardening options in the Linux kernel config') parser.add_argument('-p', '--print', choices=supported_archs, help='print hardening preferences for selected architecture') @@ -603,7 +608,7 @@ if __name__ == '__main__': print('[+] Detected kernel version: {}.{}'.format(kernel_version[0], kernel_version[1])) construct_checklist(config_checklist, arch) - check_config_file(config_checklist, args.config) + check_config_file(config_checklist, args.config, arch) error_count = len(list(filter(lambda opt: opt.result.startswith('FAIL'), config_checklist))) ok_count = len(list(filter(lambda opt: opt.result.startswith('OK'), config_checklist))) if debug_mode: @@ -621,3 +626,6 @@ if __name__ == '__main__': sys.exit(0) parser.print_help() + +if __name__ == '__main__': + main()