From: Fabian Grünbichler Date: Mon, 20 Nov 2023 07:22:40 +0000 (+0100) Subject: pools: record parent/subpool information X-Git-Url: https://git.proxmox.com/?p=pve-access-control.git;a=commitdiff_plain;h=4418b06b351011405fb13140f3c71bfcff109e95 pools: record parent/subpool information and ensure a missing intermediate pool exists at all times. Signed-off-by: Fabian Grünbichler --- diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm index 4e3b077..461a64e 100644 --- a/src/PVE/AccessControl.pm +++ b/src/PVE/AccessControl.pm @@ -1529,7 +1529,21 @@ sub parse_user_config { } # make sure to add the pool (even if there are no members) - $cfg->{pools}->{$pool} = { vms => {}, storage => {} } if !$cfg->{pools}->{$pool}; + $cfg->{pools}->{$pool} = { vms => {}, storage => {}, pools => {} } + if !$cfg->{pools}->{$pool}; + + if ($pool =~ m!/!) { + my $curr = $pool; + while ($curr =~ m!^(.+)/[^/]+$!) { + # ensure nested pool info is correctly recorded + my $parent = $1; + $cfg->{pools}->{$curr}->{parent} = $parent; + $cfg->{pools}->{$parent} = { vms => {}, storage => {}, pools => {} } + if !$cfg->{pools}->{$parent}; + $cfg->{pools}->{$parent}->{pools}->{$curr} = 1; + $curr = $parent; + } + } $cfg->{pools}->{$pool}->{comment} = PVE::Tools::decode_text($comment) if $comment; diff --git a/src/test/parser_writer.pl b/src/test/parser_writer.pl index 65a70eb..80c346b 100755 --- a/src/test/parser_writer.pl +++ b/src/test/parser_writer.pl @@ -237,21 +237,25 @@ my $default_cfg = { 'id' => 'testpool', vms => {}, storage => {}, + pools => {}, }, test_pool_members => { 'id' => 'testpool', vms => { 123 => 1, 1234 => 1}, storage => { 'local' => 1, 'local-zfs' => 1}, + pools => {}, }, test_pool_duplicate_vms => { 'id' => 'test_duplicate_vms', vms => {}, storage => {}, + pools => {}, }, test_pool_duplicate_storages => { 'id' => 'test_duplicate_storages', vms => {}, storage => { 'local' => 1, 'local-zfs' => 1}, + pools => {}, }, acl_simple_user => { 'path' => '/',