Commit 52216da1 by Alexander Popov

Add main() and clean up working with globals

parent a7e40940
...@@ -69,7 +69,7 @@ debug_mode = False ...@@ -69,7 +69,7 @@ debug_mode = False
json_mode = False json_mode = False
supported_archs = [ 'X86_64', 'X86_32', 'ARM64', 'ARM' ] supported_archs = [ 'X86_64', 'X86_32', 'ARM64', 'ARM' ]
config_checklist = []
kernel_version = None kernel_version = None
...@@ -525,7 +525,7 @@ def perform_checks(checklist, parsed_options): ...@@ -525,7 +525,7 @@ def perform_checks(checklist, parsed_options):
opt.check() opt.check()
def check_config_file(checklist, fname): def check_config_file(checklist, fname, arch):
with open(fname, 'r') as f: with open(fname, 'r') as f:
parsed_options = OrderedDict() parsed_options = OrderedDict()
opt_is_on = re.compile("CONFIG_[a-zA-Z0-9_]*=[a-zA-Z0-9_\"]*") opt_is_on = re.compile("CONFIG_[a-zA-Z0-9_]*=[a-zA-Z0-9_\"]*")
...@@ -568,8 +568,13 @@ def check_config_file(checklist, fname): ...@@ -568,8 +568,13 @@ def check_config_file(checklist, fname):
print_checklist(checklist, True) 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 = ArgumentParser(description='Checks the hardening options in the Linux kernel config')
parser.add_argument('-p', '--print', choices=supported_archs, parser.add_argument('-p', '--print', choices=supported_archs,
help='print hardening preferences for selected architecture') help='print hardening preferences for selected architecture')
...@@ -603,7 +608,7 @@ if __name__ == '__main__': ...@@ -603,7 +608,7 @@ if __name__ == '__main__':
print('[+] Detected kernel version: {}.{}'.format(kernel_version[0], kernel_version[1])) print('[+] Detected kernel version: {}.{}'.format(kernel_version[0], kernel_version[1]))
construct_checklist(config_checklist, arch) 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))) 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))) ok_count = len(list(filter(lambda opt: opt.result.startswith('OK'), config_checklist)))
if debug_mode: if debug_mode:
...@@ -621,3 +626,6 @@ if __name__ == '__main__': ...@@ -621,3 +626,6 @@ if __name__ == '__main__':
sys.exit(0) sys.exit(0)
parser.print_help() parser.print_help()
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment