]> git.proxmox.com Git - pve-access-control.git/blobdiff - PVE/RPCEnvironment.pm
fix access permissions for backup files
[pve-access-control.git] / PVE / RPCEnvironment.pm
index 89c4be7876f4207b218b6d87ec69e58eedd3efef..eb7b3c7645da60ca19106f5ec0281b9da2b13224 100644 (file)
@@ -295,7 +295,12 @@ sub check_volume_access {
        ($path, $ownervm, $vtype) = PVE::Storage::path($storecfg, $volid);
        if ($vtype eq 'iso' || $vtype eq 'vztmpl') {
            # we simply allow access 
-       } elsif (!$ownervm || ($ownervm != $vmid)) {
+       } elsif (defined($ownervm) && defined($vmid) && ($ownervm == $vmid)) {
+           # we are owner - allow access 
+       } elsif ($vtype eq 'backup' && $ownervm) {
+           $self->check($user, "/storage/$sid", ['Datastore.AllocateSpace']);
+           $self->check($user, "/vms/$ownervm", ['VM.Backup']);
+       } else {
            # allow if we are Datastore administrator
            $self->check($user, "/storage/$sid", ['Datastore.Allocate']);
        }
@@ -304,6 +309,9 @@ sub check_volume_access {
            if $user ne 'root@pam';
 
        $path = abs_path($volid);
+       if ($path =~ m|^(/.+)$|) {
+           $path = $1; # untaint any path
+       }
     }
     return $path;
 }
@@ -428,7 +436,7 @@ sub exec_api2_perm_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 1 if $username eq $userid;
            return 0 if $noerr;
            raise_perm_exc();
        } elsif ($subtest eq 'Realm.AllocateUser') {
@@ -820,14 +828,14 @@ sub check_worker {
 # STDOUT,STDERR are redirected to the filename returned by upid_decode
 # NOTE: we simulate running in foreground if ($self->{type} eq 'cli')
 sub fork_worker {
-    my ($self, $dtype, $id, $user, $function) = @_;
+    my ($self, $dtype, $id, $user, $function, $background) = @_;
 
     $dtype = 'unknown' if !defined ($dtype);
     $id = '' if !defined ($id);
 
     $user = 'root@pve' if !defined ($user);
 
-    my $sync = $self->{type} eq 'cli' ? 1 : 0;
+    my $sync = ($self->{type} eq 'cli' && !$background) ? 1 : 0;
 
     local $SIG{INT} = 
        local $SIG{QUIT} =