aboutsummaryrefslogtreecommitdiffstats
path: root/mcstrans/share/util/mlstrans-test
blob: c026d00ef9c70ae88b2e1438b2501d67f71fe721 (plain)
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
#!/usr/bin/python -E
import sys
import selinux


verbose = 0
errors = 0


def untrans(trans, val):
    global errors, verbose
    (rc, raw) = selinux.selinux_trans_to_raw_context(trans)
    if raw != val:
        print("untrans: '%s' -> '%s' != '%s' FAILED" % (trans, raw, val))
        errors += 1
    else:
        if verbose:
            print("untrans: %s -> %s != %s SUCCESS" % (trans, raw, val))


def trans(raw, val):
    global errors, verbose
    (rc, trans) = selinux.selinux_raw_to_trans_context(raw)
    if trans != val:
        print("trans: '%s' -> '%s' != '%s' FAILED" % (raw, trans, val))
        errors += 1
    else:
        if verbose:
            print("trans: %s -> %s != %s SUCCESS" % (raw, trans, val))


if len(sys.argv) > 1 and sys.argv[1] == "-v":
    verbose = 1

for arg in sys.argv[1:]:
    f = open(arg, 'r')
    for line in f:
        if line.startswith('#'):
            continue
        if not line.strip():
            continue
        line = line.rstrip('\n')
        if line.find("==") != -1:
            t, r = line.split("==")
            untrans("a:b:c:" + t, "a:b:c:" + r)
            trans("a:b:c:" + r, "a:b:c:" + t)
        else:
            t, r = line.split("=")
            untrans("a:b:c:" + t, "a:b:c:" + r)
    f.close()

s = "s"
if errors == 1:
    s = ""
print("mlstrans-test done with %d error%s" % (errors, s))

sys.exit(errors)