]> git.proxmox.com Git - pve-access-control.git/blobdiff - PVE/RPCEnvironment.pm
fix syntax
[pve-access-control.git] / PVE / RPCEnvironment.pm
index 06360f23ddc01fe01496a67e6eac0a52df06e671..d14104a7cacfb4624d77e6555871b7276a94147e 100644 (file)
@@ -259,6 +259,53 @@ sub check_user_exist {
     return PVE::AccessControl::check_user_exist($cfg, $user, $noerr);
 }
 
+sub check_pool_exist {
+    my ($self, $pool, $noerr) = @_;
+
+    my $cfg = $self->{user_cfg};
+
+    return 1 if $cfg->{pools}->{$pool};
+
+    return undef if $noerr;
+
+    raise_perm_exc("pool '$pool' does not exist"); 
+}
+
+sub check_vm_perm {
+    my ($self, $user, $vmid, $pool, $privs, $any, $noerr) = @_;
+
+    my $cfg = $self->{user_cfg};
+   
+    if ($pool) {
+       return if $self->check_full($user, "/pool/$pool", $privs, $any, 1);
+    }
+    return $self->check_full($user, "/vms/$vmid", $privs, $any, $noerr);
+};
+
+sub check_volume_access {
+    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) = @_;