From nobody Sun Feb 8 14:51:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569337493; cv=none; d=zoho.com; s=zohoarc; b=OjKP2v0RRfGkZkdAjNJc3PC3n4/7IhicK2O7wdX67E9jyx2oU3/4BSgMpTPC0InhqcaUFUrgqKyfBVNrK2LyUYdDy2kaiueGgZGosl4YBxQSaeacft+vAuEyqbLNQlKYozXddi6ep++MZIVKu3MkKxgkxEUBKHAUuxu5aINlAWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569337493; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Yr4yzEcr9O+5ak1wGiCO4/LbcSZ3uWCnQU1eRHMuFQI=; b=MxkB0tbqkLhmjc184fMBOBtbOeMsVRUXZKV6CgICQJdAlUOch5SJnbRSdjI+zYeRHU9NFyfWil0EtkyKAM/52zQqPbiuvBW8HRdQDWVP9Io56d/A4M2gJM0i2kLS4Tyrlc0on9i9lxP6JSTBCZyi6DXRd9Ubq4xustMGCzbiSyY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1569337493178432.60759270756034; Tue, 24 Sep 2019 08:04:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B7E83086E25; Tue, 24 Sep 2019 15:04:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 564A0608C0; Tue, 24 Sep 2019 15:04:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 11F56180BAA5; Tue, 24 Sep 2019 15:04:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8OF4ktx028002 for ; Tue, 24 Sep 2019 11:04:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 608FD5DD78; Tue, 24 Sep 2019 15:04:46 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (dhcp-32.gsslab.fab.redhat.com [10.33.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id C393D5DC1B; Tue, 24 Sep 2019 15:04:45 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 24 Sep 2019 15:58:57 +0100 Message-Id: <20190924145903.17123-17-berrange@redhat.com> In-Reply-To: <20190924145903.17123-1-berrange@redhat.com> References: <20190924145903.17123-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 16/22] src: rewrite polkit ACL generator in Python X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 24 Sep 2019 15:04:51 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the genpolkit.pl tool in Python. This was a straight conversion, manually going line-by-line to change the syntax from Perl to Python. Thus the overall structure of the file and approach is the same. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/access/Makefile.inc.am | 7 ++- src/access/genpolkit.pl | 119 ------------------------------------ src/access/genpolkit.py | 122 +++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 122 deletions(-) delete mode 100755 src/access/genpolkit.pl create mode 100755 src/access/genpolkit.py diff --git a/src/access/Makefile.inc.am b/src/access/Makefile.inc.am index 4dc742f4e5..1550cce720 100644 --- a/src/access/Makefile.inc.am +++ b/src/access/Makefile.inc.am @@ -44,7 +44,7 @@ GENERATED_SYM_FILES +=3D $(ACCESS_DRIVER_SYM_FILES) =20 EXTRA_DIST +=3D \ $(ACCESS_DRIVER_POLKIT_POLICY) \ - access/genpolkit.pl \ + access/genpolkit.py \ $(NULL) =20 =20 @@ -63,8 +63,9 @@ libvirt_driver_access_la_LIBADD =3D =20 =20 $(ACCESS_DRIVER_POLKIT_POLICY): $(srcdir)/access/viraccessperm.h \ - $(srcdir)/access/genpolkit.pl Makefile.am - $(AM_V_GEN)$(PERL) $(srcdir)/access/genpolkit.pl < $< > $@ || rm -f $@ + $(srcdir)/access/genpolkit.py Makefile.am + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) \ + $(srcdir)/access/genpolkit.py $< > $@ || rm -f $@ =20 if WITH_POLKIT libvirt_driver_access_la_SOURCES +=3D $(ACCESS_DRIVER_POLKIT_SOURCES) diff --git a/src/access/genpolkit.pl b/src/access/genpolkit.pl deleted file mode 100755 index f8f20caf65..0000000000 --- a/src/access/genpolkit.pl +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env perl -# -# Copyright (C) 2012-2013 Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library. If not, see -# . -# - -use strict; -use warnings; - -my @objects =3D ( - "CONNECT", "DOMAIN", "INTERFACE", "NETWORK_PORT", - "NETWORK","NODE_DEVICE", "NWFILTER_BINDING", "NWFILTER", - "SECRET", "STORAGE_POOL", "STORAGE_VOL", - ); - -my $objects =3D join ("|", @objects); - -# Data we're going to be generating looks like this -# -# -# -# Monitor local virtualized systems -# System policy prevents monitoring of local virtualized syst= ems -# -# yes -# yes -# yes -# -# -# ...more rules... -# - -my %opts; -my $in_opts =3D 0; - -my %perms; - -while (<>) { - if ($in_opts) { - if (m,\*/,) { - $in_opts =3D 0; - } elsif (/\*\s*\@(\w+):\s*(.*?)\s*$/) { - $opts{$1} =3D $2; - } - } elsif (m,/\*\*,) { - $in_opts =3D 1; - } elsif (/VIR_ACCESS_PERM_($objects)_((?:\w|_)+),/) { - my $object =3D lc $1; - my $perm =3D lc $2; - next if $perm eq "last"; - - $object =3D~ s/_/-/g; - $perm =3D~ s/_/-/g; - - $perms{$object} =3D {} unless exists $perms{$object}; - $perms{$object}->{$perm} =3D { - desc =3D> $opts{desc}, - message =3D> $opts{message}, - anonymous =3D> $opts{anonymous} - }; - %opts =3D (); - } -} - -print < - - - Libvirt Project - https://libvirt.org -EOF - -foreach my $object (sort { $a cmp $b } keys %perms) { - foreach my $perm (sort { $a cmp $b } keys %{$perms{$object}}) { - my $description =3D $perms{$object}->{$perm}->{desc}; - my $message =3D $perms{$object}->{$perm}->{message}; - my $anonymous =3D $perms{$object}->{$perm}->{anonymous}; - - die "missing description for $object.$perm" unless - defined $description; - die "missing message for $object.$perm" unless - defined $message; - - my $allow_any =3D $anonymous ? "yes" : "no"; - my $allow_inactive =3D $allow_any; - my $allow_active =3D $allow_any; - - print < - $description - $message - - $allow_any - $allow_inactive - $allow_active - - -EOF - - } -} - -print < -EOF diff --git a/src/access/genpolkit.py b/src/access/genpolkit.py new file mode 100755 index 0000000000..04628d2d6a --- /dev/null +++ b/src/access/genpolkit.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +# +# Copyright (C) 2012-2019 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# . +# + +from __future__ import print_function + +import re +import sys + +objects =3D [ + "CONNECT", "DOMAIN", "INTERFACE", "NETWORK_PORT", + "NETWORK", "NODE_DEVICE", "NWFILTER_BINDING", + "NWFILTER", "SECRET", "STORAGE_POOL", "STORAGE_VOL", +] + +objectstr =3D "|".join(objects) + +# Data we're going to be generating looks like this +# +# +# +# Monitor local virtualized systems +# System policy prevents monitoring of +# local virtualized systems +# +# yes +# yes +# yes +# +# +# ...more rules... +# + +opts =3D {} +in_opts =3D False + +perms =3D {} + +aclfile =3D sys.argv[1] +with open(aclfile, "r") as fh: + for line in fh: + if in_opts: + if line.find("*/") !=3D -1: + in_opts =3D False + else: + m =3D re.match(r'''.*\*\s*\@(\w+):\s*(.*?)\s*$''', line) + if m is not None: + opts[m.group(1)] =3D m.group(2) + elif line.find("**") !=3D -1: + in_opts =3D True + else: + m =3D re.match(r'''.*VIR_ACCESS_PERM_(%s)_((?:\w|_)+),''' % + objectstr, line) + if m is not None: + obj =3D m.group(1).lower() + perm =3D m.group(2).lower() + if perm =3D=3D "last": + continue + + obj =3D obj.replace("_", "-") + perm =3D perm.replace("_", "-") + + if obj not in perms: + perms[obj] =3D {} + perms[obj][perm] =3D { + "desc": opts.get("desc", None), + "message": opts.get("message", None), + "anonymous": opts.get("anonymous", None), + } + opts =3D {} + +print('') +print('') +print('') +print(' Libvirt Project') +print(' https://libvirt.org') + +for obj in sorted(perms.keys()): + for perm in sorted(perms[obj].keys()): + description =3D perms[obj][perm]["desc"] + message =3D perms[obj][perm]["message"] + anonymous =3D perms[obj][perm]["anonymous"] + + if description is None: + raise Exception("missing description for %s.%s" % (obj, perm)) + if message is None: + raise Exception("missing message for %s.%s" % (obj, perm)) + + allow_any =3D "no" + if anonymous: + allow_any =3D "yes" + allow_inactive =3D allow_any + allow_active =3D allow_any + + print(' ' % (obj, perm)) + print(' %s' % description) + print(' %s' % message) + print(' ') + print(' %s' % allow_any) + print(' %s' % allow_inactive) + print(' %s' % allow_active) + print(' ') + print(' ') + +print('') --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list