]> git.proxmox.com Git - pve-access-control.git/blobdiff - PVE/RPCEnvironment.pm
better error message for useradd
[pve-access-control.git] / PVE / RPCEnvironment.pm
index d382dcbe88443f7c4ca57620e829d16eb9d488c2..89c4be7876f4207b218b6d87ec69e58eedd3efef 100644 (file)
@@ -14,6 +14,7 @@ use PVE::INotify;
 use PVE::Cluster;
 use PVE::ProcFSTools;
 use PVE::AccessControl;
+use Cwd 'abs_path';
 use CGI;
 
 # we use this singleton class to pass RPC related environment values
@@ -282,17 +283,30 @@ sub check_vm_perm {
     return $self->check_full($user, "/vms/$vmid", $privs, $any, $noerr);
 };
 
-sub check_storage_perm {
-    my ($self, $user, $vmid, $pool, $storeid, $privs, $any, $noerr) = @_;
+sub check_volume_access {
+    my ($self, $user, $storecfg, $vmid, $volid) = @_;
+
+    # test if we have read access to volid
+
+    my $path;
+    my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
+    if ($sid) {
+       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';
 
-    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);
+       $path = abs_path($volid);
     }
-    return $self->check_full($user, "/storage/$storeid", $privs, $any, $noerr);
-};
+    return $path;
+}
 
 sub is_group_member {
     my ($self, $group, $user) = @_;
@@ -409,11 +423,11 @@ sub exec_api2_perm_check {
        }
        return 1;
     } elsif ($test eq 'userid-param') {
-       my ($userid, undef, $realm) = verify_username($param->{userid});
-       return if !$self->check_user_exist($userid, $noerr);
+       my ($userid, undef, $realm) = PVE::AccessControl::verify_username($param->{userid});
        my ($t, $subtest) = @$check;
        die "missing parameters" if !$subtest;
        if ($subtest eq 'self') {
+           return 0 if !$self->check_user_exist($userid, $noerr);
            return 1 if $username eq 'userid';
            return 0 if $noerr;
            raise_perm_exc();