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) = @_;
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_storage_perm {
+ my ($self, $user, $vmid, $pool, $storeid, $privs, $any, $noerr) = @_;
+
+ my $cfg = $self->{user_cfg};
+
+ if ($pool && $cfg->{pools}->{$pool} &&
+ $cfg->{pools}->{$pool}->{storage}->{$storeid}) {
+ return if $self->check_full($user, "/pool/$pool", $privs, $any, 1);
+ }
+ return $self->check_full($user, "/storage/$storeid", $privs, $any, $noerr);
+};
+
sub is_group_member {
my ($self, $group, $user) = @_;
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};
}
}
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;
} 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";
}