1import sys 2import dbus 3import dbus.service 4import dbus.mainloop.glib 5from slip.dbus import polkit 6 7 8class SELinuxDBus (object): 9 10 def __init__(self): 11 self.bus = dbus.SystemBus() 12 self.dbus_object = self.bus.get_object("org.selinux", "/org/selinux/object") 13 14 @polkit.enable_proxy 15 def semanage(self, buf): 16 ret = self.dbus_object.semanage(buf, dbus_interface="org.selinux") 17 return ret 18 19 @polkit.enable_proxy 20 def restorecon(self, path): 21 ret = self.dbus_object.restorecon(path, dbus_interface="org.selinux") 22 return ret 23 24 @polkit.enable_proxy 25 def setenforce(self, value): 26 ret = self.dbus_object.setenforce(value, dbus_interface="org.selinux") 27 return ret 28 29 @polkit.enable_proxy 30 def customized(self): 31 ret = self.dbus_object.customized(dbus_interface="org.selinux") 32 return ret 33 34 @polkit.enable_proxy 35 def semodule_list(self): 36 ret = self.dbus_object.semodule_list(dbus_interface="org.selinux") 37 return ret 38 39 @polkit.enable_proxy 40 def relabel_on_boot(self, value): 41 ret = self.dbus_object.relabel_on_boot(value, dbus_interface="org.selinux") 42 return ret 43 44 @polkit.enable_proxy 45 def change_default_mode(self, value): 46 ret = self.dbus_object.change_default_mode(value, dbus_interface="org.selinux") 47 return ret 48 49 @polkit.enable_proxy 50 def change_default_policy(self, value): 51 ret = self.dbus_object.change_default_policy(value, dbus_interface="org.selinux") 52 return ret 53 54if __name__ == "__main__": 55 try: 56 dbus_proxy = SELinuxDBus() 57 resp = dbus_proxy.setenforce(int(sys.argv[1])) 58 print(resp) 59 except dbus.DBusException as e: 60 print(e) 61