X-Git-Url: https://git.proxmox.com/?p=pve-access-control.git;a=blobdiff_plain;f=PVE%2FRPCEnvironment.pm;h=765008eee5c63a5ee0b3ae591c25da372f770153;hp=89c4be7876f4207b218b6d87ec69e58eedd3efef;hb=b78ce7c2529a381669792a909d6b55b7790969d7;hpb=a69bbe2e7e6e475bfe81a959bd166cc777364fda diff --git a/PVE/RPCEnvironment.pm b/PVE/RPCEnvironment.pm index 89c4be7..765008e 100644 --- a/PVE/RPCEnvironment.pm +++ b/PVE/RPCEnvironment.pm @@ -15,7 +15,6 @@ 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 @@ -295,7 +294,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 +308,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 +435,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') { @@ -520,51 +527,6 @@ sub get { return $pve_env; } -sub parse_params { - my ($self, $enable_upload) = @_; - - if ($self->{request_rec}) { - my $cgi; - if ($enable_upload) { - $cgi = CGI->new($self->{request_rec}); - } else { - # disable upload using empty upload_hook - $cgi = CGI->new($self->{request_rec}, sub {}, undef, 0); - } - $self->{cgi} = $cgi; - my $params = $cgi->Vars(); - return PVE::Tools::decode_utf8_parameters($params); - } elsif ($self->{params}) { - return $self->{params}; - } else { - die "no parameters registered"; - } -} - -sub get_upload_info { - my ($self, $param) = @_; - - my $cgi = $self->{cgi}; - die "CGI not initialized" if !$cgi; - - my $pd = $cgi->param($param); - die "unable to get cgi parameter info\n" if !$pd; - my $info = $cgi->uploadInfo($pd); - die "unable to get cgi upload info\n" if !$info; - - my $res = { %$info }; - - my $tmpfilename = $cgi->tmpFileName($pd); - die "unable to get cgi upload file name\n" if !$tmpfilename; - $res->{tmpfilename} = $tmpfilename; - - #my $hndl = $cgi->upload($param); - #die "unable to get cgi upload handle\n" if !$hndl; - #$res->{handle} = $hndl->handle; - - return $res; -} - # init_request - must be called before each RPC request sub init_request { my ($self, %params) = @_; @@ -577,11 +539,6 @@ sub init_request { foreach my $p (keys %params) { if ($p eq 'userconfig') { $userconfig = $params{$p}; - } elsif ($p eq 'request_rec') { - # pass Apache2::RequestRec - $self->{request_rec} = $params{$p}; - } elsif ($p eq 'params') { - $self->{params} = $params{$p}; } else { die "unknown parameter '$p'"; } @@ -820,14 +777,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} =