92 lines
2.8 KiB
Diff
92 lines
2.8 KiB
Diff
|
From 72de472c510e6e3d50c72efbd1e1fd291ed35b68 Mon Sep 17 00:00:00 2001
|
||
|
From: Petr Lautrbach <plautrba@redhat.com>
|
||
|
Date: Tue, 25 Feb 2020 10:29:55 +0100
|
||
|
Subject: [PATCH] setroubleshoot.utils.get_rpm_nvr_by_scontext add option to
|
||
|
use DBUS method
|
||
|
|
||
|
Using keyword `use_dbus=True`:
|
||
|
|
||
|
get_rpm_nvr_by_scontext("system_u:system_r:timedatex_t:s0", use_dbus=True)
|
||
|
|
||
|
the function calls org.fedoraproject.SetroubleshootPrivileged.get_rpm_nvr_by_scontext
|
||
|
DBUS method in order to get data using privileged process.
|
||
|
---
|
||
|
framework/src/setroubleshoot/util.py | 33 ++++++++++++++++++++--------
|
||
|
1 file changed, 24 insertions(+), 9 deletions(-)
|
||
|
|
||
|
diff --git a/framework/src/setroubleshoot/util.py b/framework/src/setroubleshoot/util.py
|
||
|
index a69269113236..94bb988564ed 100755
|
||
|
--- a/framework/src/setroubleshoot/util.py
|
||
|
+++ b/framework/src/setroubleshoot/util.py
|
||
|
@@ -67,6 +67,7 @@ __all__ = [
|
||
|
import bz2
|
||
|
import six
|
||
|
import datetime
|
||
|
+import dbus
|
||
|
import glob
|
||
|
from gi.repository import GObject
|
||
|
import os
|
||
|
@@ -423,10 +424,10 @@ Finds an SELinux module which defines given SELinux type
|
||
|
##### usage
|
||
|
|
||
|
>>> get_rpm_nvr_by_type("sshd_t")
|
||
|
-selinux-policy-
|
||
|
+'selinux-policy-...
|
||
|
|
||
|
>>> get_rpm_nvr_by_type("mysqld_log_t")
|
||
|
-mysqld-selinux
|
||
|
+'mysql-selinux-...
|
||
|
|
||
|
"""
|
||
|
retval, policytype = selinux.selinux_getpolicytype()
|
||
|
@@ -457,7 +458,7 @@ mysqld-selinux
|
||
|
|
||
|
return None
|
||
|
|
||
|
-def get_rpm_nvr_by_scontext(scontext):
|
||
|
+def get_rpm_nvr_by_scontext(scontext, use_dbus=False):
|
||
|
"""
|
||
|
Finds an SELinux module which defines given SELinux context
|
||
|
|
||
|
@@ -472,17 +473,31 @@ Finds an SELinux module which defines given SELinux context
|
||
|
##### usage
|
||
|
|
||
|
>>> get_rpm_nvr_by_scontext("system_u:system_r:syslogd_t:s0")
|
||
|
-selinux-policy-
|
||
|
+'selinux-policy-...
|
||
|
|
||
|
>>> get_rpm_nvr_by_scontext("system_u:system_r:mysqld_log_t:s0")
|
||
|
-mysqld-selinux-
|
||
|
+'mysql-selinux-...
|
||
|
|
||
|
->>> get_rpm_nvr_by_scontext("system_u:system_r:timedatex_t:s0")
|
||
|
-selinux-policy-
|
||
|
+>>> get_rpm_nvr_by_scontext("system_u:system_r:timedatex_t:s0", use_dbus=True)
|
||
|
+'selinux-policy-...
|
||
|
|
||
|
"""
|
||
|
- context = selinux.context_new(str(scontext))
|
||
|
- return get_rpm_nvr_by_type(str(selinux.context_type_get(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
|
||
|
+ else:
|
||
|
+ context = selinux.context_new(str(scontext))
|
||
|
+ return get_rpm_nvr_by_type(str(selinux.context_type_get(context)))
|
||
|
|
||
|
def get_user_home_dir():
|
||
|
uid = os.getuid()
|
||
|
--
|
||
|
2.25.1
|
||
|
|