1import dbus 2import dbus.service 3from sepolicy.sedbus import SELinuxDBus 4 5def convert_customization(buf): 6 cust_dict = {} 7 cust_dict["fcontext-equiv"] = {} 8 for i in buf.split("\n"): 9 rec = i.split() 10 if len(rec) == 0: 11 continue 12 if rec[1] == "-D": 13 continue 14 if rec[0] not in cust_dict: 15 cust_dict[rec[0]] = {} 16 if rec[0] == "boolean": 17 cust_dict["boolean"][rec[-1]] = { "active": rec[2] == "-1" } 18 if rec[0] == "login": 19 cust_dict["login"][rec[-1]] = { "seuser": rec[3], "range": rec[5] } 20 if rec[0] == "interface": 21 cust_dict["login"][rec[-1]] = { "type": rec[3] } 22 if rec[0] == "user": 23 cust_dict["user"][rec[-1]] = { "level": rec[3], "range": rec[5], "role": rec[7] } 24 if rec[0] == "port": 25 cust_dict["port"][(rec[-1], rec[-2] )] = { "type": rec[3] } 26 if rec[0] == "node": 27 cust_dict["node"][rec[-1]] = { "mask": rec[3], "protocol":rec[5], "type": rec[7] } 28 if rec[0] == "fcontext": 29 if rec[2] == "-e": 30 cust_dict["fcontext-equiv"][(rec[-1])] = { "equiv": rec[3] } 31 else: 32 cust_dict["fcontext"][(rec[-1],rec[3])] = { "type": rec[5] } 33 if rec[0] == "module": 34 cust_dict["module"][rec[-1]] = { "enabled": rec[2] != "-d" } 35 36 return cust_dict 37if __name__ == "__main__": 38 try: 39 dbus_proxy = SELinuxDBus() 40 resp = dbus_proxy.customized() 41 print convert_customization(resp) 42 except dbus.DBusException, e: 43 print e 44