[pve-devel] [PATCH] fix #1427: Set file mode on uploaded templates/ISOs

Stefan Reiter s.reiter at proxmox.com
Wed Jun 12 16:52:45 CEST 2019


Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 PVE/API2/Storage/Status.pm | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/PVE/API2/Storage/Status.pm b/PVE/API2/Storage/Status.pm
index 9a5a952..8649a7d 100644
--- a/PVE/API2/Storage/Status.pm
+++ b/PVE/API2/Storage/Status.pm
@@ -369,7 +369,7 @@ __PACKAGE__->register_method ({
 		type => 'string',
 	    },
 	    tmpfilename => { 
-		description => "The source file name. This parameter is usually set by the REST handler. You can only overwrite it when connecting to the trustet port on localhost.",
+		description => "The source file name. This parameter is usually set by the REST handler. You can only overwrite it when connecting to the trusted port on localhost.",
 		type => 'string',
 		optional => 1,
 	    },
@@ -427,10 +427,15 @@ __PACKAGE__->register_method ({
 	my $dest = "$path/$filename";
 	my $dirname = dirname($dest);
 
-	# we simply overwrite when destination when file already exists
+	# we simply overwrite when destination file already exists
+
+	# default mode for $dest is 600, templates have default 644
+	# let's keep them in sync
+	my $mode_cmd = ['chmod', 'a+r', '--', PVE::Tools::shell_quote($dest)];
 
 	my $cmd;
 	if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) {
+	    # remote node, execute commands over ssh
 	    my $remip = PVE::Cluster::remote_node_ip($node);
 
 	    my @ssh_options = ('-o', 'BatchMode=yes');
@@ -446,8 +451,9 @@ __PACKAGE__->register_method ({
 
 	    PVE::Tools::run_command([@remcmd, '/bin/mkdir', '-p', '--', PVE::Tools::shell_quote($dirname)],
 				    errmsg => "mkdir failed");
- 
+
 	    $cmd = ['/usr/bin/scp', @ssh_options, '--', $tmpfilename, "[$remip]:" . PVE::Tools::shell_quote($dest)];
+	    $mode_cmd = [@remcmd, @$mode_cmd];
 	} else {
 	    PVE::Storage::activate_storage($cfg, $param->{storage});
 	    File::Path::make_path($dirname);
@@ -456,7 +462,7 @@ __PACKAGE__->register_method ({
 
 	my $worker = sub  {
 	    my $upid = shift;
-	    
+
 	    print "starting file import from: $tmpfilename\n";
 	    print "target node: $node\n";
 	    print "target file: $dest\n";
@@ -468,6 +474,17 @@ __PACKAGE__->register_method ({
 		unlink $dest;
 		die $err;
 	    }
+
+	    print "set file mode: " . join(' ', @$mode_cmd) . "\n";
+
+	    # set file mode
+	    eval { PVE::Tools::run_command($mode_cmd, errmsg => 'chmod error'); };
+	    if (my $err = $@) {
+		# pve works with the default mode too, so this error has
+		# "cosmetic" consequences only - hence we warn, not die
+		warn $err;
+	    }
+
 	    print "finished file import successfully\n";
 	};
 
-- 
2.20.1





More information about the pve-devel mailing list