From 4e1d4629a9230d60a9468932e9fea65f3fd864b6 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Mon, 20 Mar 2017 13:19:39 -0400 Subject: [PATCH] Preserve the user ownership of the file for xdcp command --- perl-xCAT/xCAT/DSHCLI.pm | 11 +++++++++++ xCAT-client/bin/xdsh | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/perl-xCAT/xCAT/DSHCLI.pm b/perl-xCAT/xCAT/DSHCLI.pm index 8121f475d..2fa5c5a14 100644 --- a/perl-xCAT/xCAT/DSHCLI.pm +++ b/perl-xCAT/xCAT/DSHCLI.pm @@ -4434,6 +4434,17 @@ sub parse_and_run_dcp return 0; } + unless ($options{'user'}) + { + # user was not specified with -l flag, check it user calling the command + # was saved in DSH_FROM_USERID environment variable + my $current_userid = $ENV{'DSH_FROM_USERID'}; + if (defined($current_userid)) { + # Set userid from value in DSH_FROM_USERID environment variable + $options{'user'} = $current_userid; + } + } + if (defined($options{'rootimg'})) { if (xCAT::Utils->isAIX()) diff --git a/xCAT-client/bin/xdsh b/xCAT-client/bin/xdsh index 0797f4d93..cad1bf394 100644 --- a/xCAT-client/bin/xdsh +++ b/xCAT-client/bin/xdsh @@ -666,6 +666,24 @@ sub parse_args_xdcp $::NODE_RCP = 1; } + # find out who is the current user running xdcp + my $current_userid = getpwuid($>); + + $ENV{DSH_FROM_USERID} = $current_userid; + + my $to_userid; + if ($options{'user'}) # if -l option + { + $to_userid = $options{'user'}; + } + else + { + $to_userid = $current_userid; + } + # Save userid running this command in ENV variable. + # It will be later extraced by DSHCLI.pm + $ENV{DSH_TO_USERID} = $to_userid; + if ($options{'bypass'}) { $ENV{XCATBYPASS} = "yes"; # bypass xcatd