SELinux Archive mirror
 help / color / mirror / Atom feed
From: James Carter <jwcart2@gmail.com>
To: Ondrej Mosnacek <omosnace@redhat.com>
Cc: Petr Lautrbach <lautrbach@redhat.com>, selinux@vger.kernel.org
Subject: Re: [PATCH v2] sepolicy: port to dnf4 python API
Date: Wed, 6 Dec 2023 15:55:39 -0500	[thread overview]
Message-ID: <CAP+JOzTYDgrF-5BcxBNaRGpGykpkdX8WRi0JroqksCG9+vpdAg@mail.gmail.com> (raw)
In-Reply-To: <CAFqZXNtbOW6n_UptZXNLS1LUwPuHd7ezMTnJO-ysbJHDz-pAXg@mail.gmail.com>

On Tue, Nov 28, 2023 at 10:02 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
>
> On Wed, Nov 22, 2023 at 12:31 PM Petr Lautrbach <lautrbach@redhat.com> wrote:
> >
> > 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 <lautrbach@redhat.com>
> > ---
> >
> > v2: use with dnf.Base() as base:  suggested by Ondrej Mosnacek <omosnace@redhat.com>
>
> For the fix:
>
> Acked-by: Ondrej Mosnacek <omosnace@redhat.com>
>
> (I didn't review the full patch, but Jim's v1 ack should still apply
> to the rest.)
>

This has now been merged.
Thanks,
Jim

> >
> >  python/sepolicy/sepolicy/generate.py | 56 +++++++++++++---------------
> >  1 file changed, 25 insertions(+), 31 deletions(-)
> >
> > diff --git a/python/sepolicy/sepolicy/generate.py b/python/sepolicy/sepolicy/generate.py
> > index b6df3e91160b..adf65f27a822 100644
> > --- a/python/sepolicy/sepolicy/generate.py
> > +++ b/python/sepolicy/sepolicy/generate.py
> > @@ -1262,24 +1262,20 @@ allow %s_t %s_t:%s_socket name_%s;
> >          return fcfile
> >
> >      def __extract_rpms(self):
> > -        import yum
> > -        yb = yum.YumBase()
> > -        yb.setCacheDir()
> > -
> > -        for pkg in yb.rpmdb.searchProvides(self.program):
> > -            self.rpms.append(pkg.name)
> > -            for fname in pkg.dirlist + pkg.filelist + pkg.ghostlist:
> > -                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)
> > +        import dnf
> > +
> > +        with dnf.Base() as base:
> > +            base.read_all_repos()
> > +            base.fill_sack(load_system_repo=True)
> > +
> > +            query = base.sack.query()
> >
> > -            for bpkg in yb.rpmdb.searchNames([pkg.base_package_name]):
> > -                for fname in bpkg.dirlist + bpkg.filelist + bpkg.ghostlist:
> > +            pq = query.available()
> > +            pq = pq.filter(file=self.program)
> > +
> > +            for pkg in pq:
> > +                self.rpms.append(pkg.name)
> > +                for fname in pkg.files:
> >                      for b in self.DEFAULT_DIRS:
> >                          if b == "/etc":
> >                              continue
> > @@ -1288,20 +1284,18 @@ allow %s_t %s_t:%s_socket name_%s;
> >                                  self.add_file(fname)
> >                              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)
> > +                sq = query.available()
> > +                sq = sq.filter(provides=pkg.source_name)
> > +                for bpkg in sq:
> > +                    for fname in bpkg.files:
> > +                        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:
> > --
> > 2.41.0
> >
>
> --
> Ondrej Mosnacek
> Senior Software Engineer, Linux Security - SELinux kernel
> Red Hat, Inc.
>
>

      reply	other threads:[~2023-12-06 20:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-20 16:05 [PATCH] sepolicy: port to dnf4 python API Petr Lautrbach
2023-11-20 20:59 ` James Carter
2023-11-21  9:57 ` Ondrej Mosnacek
2023-11-22 11:29   ` [PATCH v2] " Petr Lautrbach
2023-11-28 15:01     ` Ondrej Mosnacek
2023-12-06 20:55       ` James Carter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAP+JOzTYDgrF-5BcxBNaRGpGykpkdX8WRi0JroqksCG9+vpdAg@mail.gmail.com \
    --to=jwcart2@gmail.com \
    --cc=lautrbach@redhat.com \
    --cc=omosnace@redhat.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).