From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D99649AB00 for ; Fri, 17 Nov 2023 16:29:54 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B405736285 for ; Fri, 17 Nov 2023 16:29:24 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 17 Nov 2023 16:29:24 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id BFBB643EB9 for ; Fri, 17 Nov 2023 16:29:23 +0100 (CET) Date: Fri, 17 Nov 2023 16:29:22 +0100 (CET) From: =?UTF-8?Q?Fabian_Gr=C3=BCnbichler?= To: Wolfgang Bumiller Cc: pve-devel@lists.proxmox.com Message-ID: <1066010498.4111.1700234962992@webmail.proxmox.com> In-Reply-To: References: <20231116153128.788593-1-f.gruenbichler@proxmox.com> <20231116153128.788593-3-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.6-Rev54 X-Originating-Client: open-xchange-appsuite X-SPAM-LEVEL: Spam detection results: 0 AWL 0.066 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH access-control 2/2] pools: record parent/subpool information X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Nov 2023 15:29:54 -0000 > Wolfgang Bumiller hat am 17.11.2023 11:10 CET ge= schrieben: >=20 > =20 > On Thu, Nov 16, 2023 at 04:31:26PM +0100, Fabian Gr=C3=BCnbichler wrote: > > and ensure a missing intermediate pool exists at all times. > >=20 > > Signed-off-by: Fabian Gr=C3=BCnbichler > > --- > >=20 > > Notes: > > a "missing link" should never happen when modifying via the API (bo= th deletion > > with children and addition without the parent existing is blocked t= here), but > > it could happen when manually editing the config. > >=20 > > src/PVE/AccessControl.pm | 14 +++++++++++++- > > src/test/parser_writer.pl | 4 ++++ > > 2 files changed, 17 insertions(+), 1 deletion(-) > >=20 > > diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm > > index d9ae611..e33f844 100644 > > --- a/src/PVE/AccessControl.pm > > +++ b/src/PVE/AccessControl.pm > > @@ -1529,7 +1529,19 @@ sub parse_user_config { > > =09 } > > =20 > > =09 # make sure to add the pool (even if there are no members) > > -=09 $cfg->{pools}->{$pool} =3D { vms =3D> {}, storage =3D> {} } if = !$cfg->{pools}->{$pool}; > > +=09 $cfg->{pools}->{$pool} =3D { vms =3D> {}, storage =3D> {}, pool= s =3D> {} } if !$cfg->{pools}->{$pool}; > > + > > +=09 if ($pool =3D~ m!/!) { > > +=09=09my $curr =3D $pool; > > +=09=09while ($curr =3D~ m!^(.*)/[^/]+$!) { >=20 > I wonder if we should use `.+` instead of `.*`. > This way it would work the same even with a leading slash. > That said, we don't allow leading slashes and there's a verify_poolname > further up in the function so it doesn't really matter much. > We just need to be careful that we never allow/introduce leading slashes > anywhere, otherwise this runs with a final iteration where $parent is an > empty string. ack. > > +=09=09 # ensure nested pool info is correctly recorded > > +=09=09 my $parent =3D $1; > > +=09=09 $cfg->{pools}->{$curr}->{parent} =3D $parent; > > +=09=09 $cfg->{pools}->{$parent} =3D { vms =3D> {}, storage =3D> {},= pools =3D> {} } if !$cfg->{pools}->{$parent}; >=20 > (could use //=3D instead of the suffix if, IMO a bit easier to read (and > doesn't break the 100 char limit :p) that style is used across the whole parser here, I am always a bit hesitant= to mix styles within a sub as IMHO that makes it harder to parse. move the post-if to its own line, and optional follow-up to convert the who= le parser to drop post ifs for initialization? ;)