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