]> git.proxmox.com Git - pve-access-control.git/blobdiff - PVE/RPCEnvironment.pm
fix syntax
[pve-access-control.git] / PVE / RPCEnvironment.pm
index 31692ce2a027f37f9f7233f6568c1dc8f1d56b71..d14104a7cacfb4624d77e6555871b7276a94147e 100644 (file)
@@ -236,6 +236,15 @@ sub check_any {
     raise_perm_exc("$path, " . join("|", @$privs)); 
 };
 
+sub check_full {
+    my ($self, $username, $path, $privs, $any, $noerr) = @_;
+    if ($any) {
+       return $self->check_any($username, $path, $privs, $noerr);
+    } else {
+       return $self->check($username, $path, $privs, $noerr);
+    }
+}
+
 sub check_user_enabled {
     my ($self, $user, $noerr) = @_;
     
@@ -250,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) = @_;
 
@@ -268,14 +324,8 @@ sub filter_groups {
     my $groups = {};
     foreach my $group (keys %{$cfg->{groups}}) {
        my $path = "/access/groups/$group";
-       if ($any) {
-           if ($self->check_any($user, $path, $privs, 1)) {
-               $groups->{$group} = $cfg->{groups}->{$group};
-           }
-       } else {
-           if ($self->check($user, $path, $privs, 1)) {
-               $groups->{$group} = $cfg->{groups}->{$group};
-           }
+       if ($self->check_full($user, $path, $privs, $any, 1)) {
+           $groups->{$group} = $cfg->{groups}->{$group};
        }
     }
 
@@ -309,6 +359,8 @@ sub check_perm_modify {
        push @$testperms, 'Datastore.Allocate';
     } elsif ($path =~ m|^/vms/.+$|) {
        push @$testperms, 'VM.Allocate';
+    } elsif ($path =~ m|^/pool/.+$|) {
+       push @$testperms, 'Pool.Allocate';
     }
 
     return $self->check_any($username, $path, $testperms, $noerr);
@@ -338,13 +390,14 @@ sub exec_api2_perm_check {
        my ($t, $tmplpath, $privs, %options) = @$check;
        my $any = $options{any};
        die "missing parameters" if !($tmplpath && $privs);
+       my $require_param = $options{require_param};
+       if ($require_param && !defined($param->{$require_param})) {
+           return 0 if $noerr;
+           raise_perm_exc();
+       }
        my $path = PVE::Tools::template_replace($tmplpath, $param);
        $path = PVE::AccessControl::normalize_path($path);
-       if ($any) {
-           return $self->check_any($username, $path, $privs, $noerr);
-       } else {
-           return $self->check($username, $path, $privs, $noerr);
-       }
+       return $self->check_full($username, $path, $privs, $any, $noerr);
     } elsif ($test eq 'userid-group') {
        my $userid = $param->{userid};
        my ($t, $privs, %options) = @$check;
@@ -379,8 +432,6 @@ sub exec_api2_perm_check {
        } elsif ($subtest eq 'Realm.AllocateUser') {
            my $path =  "/access/realm/$realm";
            return $self->check($username, $path, ['Realm.AllocateUser'], $noerr);
-           return 0 if $noerr;
-           raise_perm_exc("$path, 'Realm.AllocateUser'");
        } else {
            die "unknown userid-param test";
        }