setroubleshoot-3.3.32-6

- 'imp' module is deprecated in favor of 'importlib' (rhbz#2224393)
This commit is contained in:
Petr Lautrbach 2023-07-25 11:21:16 +02:00
parent 95d38b7207
commit 47767e1756
5 changed files with 77 additions and 188 deletions

View File

@ -0,0 +1,71 @@
From 2f9e575333af7c7798956f211c29a46a338155e5 Mon Sep 17 00:00:00 2001
From: Petr Lautrbach <lautrbach@redhat.com>
Date: Mon, 24 Jul 2023 17:33:17 +0200
Subject: [PATCH] 'imp' module is deprecated in favor of 'importlib'
Content-type: text/plain
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2224393
---
src/setroubleshoot/util.py | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/src/setroubleshoot/util.py b/src/setroubleshoot/util.py
index 0e02f12de682..828a598ef1c2 100755
--- a/src/setroubleshoot/util.py
+++ b/src/setroubleshoot/util.py
@@ -73,6 +73,7 @@ import datetime
from dasbus.connection import SystemMessageBus
import glob
from gi.repository import GObject
+import importlib
import os
import pwd
import re
@@ -771,37 +772,26 @@ def load_plugins(filter_glob=None):
# load the parent (e.g. the package containing the submodules), required for python 2.5 and above
module_name = plugin_base
- plugin_name = '__init__'
if module_name not in sys.modules:
try:
- import imp
- mod_fp, mod_path, mod_description = imp.find_module(plugin_name, [plugin_dir])
- mod = imp.load_module(module_name, mod_fp, mod_path, mod_description)
+ mod_spec = importlib.util.spec_from_file_location(plugin_base, plugin_dir + "/__init__.py")
+ mod = importlib.util.module_from_spec(mod_spec)
+ mod_spec.loader.exec_module(mod)
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "failed to initialize plugins in %s: %s" % (plugin_dir, str(e)))
return []
- if mod_fp:
- mod_fp.close()
-
for plugin_name in plugin_names:
module_name = "%s.%s" % (plugin_base, plugin_name)
- mod = sys.modules.get(module_name)
- if mod is not None:
- log_debug("load_plugins() %s previously imported" % module_name)
- plugins.append(mod.plugin())
- continue
+
try:
- import imp
- mod_fp, mod_path, mod_description = imp.find_module(plugin_name, [plugin_dir])
- mod = imp.load_module(module_name, mod_fp, mod_path, mod_description)
+ mod_spec = importlib.util.spec_from_file_location(module_name, plugin_dir + "/" + plugin_name + ".py")
+ mod = importlib.util.module_from_spec(mod_spec)
+ mod_spec.loader.exec_module(mod)
plugins.append(mod.plugin())
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "failed to load %s plugin: %s" % (plugin_name, str(e)))
- if mod_fp:
- mod_fp.close()
-
plugins.sort(key=cmp_to_key(sort_plugins))
return plugins
--
2.41.0

View File

@ -1,95 +0,0 @@
From def9fd0c22e43e437f867eb1f4bafc7c4a68898b Mon Sep 17 00:00:00 2001
From: Petr Lautrbach <plautrba@redhat.com>
Date: Tue, 18 Jan 2022 11:59:40 +0100
Subject: [PATCH] util.py: Improve doctest tests
Usage:
# python3 -m doctest -v src/setroubleshoot/util.py
---
src/setroubleshoot/util.py | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/setroubleshoot/util.py b/src/setroubleshoot/util.py
index 02c4f752e690..de10c7319138 100755
--- a/src/setroubleshoot/util.py
+++ b/src/setroubleshoot/util.py
@@ -321,7 +321,7 @@ def default_date_text(date):
def get_standard_directories():
"""
->>> get_standard_directories()
+>>> get_standard_directories() # doctest: +ELLIPSIS
[...'/bin'...]
"""
lst = []
@@ -347,8 +347,8 @@ def get_rpm_nvr_from_header(hdr):
def get_package_nvr_by_name(name):
"""
->>> get_package_nvr_by_name("coreutils")
-'coreutils-8.30-3+b1:amd64'
+>>> get_package_nvr_by_name("coreutils")[0:9]
+'coreutils'
"""
if name is None:
return None
@@ -369,8 +369,8 @@ def get_package_nvr_by_name(name):
def get_package_nvr_by_file_path(name):
"""
->>> get_package_nvr_by_file_path("/bin/ls")
-'coreutils-8.30-3+b1:amd64'
+>>> get_package_nvr_by_file_path("/bin/ls")[0:9]
+'coreutils'
"""
if name is None:
return None
@@ -424,11 +424,11 @@ Finds an SELinux module which defines given SELinux type
##### usage
->>> get_rpm_nvr_by_type("sshd_t")
-'selinux-policy-...
+>>> get_rpm_nvr_by_type("sshd_t")[0:14]
+'selinux-policy'
->>> get_rpm_nvr_by_type("mysqld_log_t")
-'mysql-selinux-...
+>>> get_rpm_nvr_by_type("mysqld_log_t")[0:13]
+'mysql-selinux'
"""
@@ -511,14 +511,14 @@ Finds an SELinux module which defines given SELinux context
##### usage
->>> get_rpm_nvr_by_scontext("system_u:system_r:syslogd_t:s0")
-'selinux-policy-...
+>>> get_rpm_nvr_by_scontext("system_u:system_r:syslogd_t:s0")[0:14]
+'selinux-policy'
->>> get_rpm_nvr_by_scontext("system_u:system_r:mysqld_log_t:s0")
-'mysql-selinux-...
+>>> get_rpm_nvr_by_scontext("system_u:system_r:mysqld_log_t:s0")[0:13]
+'mysql-selinux'
->>> get_rpm_nvr_by_scontext("system_u:system_r:timedatex_t:s0", use_dbus=True)
-'selinux-policy-...
+>>> get_rpm_nvr_by_scontext("system_u:system_r:timedatex_t:s0", use_dbus=True)[0:14]
+'selinux-policy'
"""
if use_dbus:
@@ -542,6 +542,8 @@ def get_rpm_source_package(name):
>>> get_rpm_source_package("selinux-policy-targeted")
'selinux-policy'
+ >>> get_rpm_source_package("selinux-policy-targeted-35.8-1.fc35.noarch")
+ 'selinux-policy'
"""
if name is None:
return None
--
2.34.1

View File

@ -1,54 +0,0 @@
From 93a63babd44e8fc7652b4e6c3c078133f234310f Mon Sep 17 00:00:00 2001
From: Petr Lautrbach <plautrba@redhat.com>
Date: Tue, 18 Jan 2022 15:59:09 +0100
Subject: [PATCH] Look for modules in /usr/share/selinux/packages
Not all packages shipping SELinux modules own their directory in
/var/lib/selinux/... Some of them own just .pp.bz2 file in
/usr/share/selinux/packages. Lets look there when we try to detect the
right component for the report.
---
src/setroubleshoot/util.py | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/setroubleshoot/util.py b/src/setroubleshoot/util.py
index de10c7319138..1405bb84c342 100755
--- a/src/setroubleshoot/util.py
+++ b/src/setroubleshoot/util.py
@@ -430,6 +430,9 @@ Finds an SELinux module which defines given SELinux type
>>> get_rpm_nvr_by_type("mysqld_log_t")[0:13]
'mysql-selinux'
+>>> get_rpm_nvr_by_type("spc_t")[0:17]
+'container-selinux'
+
"""
if module_type_cache is None:
@@ -439,7 +442,22 @@ Finds an SELinux module which defines given SELinux type
path = module_type_cache.get(selinux_type, None)
- return get_package_nvr_by_file_path(path)
+ if path is None:
+ return None
+
+ package = get_package_nvr_by_file_path(path)
+
+ if package is None:
+ module_name = path.split('/')[-1]
+ path = '/usr/share/selinux/packages/' + module_name + '.pp'
+ package = get_package_nvr_by_file_path(path)
+ if package is None:
+ path += '.bz2'
+ package = get_package_nvr_by_file_path(path)
+
+ return package
+
+
# check if given string represents an integer
def __str_is_int(str):
--
2.34.1

View File

@ -1,37 +0,0 @@
From 2dbf243d535c3b8dca5fa3b4e360ca8c6959f68d Mon Sep 17 00:00:00 2001
From: Petr Lautrbach <plautrba@redhat.com>
Date: Tue, 18 Jan 2022 12:01:03 +0100
Subject: [PATCH] Always use rpm source package for reporting
Originally when a module wasn't owned by any package policy_rpm, e.g.
selinux-policy-targeted..., was used. In Red Hat bugzilla there's no
component selinux-policy-targeted therefore we need to use source
package name when reporting a problem.
Fixes:
fatal: RPC failed at server. There is no component named 'selinux-policy-targeted-35.8-1.fc35.noarch' in the 'Fedora' product.
---
src/setroubleshoot/browser.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/setroubleshoot/browser.py b/src/setroubleshoot/browser.py
index 3203f75e0c17..48015834fe57 100644
--- a/src/setroubleshoot/browser.py
+++ b/src/setroubleshoot/browser.py
@@ -1002,9 +1002,10 @@ 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)
- local_policy_package = get_rpm_source_package(self.alert.environment.local_policy_rpm)
- if local_policy_package is None:
- local_policy_package = self.alert.environment.policy_rpm
+ local_policy_rpm = self.alert.environment.local_policy_rpm
+ if not local_policy_rpm:
+ local_policy_rpm = self.alert.environment.policy_rpm
+ local_policy_package = get_rpm_source_package(local_policy_rpm)
signature = report.createAlertSignature(str(local_policy_package),
"setroubleshoot",
self.alert.get_hash(),
--
2.34.1

View File

@ -4,14 +4,15 @@
Summary: Helps troubleshoot SELinux problems Summary: Helps troubleshoot SELinux problems
Name: setroubleshoot Name: setroubleshoot
Version: 3.3.32 Version: 3.3.32
Release: 5%{?dist} Release: 6%{?dist}
License: GPL-2.0-or-later License: GPL-2.0-or-later
URL: https://gitlab.com/setroubleshoot/setroubleshoot URL: https://gitlab.com/setroubleshoot/setroubleshoot
Source0: https://gitlab.com/setroubleshoot/setroubleshoot/-/archive/%{version}/setroubleshoot-%{version}.tar.gz Source0: https://gitlab.com/setroubleshoot/setroubleshoot/-/archive/%{version}/setroubleshoot-%{version}.tar.gz
Source1: %{name}.tmpfiles Source1: %{name}.tmpfiles
Source2: %{name}.sysusers Source2: %{name}.sysusers
# git format-patch -N 3.3.30 # git format-patch -N 3.3.32
# i=1; for j in 00*patch; do printf "Patch%04d: %s\n" $i $j; i=$((i+1));done # i=1; for j in 00*patch; do printf "Patch%04d: %s\n" $i $j; i=$((i+1));done
Patch0001: 0001-imp-module-is-deprecated-in-favor-of-importlib.patch
BuildRequires: gcc BuildRequires: gcc
BuildRequires: make BuildRequires: make
BuildRequires: libcap-ng-devel BuildRequires: libcap-ng-devel
@ -191,6 +192,9 @@ to user preference. The same tools can be run on existing log files.
%doc AUTHORS COPYING ChangeLog DBUS.md NEWS README TODO %doc AUTHORS COPYING ChangeLog DBUS.md NEWS README TODO
%changelog %changelog
* Tue Jul 25 2023 Petr Lautrbach <lautrbach@redhat.com> - 3.3.32-6
- 'imp' module is deprecated in favor of 'importlib' (rhbz#2224393)
* Sat Jul 22 2023 Fedora Release Engineering <releng@fedoraproject.org> - 3.3.32-5 * Sat Jul 22 2023 Fedora Release Engineering <releng@fedoraproject.org> - 3.3.32-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild - Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild