From nobody Sun Feb 8 03:57:56 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=1568219324; cv=none; d=zoho.com; s=zohoarc; b=dzixl2Zi/lS+Vjshf5zDfYr4iX7goaH7xkTLzPs+cLBKOtvm9zrxN5wNfKgvrztlgklFUcFPg0se6o7AhI0IIX3Vpdl5MCbOG0B1H7qCECz0mIt+zhHVkmphlDwAw1/nSVc9/QEX9wUA3yng0+LEYFmgZC4XNzKAVpYvXMgz8IM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568219324; 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=AIVAfthXEtA3Z9d6b+Wd/7JIwgOT38/fHkhTTaY0NQY=; b=OOvf33k6lH9at4giJ58O3Bq9rpZf1qWBiBTkHMx1jQ6/AV0qKo7YG+fE8ypLVp3G64QsvhC8gRF0Dgm+OBPk5YsdMS7loWn+IKOLUWcbxmxmP7OTVjy3dexED/vdIJN0Wj1RLy88rA3GwzczHvBdy6NWN+JfcpPvPP6WdZiLZUQ= 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 1568219324734408.9302541141278; Wed, 11 Sep 2019 09:28:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82F043098215; Wed, 11 Sep 2019 16:28:42 +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 1A96A1001959; Wed, 11 Sep 2019 16:28:42 +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 CD5661806B09; Wed, 11 Sep 2019 16:28:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8BGSTsA013225 for ; Wed, 11 Sep 2019 12:28:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7A417601B3; Wed, 11 Sep 2019 16:28:29 +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 DE91E6017E; Wed, 11 Sep 2019 16:28:26 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 11 Sep 2019 17:23:27 +0100 Message-Id: <20190911162333.8668-19-berrange@redhat.com> In-Reply-To: <20190911162333.8668-1-berrange@redhat.com> References: <20190911162333.8668-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 18/24] 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 11 Sep 2019 16:28:43 +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 | 6 +- src/access/genpolkit.pl | 119 ------------------------------------- src/access/genpolkit.py | 119 +++++++++++++++++++++++++++++++++++++ 3 files changed, 122 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..5f3648aa6b 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,8 @@ 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..5a70200f87 --- /dev/null +++ b/src/access/genpolkit.py @@ -0,0 +1,119 @@ +#!/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 syst= ems +# +# 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|_)+),''' % ob= jectstr, 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