1 #!/usr/bin/python -E 2 import sys 3 import re 4 from selinux import * 5 verbose = 0 6 errors = 0 7 8 9 def untrans(trans, val): 10 global errors, verbose 11 (rc, raw) = selinux_trans_to_raw_context(trans) 12 if raw != val: 13 print "untrans: '%s' -> '%s' != '%s' FAILED" % (trans, raw, val) 14 errors += 1 15 else: 16 if verbose: 17 print "untrans: %s -> %s != %s SUCCESS" % (trans, raw, val) 18 19 20 def trans(raw, val): 21 global errors, verbose 22 (rc, trans) = selinux_raw_to_trans_context(raw) 23 if trans != val: 24 print "trans: '%s' -> '%s' != '%s' FAILED" % (raw, trans, val) 25 errors += 1 26 else: 27 if verbose: 28 print "trans: %s -> %s != %s SUCCESS" % (raw, trans, val) 29 30 if len(sys.argv) > 1 and sys.argv[1] == "-v": 31 verbose = 1 32 33 for arg in sys.argv[1:]: 34 f = open(arg, 'r') 35 for line in f: 36 if line.startswith('#'): 37 continue 38 if not line.strip(): 39 continue 40 line = line.rstrip('\n') 41 # print line 42 if (line.find("==") != -1): 43 t, r = line.split("==") 44 untrans("a:b:c:" + t, "a:b:c:" + r) 45 trans("a:b:c:" + r, "a:b:c:" + t) 46 else: 47 t, r = line.split("=") 48 untrans("a:b:c:" + t, "a:b:c:" + r) 49 f.close() 50 51 s = "s" 52 if errors == 1: 53 s = "" 54 print "mlstrans-test done with %d error%s" % (errors, s) 55 56 sys.exit(errors) 57