117 lines
4.0 KiB
Diff
117 lines
4.0 KiB
Diff
From 25dd8cee2841d0be01756b6c600ea887fad0c67d Mon Sep 17 00:00:00 2001
|
|
From: Petr Lautrbach <plautrba@redhat.com>
|
|
Date: Fri, 28 Feb 2020 13:22:32 +0100
|
|
Subject: [PATCH] Use pydbus, a modern Python dbus API, for
|
|
SetroubleshootPrivileged
|
|
|
|
According to https://wiki.python.org/moin/DbusExamples dbus-python is a legacy API.
|
|
---
|
|
framework/src/SetroubleshootPrivileged.py | 36 +++++++++++++----------
|
|
framework/src/setroubleshoot/util.py | 17 +++--------
|
|
2 files changed, 25 insertions(+), 28 deletions(-)
|
|
|
|
diff --git a/framework/src/SetroubleshootPrivileged.py b/framework/src/SetroubleshootPrivileged.py
|
|
index 858115bbe5ae..899e68770880 100644
|
|
--- a/framework/src/SetroubleshootPrivileged.py
|
|
+++ b/framework/src/SetroubleshootPrivileged.py
|
|
@@ -18,31 +18,35 @@
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
-import dbus
|
|
-import dbus.service
|
|
-from dbus.mainloop.glib import DBusGMainLoop
|
|
from gi.repository import GLib
|
|
+from pydbus import SystemBus
|
|
import setroubleshoot.util
|
|
import signal
|
|
|
|
-DBusGMainLoop(set_as_default=True)
|
|
-
|
|
-class Privileged(dbus.service.Object):
|
|
+loop = GLib.MainLoop()
|
|
+
|
|
+class Privileged(object):
|
|
+ """
|
|
+ <node>
|
|
+ <interface name='org.fedoraproject.SetroubleshootPrivileged'>
|
|
+ <method name='get_rpm_nvr_by_scontext'>
|
|
+ <arg type='s' name='scontext' direction='in'/>
|
|
+ <arg type='s' name='rpmnvr' direction='out'/>
|
|
+ </method>
|
|
+ <method name='finish'/>
|
|
+ </interface>
|
|
+ </node>
|
|
+ """
|
|
|
|
def __init__(self, timeout=10):
|
|
self.timeout = timeout
|
|
self.alarm(self.timeout)
|
|
|
|
- bus = dbus.SystemBus()
|
|
- bus.request_name("org.fedoraproject.SetroubleshootPrivileged")
|
|
- bus_name = dbus.service.BusName("org.fedoraproject.SetroubleshootPrivileged", bus=bus)
|
|
- dbus.service.Object.__init__(self, bus_name, "/org/fedoraproject/SetroubleshootPrivileged/object")
|
|
-
|
|
def alarm(self, timeout=10):
|
|
signal.alarm(timeout)
|
|
|
|
- @dbus.service.method("org.fedoraproject.SetroubleshootPrivileged", in_signature='s', out_signature='s')
|
|
def get_rpm_nvr_by_scontext(self, scontext):
|
|
+ """Finds an SELinux module which defines given SELinux context"""
|
|
signal.alarm(self.timeout)
|
|
rpmnvr = setroubleshoot.util.get_rpm_nvr_by_scontext(scontext)
|
|
if rpmnvr is None:
|
|
@@ -50,8 +54,10 @@ class Privileged(dbus.service.Object):
|
|
|
|
return rpmnvr
|
|
|
|
-if __name__ == "__main__":
|
|
- privileged = Privileged()
|
|
+ def finish(self):
|
|
+ loop.quit()
|
|
|
|
- loop = GLib.MainLoop()
|
|
+if __name__ == "__main__":
|
|
+ bus = SystemBus()
|
|
+ bus.publish("org.fedoraproject.SetroubleshootPrivileged", Privileged())
|
|
loop.run()
|
|
diff --git a/framework/src/setroubleshoot/util.py b/framework/src/setroubleshoot/util.py
|
|
index 77b3668afa86..4d18555fb9e4 100755
|
|
--- a/framework/src/setroubleshoot/util.py
|
|
+++ b/framework/src/setroubleshoot/util.py
|
|
@@ -68,7 +68,7 @@ __all__ = [
|
|
import bz2
|
|
import six
|
|
import datetime
|
|
-import dbus
|
|
+from pydbus import SystemBus
|
|
import glob
|
|
from gi.repository import GObject
|
|
import os
|
|
@@ -484,18 +484,9 @@ Finds an SELinux module which defines given SELinux context
|
|
|
|
"""
|
|
if use_dbus:
|
|
- bus = dbus.SystemBus()
|
|
-
|
|
- try:
|
|
- remote_object = bus.get_object("org.fedoraproject.SetroubleshootPrivileged",
|
|
- "/org/fedoraproject/SetroubleshootPrivileged/object")
|
|
-
|
|
- return str(remote_object.get_rpm_nvr_by_scontext(str(scontext),
|
|
- dbus_interface = "org.fedoraproject.SetroubleshootPrivileged"))
|
|
- except dbus.DBusException:
|
|
- from traceback import print_exc
|
|
- print_exc()
|
|
- return None
|
|
+ bus = SystemBus()
|
|
+ remote_object = bus.get("org.fedoraproject.SetroubleshootPrivileged")
|
|
+ return str(remote_object.get_rpm_nvr_by_scontext(str(scontext)))
|
|
else:
|
|
context = selinux.context_new(str(scontext))
|
|
return get_rpm_nvr_by_type(str(selinux.context_type_get(context)))
|
|
--
|
|
2.25.1
|
|
|