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