mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-08-26 16:46:41 +00:00
e22bcf54d4
syncfiles builds an xdcp subrequest with no username. xdcp takes its user from
-l, then from DSH_FROM_USERID, and otherwise leaves it unset, so the sync ends
up running as whatever identity xcatd happens to have rather than one the
request states.
That gap dates from 2c9bdf848, which removed the forceroot flag because any
caller could set it, and replaced it by passing the real username through.
updatenode was updated to do that; syncfiles was not. Its request comes from the
node, so there is no calling user to carry through, and root is what the sync
has to run as.
Name it explicitly, the same way updatenode does. This is a consistency and
hardening change: on a management node running as root the resulting identity is
the same either way, and no behavior difference is observable today.
Co-authored-by: Jarrod Johnson <10814490+jjohnson42@users.noreply.github.com>
138 lines
3.2 KiB
Perl
138 lines
3.2 KiB
Perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
#-------------------------------------------------------
|
|
|
|
=head1
|
|
xCAT plugin package to handle syncfiles command
|
|
|
|
=cut
|
|
|
|
#-------------------------------------------------------
|
|
package xCAT_plugin::syncfiles;
|
|
use xCAT::Utils;
|
|
use xCAT::MsgUtils;
|
|
use xCAT::SvrUtils;
|
|
use xCAT::NodeRange;
|
|
use Data::Dumper;
|
|
use Getopt::Long;
|
|
1;
|
|
|
|
#-------------------------------------------------------
|
|
|
|
=head3 handled_commands
|
|
|
|
Return list of commands handled by this plugin
|
|
|
|
=cut
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub handled_commands
|
|
{
|
|
return { 'syncfiles' => "syncfiles" };
|
|
}
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
=head3 process_request
|
|
|
|
Process the command
|
|
|
|
=cut
|
|
|
|
#-------------------------------------------------------
|
|
sub process_request
|
|
{
|
|
my $request = shift;
|
|
my $callback = shift;
|
|
my $subreq = shift;
|
|
|
|
my $args= $request->{arg}; # argument
|
|
@ARGV = @{$args};
|
|
my $client;
|
|
if ($request->{'_xcat_clienthost'}) {
|
|
$client = $request->{'_xcat_clienthost'}->[0];
|
|
}
|
|
|
|
|
|
my %options = ();
|
|
Getopt::Long::Configure("posix_default");
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
Getopt::Long::Configure("bundling");
|
|
if (
|
|
!GetOptions(
|
|
'r|c|node-rcp=s' => \$options{'node-rcp'},
|
|
)
|
|
)
|
|
{
|
|
xCAT::MsgUtils->message("S", "Received syncfiles from $client, with invalid options @ARGV");
|
|
return;
|
|
}
|
|
|
|
if ($options{'node-rcp'}){
|
|
$::RCP=$options{'node-rcp'};
|
|
}
|
|
|
|
if ($client) { ($client) = noderange($client) }
|
|
unless ($client) { #Not able to do identify the host in question
|
|
xCAT::MsgUtils->message("S", "Received syncfiles from $client, which couldn't be correlated to a node (domain mismatch?)");
|
|
return;
|
|
}
|
|
|
|
require xCAT::Postage;
|
|
&syncfiles($client, $callback, $subreq);
|
|
}
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
=head3 syncfiles
|
|
|
|
Use the xdcp command to sync files from Management node/Service node t
|
|
o the Compute node
|
|
|
|
Arguments:
|
|
Returns: 0 - failed; 1 - succeeded;
|
|
Example:
|
|
syncfiles($node, $callback);
|
|
|
|
Comments:
|
|
|
|
=cut
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub syncfiles {
|
|
my $node = shift;
|
|
if ($node =~ /xCAT::Postage/) {
|
|
$node = shift;
|
|
}
|
|
my $callback = shift;
|
|
my $subreq = shift;
|
|
|
|
#get the sync file base on the node type
|
|
my $synclist = xCAT::SvrUtils->getsynclistfile([$node]);
|
|
if (!$synclist) {
|
|
xCAT::MsgUtils->message("S", "Cannot find synclist file for the $node");
|
|
return 0;
|
|
}
|
|
|
|
# this can be a comma separated list of multiple
|
|
# syncfiles
|
|
my @sl = split(',', $$synclist{$node});
|
|
foreach my $synclistfile (@sl) {
|
|
|
|
# call the xdcp plugin to handle the syncfile operation
|
|
my $args = [ "-F", "$synclistfile"];
|
|
if($::RCP){
|
|
push @$args,"-r";
|
|
push @$args, "$::RCP";
|
|
}
|
|
my $env = ["DSH_RSYNC_FILE=$synclistfile"];
|
|
$subreq->({ command => ['xdcp'], username => ['root'], node => [$node], arg => $args, env => $env }, $callback);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
1;
|