1 #!/usr/bin/python3 -E 2 import sys 3 import selinux 4 5 6 verbose = 0 7 errors = 0 8 9 if len(sys.argv) > 1 and sys.argv[1] == "-v": 10 verbose = 1 11 12 for arg in sys.argv[1:]: 13 f = open(arg, 'r') 14 for line in f: 15 if line.startswith('#'): 16 continue 17 if not line.strip(): 18 continue 19 line = line.rstrip('\n') 20 # print line 21 context, expected = line.split("=") 22 rc, raw = selinux.selinux_trans_to_raw_context(context) 23 if rc < 0: 24 print("Unable to get raw context of '%s'" % (context)) 25 errors += 1 26 continue 27 rc, colors = selinux.selinux_raw_context_to_color(raw) 28 if rc < 0: 29 print("Unable to get colors for '%s'" % (context)) 30 errors += 1 31 continue 32 colors = colors.rstrip() 33 if colors != expected: 34 print("For '%s' got\n\t'%s' expected\n\t'%s'" % (context, colors, expected)) 35 errors += 1 36 continue 37 f.close() 38 39 s = "s" 40 if errors == 1: 41 s = "" 42 print("mlscolor-test done with %d error%s" % (errors, s)) 43 44 sys.exit(errors) 45