From a9a1d1b99c30208006a86474c19ab288c933afb6 Mon Sep 17 00:00:00 2001 From: Petr Lautrbach Date: Tue, 25 Feb 2020 13:00:10 +0100 Subject: [PATCH] Report bug on a package which owns the related SELinux domain --- framework/src/setroubleshoot/browser.py | 3 ++- framework/src/setroubleshoot/util.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/framework/src/setroubleshoot/browser.py b/framework/src/setroubleshoot/browser.py index 22ffd132d9a2..4b1c143fac9a 100644 --- a/framework/src/setroubleshoot/browser.py +++ b/framework/src/setroubleshoot/browser.py @@ -997,7 +997,8 @@ class BugReport: text_buf = self.error_submit_text.get_buffer() content = text_buf.get_text(text_buf.get_start_iter(), text_buf.get_end_iter(), False) - signature = report.createAlertSignature("selinux-policy", + local_policy_package = get_rpm_source_package(self.alert.environment.local_policy_rpm) + signature = report.createAlertSignature(local_policy_package, "setroubleshoot", self.alert.get_hash(), self.summary, diff --git a/framework/src/setroubleshoot/util.py b/framework/src/setroubleshoot/util.py index 94bb988564ed..77b3668afa86 100755 --- a/framework/src/setroubleshoot/util.py +++ b/framework/src/setroubleshoot/util.py @@ -37,6 +37,7 @@ __all__ = [ 'get_rpm_nvr_by_file_path', 'get_rpm_nvr_by_type', 'get_rpm_nvr_by_scontext', + 'get_rpm_source_package', 'is_hex', 'split_rpm_nvr', 'file_types', @@ -499,6 +500,29 @@ Finds an SELinux module which defines given SELinux context context = selinux.context_new(str(scontext)) return get_rpm_nvr_by_type(str(selinux.context_type_get(context))) +def get_rpm_source_package(name): + """ + Find a source package for `name` rpm + + >>> get_rpm_source_package("policycoreutils-python-utils") + 'policycoreutils' + + >>> get_rpm_source_package("selinux-policy-targeted") + 'selinux-policy' + + """ + if name is None: + return None + + src = None + try: + import subprocess + src = subprocess.check_output(["rpm", "-q", "--qf", "%{SOURCERPM}", name], universal_newlines=True).rsplit('-',2)[0] + except: + syslog.syslog(syslog.LOG_ERR, "failed to retrieve rpm info for %s" % name) + return src + + def get_user_home_dir(): uid = os.getuid() try: -- 2.25.1