forked from SELinuxProject/setools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sechecker
executable file
·68 lines (55 loc) · 1.88 KB
/
sechecker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# Copyright 2020 Microsoft Corporation
#
# SPDX-License-Identifier: GPL-2.0-only
#
import setools
import argparse
import sys
import logging
import signal
import warnings
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
parser = argparse.ArgumentParser(description="SELinux policy checker tool.")
parser.add_argument("--version", action="version", version=setools.__version__)
parser.add_argument("config", help="Path to the checker configuration file.")
parser.add_argument("policy", help="Path to the SELinux policy to check.", nargs="?")
parser.add_argument("-o", "--output_file", help="Path to log output.", required=False)
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()
if args.debug:
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s|%(levelname)s|%(name)s|%(message)s')
if not sys.warnoptions:
warnings.simplefilter("default")
elif args.verbose:
logging.basicConfig(level=logging.INFO, format='%(message)s')
if not sys.warnoptions:
warnings.simplefilter("default")
else:
logging.basicConfig(level=logging.WARNING, format='%(message)s')
if not sys.warnoptions:
warnings.simplefilter("ignore")
try:
p = setools.SELinuxPolicy(args.policy)
c = setools.PolicyChecker(p, args.config)
if args.output_file:
with open(args.output_file, "w") as fd:
failures = c.run(output=fd)
else:
failures = c.run()
sys.exit(1 if failures else 0)
except setools.exception.InvalidCheckerConfig as err:
if args.debug:
raise
else:
print(err)
sys.exit(2)
except Exception as err:
if args.debug:
raise
else:
print(err)
sys.exit(3)