]> git.proxmox.com Git - pve-access-control.git/blobdiff - PVE/RPCEnvironment.pm
moved check_volume_access from qemu-server
[pve-access-control.git] / PVE / RPCEnvironment.pm
index 14e6849cc411ec43f14b557e0be728532a053a2f..8cafdd182978c706b878869e724d2bc69052cbc2 100644 (file)
@@ -282,6 +282,30 @@ sub check_vm_perm {
     return $self->check_full($user, "/vms/$vmid", $privs, $any, $noerr);
 };
 
+sub check_volume_access = sub {
+    my ($self, $user, $storecfg, $vmid, $volid) = @_;
+
+    # test if we have read access to volid
+
+    my $path;
+    if (my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1)) {
+       my ($ownervm, $vtype);
+       ($path, $ownervm, $vtype) = PVE::Storage::path($storecfg, $volid);
+       if ($vtype eq 'iso' || $vtype eq 'vztmpl') {
+           # we simply allow access 
+       } elsif (!$ownervm || ($ownervm != $vmid)) {
+           # allow if we are Datastore administrator
+           $self->check($user, "/storage/$sid", ['Datastore.Allocate']);
+       }
+    } else {
+       die "Only root can pass arbitrary filesystem paths."
+           if $user ne 'root@pam';
+
+       $path = abs_path($volid);
+    }
+    return $path;
+}
+
 sub is_group_member {
     my ($self, $group, $user) = @_;