]> git.proxmox.com Git - pve-manager.git/commitdiff
set permissions for VZDump API
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 6 Feb 2012 10:15:31 +0000 (11:15 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 6 Feb 2012 10:17:42 +0000 (11:17 +0100)
PVE/API2/VZDump.pm
PVE/VZDump.pm

index 6ce9f40247fab5f0fba0dc84369d152079783149..1c0743320862e1a88a8707694722bb7ee959e96a 100644 (file)
@@ -22,6 +22,10 @@ __PACKAGE__->register_method ({
     path => '',
     method => 'POST',
     description => "Create backup.",
+    permissions => {
+       description => "The user needs VM.Backup permissions on any VM.",
+       user => 'all',
+    },
     protected => 1,
     proxyto => 'node',
     parameters => {
@@ -99,6 +103,11 @@ __PACKAGE__->register_method ({
        die "you can only backup a single VM with option --stdout\n"
            if $param->{stdout} && scalar(@vmids) != 1;
 
+       foreach my $key (qw(maxfiles tmpdir dumpdir script size bwlimit ionice)) {
+           raise_param_exc({ $key => "Only root may set this option."})
+               if defined($param->{$key}) && ($user ne 'root@pam');        
+       }
+
        my $vzdump = PVE::VZDump->new($cmdline, $param, $skiplist);
 
        my $worker = sub {
@@ -115,7 +124,7 @@ __PACKAGE__->register_method ({
                    PVE::VZDump::run_command(undef, "ionice -c2 -n$param->{ionice} -p $$");
                }
            }
-           $vzdump->exec_backup(); 
+           $vzdump->exec_backup($rpcenv, $user); 
        }; 
 
        open STDOUT, '>/dev/null' if $param->{quiet} && !$param->{stdout};
index 5ae091e4740137d951018450ccfdaddd225d4f1d..0647f308bd46cc2b304e9ceb68af5e7eaf05b8c4 100644 (file)
@@ -10,6 +10,7 @@ use IO::Select;
 use IPC::Open3;
 use POSIX qw(strftime);
 use File::Path;
+use PVE::RPCEnvironment;
 use PVE::Storage;
 use PVE::Cluster qw(cfs_read_file);
 use PVE::VZDump::OpenVZ;
@@ -953,7 +954,7 @@ sub exec_backup_task {
 }
 
 sub exec_backup {
-    my ($self) = @_;
+    my ($rpcenv, $authuser, $self) = @_;
 
     my $opts = $self->{opts};
 
@@ -968,6 +969,7 @@ sub exec_backup {
            my $vmlist = $plugin->vmlist();
            foreach my $vmid (sort @$vmlist) {
                next if grep { $_ eq  $vmid } @{$opts->{exclude}};
+               next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Backup' ], 1);
                push @$tasklist, { vmid => $vmid,  state => 'todo', plugin => $plugin };
            }
        }
@@ -981,6 +983,7 @@ sub exec_backup {
                    last;
                }
            }
+           $rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Backup' ]);
            push @$tasklist, { vmid => $vmid,  state => 'todo', plugin => $plugin };
        }
     }