X-Git-Url: https://git.proxmox.com/?p=pve-access-control.git;a=blobdiff_plain;f=PVE%2FRPCEnvironment.pm;h=06360f23ddc01fe01496a67e6eac0a52df06e671;hp=e6651d0e832f4fccab4e1bd79122b9eac105bf2c;hb=c4a776a657f4d66bbd3eb9c310907731e5133a5b;hpb=39c85db819dc564e89270f6f6d15dbce79d0540b diff --git a/PVE/RPCEnvironment.pm b/PVE/RPCEnvironment.pm index e6651d0..06360f2 100644 --- a/PVE/RPCEnvironment.pm +++ b/PVE/RPCEnvironment.pm @@ -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) = @_; @@ -268,14 +277,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 +312,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,22 +343,23 @@ 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; - return if !$options{groups_param} && !$self->check_user_exist($userid, $noerr); - if (!$self->check_any($username, "/access", $privs, 1)) { + return 0 if !$options{groups_param} && !$self->check_user_exist($userid, $noerr); + if (!$self->check_any($username, "/access/groups", $privs, 1)) { my $groups = $self->filter_groups($username, $privs, 1); if ($options{groups_param}) { my @group_param = PVE::Tools::split_list($param->{groups}); - raise_perm_exc("/access, " . join("|", @$privs)) if !scalar(@group_param); + raise_perm_exc("/access/groups, " . join("|", @$privs)) if !scalar(@group_param); foreach my $pg (@group_param) { raise_perm_exc("/access/groups/$pg, " . join("|", @$privs)) if !$groups->{$pg}; @@ -368,7 +374,7 @@ sub exec_api2_perm_check { } return 1; } elsif ($test eq 'userid-param') { - my $userid = $param->{userid}; + my ($userid, undef, $realm) = verify_username($param->{userid}); return if !$self->check_user_exist($userid, $noerr); my ($t, $subtest) = @$check; die "missing parameters" if !$subtest; @@ -376,10 +382,13 @@ sub exec_api2_perm_check { return 1 if $username eq 'userid'; return 0 if $noerr; raise_perm_exc(); + } elsif ($subtest eq 'Realm.AllocateUser') { + my $path = "/access/realm/$realm"; + return $self->check($username, $path, ['Realm.AllocateUser'], $noerr); } else { die "unknown userid-param test"; } - } elsif ($test eq 'perm-modify') { + } elsif ($test eq 'perm-modify') { my ($t, $tmplpath) = @$check; my $path = PVE::Tools::template_replace($tmplpath, $param); $path = PVE::AccessControl::normalize_path($path);