Skip to content

Commit

Permalink
sepolicy: port to dnf4 python API
Browse files Browse the repository at this point in the history
yum module is not available since RHEL 7.

Drop -systemd related code as it's obsoleted these days - only 2
packages ship their .service in -systemd subpackage

Signed-off-by: Petr Lautrbach <[email protected]>
  • Loading branch information
bachradsusi committed Jul 29, 2023
1 parent 1d20735 commit 9aecc65
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions python/sepolicy/sepolicy/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,13 +1262,24 @@ def write_fc(self, out_dir):
return fcfile

def __extract_rpms(self):
import yum
yb = yum.YumBase()
yb.setCacheDir()

import dnf

for pkg in yb.rpmdb.searchProvides(self.program):
base = dnf.Base()
base.read_all_repos()
base.fill_sack(load_system_repo=True)

query = base.sack.query()

a = query.available()
a = a.filter(file='/usr/bin/mysqld_safe')

# query = libdnf5.rpm.PackageQuery(base)
# query.filter_file([self.program])

for pkg in a:
self.rpms.append(pkg.name)
for fname in pkg.dirlist + pkg.filelist + pkg.ghostlist:
for fname in pkg.files:
for b in self.DEFAULT_DIRS:
if b == "/etc":
continue
Expand All @@ -1277,9 +1288,10 @@ def __extract_rpms(self):
self.add_file(fname)
else:
self.add_dir(fname)

for bpkg in yb.rpmdb.searchNames([pkg.base_package_name]):
for fname in bpkg.dirlist + bpkg.filelist + bpkg.ghostlist:
b = query.available()
b = b.filter(provides=pkg.source_name)
for bpkg in b:
for fname in bpkg.files:
for b in self.DEFAULT_DIRS:
if b == "/etc":
continue
Expand All @@ -1289,20 +1301,6 @@ def __extract_rpms(self):
else:
self.add_dir(fname)

# some packages have own systemd subpackage
# tor-systemd for example
binary_name = self.program.split("/")[-1]
for bpkg in yb.rpmdb.searchNames(["%s-systemd" % binary_name]):
for fname in bpkg.filelist + bpkg.ghostlist + bpkg.dirlist:
for b in self.DEFAULT_DIRS:
if b == "/etc":
continue
if fname.startswith(b):
if os.path.isfile(fname):
self.add_file(fname)
else:
self.add_dir(fname)

def gen_writeable(self):
try:
self.__extract_rpms()
Expand Down

0 comments on commit 9aecc65

Please sign in to comment.