2013-10-11 14:16:57 +00:00
|
|
|
import dbus
|
|
|
|
import dbus.service
|
|
|
|
from sepolicy.sedbus import SELinuxDBus
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2013-10-11 14:16:57 +00:00
|
|
|
def convert_customization(buf):
|
|
|
|
cust_dict = {}
|
|
|
|
cust_dict["fcontext-equiv"] = {}
|
|
|
|
for i in buf.split("\n"):
|
|
|
|
rec = i.split()
|
|
|
|
if len(rec) == 0:
|
|
|
|
continue
|
|
|
|
if rec[1] == "-D":
|
|
|
|
continue
|
|
|
|
if rec[0] not in cust_dict:
|
|
|
|
cust_dict[rec[0]] = {}
|
|
|
|
if rec[0] == "boolean":
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["boolean"][rec[-1]] = {"active": rec[2] == "-1"}
|
2013-10-11 14:16:57 +00:00
|
|
|
if rec[0] == "login":
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["login"][rec[-1]] = {"seuser": rec[3], "range": rec[5]}
|
2013-10-11 14:16:57 +00:00
|
|
|
if rec[0] == "interface":
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["login"][rec[-1]] = {"type": rec[3]}
|
2013-10-11 14:16:57 +00:00
|
|
|
if rec[0] == "user":
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["user"][rec[-1]] = {"level": rec[3], "range": rec[5], "role": rec[7]}
|
2013-10-11 14:16:57 +00:00
|
|
|
if rec[0] == "port":
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["port"][(rec[-1], rec[-2])] = {"type": rec[3]}
|
2013-10-11 14:16:57 +00:00
|
|
|
if rec[0] == "node":
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["node"][rec[-1]] = {"mask": rec[3], "protocol": rec[5], "type": rec[7]}
|
2013-10-11 14:16:57 +00:00
|
|
|
if rec[0] == "fcontext":
|
|
|
|
if rec[2] == "-e":
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["fcontext-equiv"][(rec[-1])] = {"equiv": rec[3]}
|
2013-10-11 14:16:57 +00:00
|
|
|
else:
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["fcontext"][(rec[-1], rec[3])] = {"type": rec[5]}
|
2013-10-11 14:16:57 +00:00
|
|
|
if rec[0] == "module":
|
2015-07-24 08:07:13 +00:00
|
|
|
cust_dict["module"][rec[-1]] = {"enabled": rec[2] != "-d"}
|
2013-10-11 14:16:57 +00:00
|
|
|
|
|
|
|
return cust_dict
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
dbus_proxy = SELinuxDBus()
|
|
|
|
resp = dbus_proxy.customized()
|
2016-11-07 09:51:08 +00:00
|
|
|
print(convert_customization(resp))
|
|
|
|
except dbus.DBusException as e:
|
|
|
|
print(e)
|