[pve-devel] [PATCH v2 storage 4/6] check volume accesss: add content type parameter
Fabian Ebner
f.ebner at proxmox.com
Wed Mar 30 12:24:31 CEST 2022
Adding such a check here avoids the need to parse at the call sites in
some cases.
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
No changes from v1.
PVE/Storage.pm | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index a864c33..3b86956 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -473,13 +473,18 @@ sub parse_volume_id {
# test if we have read access to volid
sub check_volume_access {
- my ($rpcenv, $user, $cfg, $vmid, $volid) = @_;
+ my ($rpcenv, $user, $cfg, $vmid, $volid, $type) = @_;
my ($sid, $volname) = parse_volume_id($volid, 1);
if ($sid) {
+ my ($vtype, undef, $ownervm) = parse_volname($cfg, $volid);
+
+ # Need to allow 'images' when expecting 'rootdir' too - not cleanly separated in plugins.
+ die "unable to use volume $volid - content type needs to be '$type'\n"
+ if defined($type) && $vtype ne $type && ($type ne 'rootdir' || $vtype ne 'images');
+
return if $rpcenv->check($user, "/storage/$sid", ['Datastore.Allocate'], 1);
- my ($vtype, undef, $ownervm) = parse_volname($cfg, $volid);
if ($vtype eq 'iso' || $vtype eq 'vztmpl') {
# require at least read access to storage, (custom) templates/ISOs could be sensitive
$rpcenv->check_any($user, "/storage/$sid", ['Datastore.AllocateSpace', 'Datastore.Audit']);
--
2.30.2
More information about the pve-devel
mailing list