[pve-devel] [PATCH qemu-server v2 3/3] move vmstate check to check_vm_modify_config_perm

Dominik Csapak d.csapak at proxmox.com
Mon Dec 9 15:27:00 CET 2019


so that it gets checked before the special case of removing the vmstate

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Qemu.pm | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index e7ed6e9..0c4486b 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -315,7 +315,6 @@ my $check_vm_modify_config_perm = sub {
 	# some checks (e.g., disk, serial port, usb) need to be done somewhere
 	# else, as there the permission can be value dependend
 	next if PVE::QemuServer::is_valid_drivename($opt);
-	next if $opt eq 'vmstate';
 	next if $opt eq 'cdrom';
 	next if $opt =~ m/^(?:unused|serial|usb)\d+$/;
 
@@ -338,6 +337,10 @@ my $check_vm_modify_config_perm = sub {
 	    $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Disk']);
 	} elsif ($cloudinitoptions->{$opt} || ($opt =~ m/^(?:net|ipconfig)\d+$/)) {
 	    $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Network']);
+	} elsif ($opt eq 'vmstate') {
+	    # the user needs Disk and PowerMgmt privileges to change the vmstate
+	    # also needs privileges on the storage, that will be checked later
+	    $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Disk', 'VM.PowerMgmt' ]);
 	} else {
 	    # catches hostpci\d+, args, lock, etc.
 	    # new options will be checked here
@@ -1152,8 +1155,6 @@ my $update_vm_api  = sub {
 		    }
 		} elsif ($opt eq 'vmstate') {
 		    PVE::QemuConfig->check_protection($conf, "can't remove vmstate '$val'");
-		    # the user needs Disk and PowerMgmt privileges to remove the vmstate
-		    $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk', 'VM.PowerMgmt' ]);
 		    if (PVE::QemuServer::try_deallocate_drive($storecfg, $vmid, $conf, $opt, { file => $val }, $rpcenv, $authuser, 1)) {
 			delete $conf->{$opt};
 			PVE::QemuConfig->write_config($vmid, $conf);
-- 
2.20.1




More information about the pve-devel mailing list