2019-02-18 16:03:46 +00:00
|
|
|
#!/usr/bin/python3 -E
|
2015-07-24 08:07:13 +00:00
|
|
|
import sys
|
2018-12-15 18:14:55 +00:00
|
|
|
import selinux
|
|
|
|
|
|
|
|
|
2010-07-21 19:40:00 +00:00
|
|
|
verbose = 0
|
2015-07-24 08:07:13 +00:00
|
|
|
errors = 0
|
|
|
|
|
|
|
|
|
2010-07-21 19:40:00 +00:00
|
|
|
def untrans(trans, val):
|
|
|
|
global errors, verbose
|
2018-12-15 18:14:55 +00:00
|
|
|
(rc, raw) = selinux.selinux_trans_to_raw_context(trans)
|
2010-07-21 19:40:00 +00:00
|
|
|
if raw != val:
|
2018-12-15 18:14:54 +00:00
|
|
|
print("untrans: '%s' -> '%s' != '%s' FAILED" % (trans, raw, val))
|
2010-07-21 19:40:00 +00:00
|
|
|
errors += 1
|
|
|
|
else:
|
|
|
|
if verbose:
|
2021-08-06 08:33:40 +00:00
|
|
|
print("untrans: '%s' -> '%s' == '%s' SUCCESS" % (trans, raw, val))
|
2015-07-24 08:07:13 +00:00
|
|
|
|
|
|
|
|
2010-07-21 19:40:00 +00:00
|
|
|
def trans(raw, val):
|
|
|
|
global errors, verbose
|
2018-12-15 18:14:55 +00:00
|
|
|
(rc, trans) = selinux.selinux_raw_to_trans_context(raw)
|
2010-07-21 19:40:00 +00:00
|
|
|
if trans != val:
|
2018-12-15 18:14:54 +00:00
|
|
|
print("trans: '%s' -> '%s' != '%s' FAILED" % (raw, trans, val))
|
2010-07-21 19:40:00 +00:00
|
|
|
errors += 1
|
|
|
|
else:
|
|
|
|
if verbose:
|
2021-08-06 08:33:40 +00:00
|
|
|
print("trans: '%s' -> '%s' == '%s' SUCCESS" % (raw, trans, val))
|
2010-07-21 19:40:00 +00:00
|
|
|
|
2018-12-15 18:14:55 +00:00
|
|
|
|
2010-07-21 19:40:00 +00:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "-v":
|
|
|
|
verbose = 1
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2010-07-21 19:40:00 +00:00
|
|
|
for arg in sys.argv[1:]:
|
2015-07-24 08:07:13 +00:00
|
|
|
f = open(arg, 'r')
|
2010-07-21 19:40:00 +00:00
|
|
|
for line in f:
|
|
|
|
if line.startswith('#'):
|
|
|
|
continue
|
|
|
|
if not line.strip():
|
|
|
|
continue
|
|
|
|
line = line.rstrip('\n')
|
2018-12-15 18:14:55 +00:00
|
|
|
if line.find("==") != -1:
|
2015-07-24 08:07:13 +00:00
|
|
|
t, r = line.split("==")
|
2010-07-21 19:40:00 +00:00
|
|
|
untrans("a:b:c:" + t, "a:b:c:" + r)
|
|
|
|
trans("a:b:c:" + r, "a:b:c:" + t)
|
|
|
|
else:
|
2015-07-24 08:07:13 +00:00
|
|
|
t, r = line.split("=")
|
2010-07-21 19:40:00 +00:00
|
|
|
untrans("a:b:c:" + t, "a:b:c:" + r)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
s = "s"
|
2015-07-24 08:07:13 +00:00
|
|
|
if errors == 1:
|
|
|
|
s = ""
|
2018-12-15 18:14:54 +00:00
|
|
|
print("mlstrans-test done with %d error%s" % (errors, s))
|
2010-07-21 19:40:00 +00:00
|
|
|
|
|
|
|
sys.exit(errors)
|