2017-09-16 18:19:32 +00:00
|
|
|
#!/usr/bin/env python3
|
2015-06-03 17:33:11 +00:00
|
|
|
# Copyright 2015, Tresys Technology, LLC
|
|
|
|
#
|
2021-11-20 19:03:26 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2015-06-03 17:33:11 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
import logging
|
2023-03-27 13:30:26 +00:00
|
|
|
import warnings
|
2015-06-03 17:33:11 +00:00
|
|
|
|
|
|
|
import setools
|
|
|
|
import setoolsgui
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Graphical SELinux policy analysis tool.")
|
|
|
|
parser.add_argument("--version", action="version", version=setools.__version__)
|
|
|
|
parser.add_argument("policy", nargs="?",
|
|
|
|
help="Path to the SELinux policy to analyze.")
|
|
|
|
parser.add_argument("-v", "--verbose", action="store_true",
|
|
|
|
help="Print extra informational messages")
|
|
|
|
parser.add_argument("--debug", action="store_true", dest="debug", help="Enable debugging.")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2016-03-04 19:05:20 +00:00
|
|
|
logging.basicConfig(level=logging.DEBUG, filename="/dev/null")
|
|
|
|
|
|
|
|
console_handler = logging.StreamHandler()
|
|
|
|
|
2015-06-03 17:33:11 +00:00
|
|
|
if args.debug:
|
2016-03-04 19:05:20 +00:00
|
|
|
console_handler.setLevel(logging.DEBUG)
|
|
|
|
console_handler.setFormatter(
|
|
|
|
logging.Formatter('%(asctime)s|%(levelname)s|%(name)s|%(message)s'))
|
2023-03-27 13:30:26 +00:00
|
|
|
|
|
|
|
if not sys.warnoptions:
|
|
|
|
warnings.simplefilter("default")
|
|
|
|
|
2015-06-03 17:33:11 +00:00
|
|
|
elif args.verbose:
|
2016-03-04 19:05:20 +00:00
|
|
|
console_handler.setLevel(logging.INFO)
|
|
|
|
console_handler.setFormatter(logging.Formatter('%(message)s'))
|
2023-03-27 13:30:26 +00:00
|
|
|
|
|
|
|
if not sys.warnoptions:
|
|
|
|
warnings.simplefilter("default")
|
2015-06-03 17:33:11 +00:00
|
|
|
else:
|
2016-03-04 19:05:20 +00:00
|
|
|
console_handler.setLevel(logging.WARNING)
|
|
|
|
console_handler.setFormatter(logging.Formatter('%(message)s'))
|
|
|
|
|
2023-03-27 13:30:26 +00:00
|
|
|
if not sys.warnoptions:
|
|
|
|
warnings.simplefilter("ignore")
|
|
|
|
|
2016-03-04 19:05:20 +00:00
|
|
|
logging.getLogger().addHandler(console_handler)
|
2015-06-03 17:33:11 +00:00
|
|
|
|
|
|
|
try:
|
2023-06-20 15:53:32 +00:00
|
|
|
sys.exit(setoolsgui.run_apol(args.policy))
|
2015-06-03 17:33:11 +00:00
|
|
|
|
2023-10-19 13:11:21 +00:00
|
|
|
except AssertionError:
|
|
|
|
# Always provide a traceback for assertion errors
|
|
|
|
raise
|
|
|
|
|
2015-06-03 17:33:11 +00:00
|
|
|
except Exception as err:
|
|
|
|
if args.debug:
|
2016-07-22 23:14:40 +00:00
|
|
|
raise
|
2015-06-03 17:33:11 +00:00
|
|
|
else:
|
|
|
|
print(err)
|
|
|
|
|
2016-03-04 18:59:21 +00:00
|
|
|
sys.exit(1)
|