2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-15 21:38:10 +00:00
Files
xcat-core/xCAT-server/lib/xcat/plugins/getpostscript.pm
T
Daniel Hilst e3429791c6 fix(xcat-core): getpostscript serves a node's postscripts to a password or token login
With nodeauthentication off and no peer name, getpostscript used
_xcat_authname as the client identity and expanded it with noderange.
becomeuser and tokens set _xcat_authname to an account name, so a user
named after a node group received the postscripts of the first node in
that group.

xcatd now records the CN of the validated client certificate as
_xcat_certname, and only while no becomeuser or token replaced it. It
deletes any _xcat_certname the client sent. getpostscript uses that
name only when it names exactly one node, with no group or range
expansion. _xcat_authname is no longer a candidate.

getpostscript_client_identity.t drives the plugin with these requests.
On the previous head the group and node login checks fail, and
dropping the exact match fails the group and range checks.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-29 14:41:25 -03:00

112 lines
3.6 KiB
Perl

# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
=head1
xCAT plugin package to handle getpostscript command
=cut
#-------------------------------------------------------
package xCAT_plugin::getpostscript;
use xCAT::Utils;
use xCAT::MsgUtils;
use xCAT::NodeRange;
use xCAT::DiscoveryUtils;
1;
#-------------------------------------------------------
=head3 handled_commands
Return list of commands handled by this plugin
=cut
#-------------------------------------------------------
sub handled_commands
{
return {
'getpostscript' => "getpostscript",
};
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
my $request = shift;
my $callback = shift;
my $nodes = $request->{node};
my $command = $request->{command}->[0];
my $args = $request->{arg};
my $envs = $request->{env};
my $rsp;
my $i = 1;
my @nodes = @$nodes;
# do your processing here
# return info
my $client;
if ($::XCATSITEVALS{nodeauthentication}) { #if requiring node authentication, this request will have a certificate associated with it, use it instead of name resolution
unless (ref $request->{username}) { return; } #TODO: log an attempt without credentials?
($client) = noderange($request->{username}->[0]);
unless ($client) {
xCAT::MsgUtils->trace(0, "E", "Received getpostscript from $request->{username}->[0], which couldn't be correlated to a node (domain mismatch?)");
return;
}
} else {
my @candidates = xCAT::DiscoveryUtils::request_client_names($request);
unless (@candidates) {
xCAT::MsgUtils->trace(0, 'E', "Received getpostscript from a client this request does not identify: it carries no peer name and no client certificate name. Ignoring it.");
return;
}
$client = xCAT::DiscoveryUtils::request_client_node($request, \&noderange);
unless ($client) { #Not able to do identify the host in question
xCAT::MsgUtils->trace(0, "E", "Received getpostscript from " . join(', ', @candidates) . ", none of which could be correlated to a node (domain mismatch?)");
return;
}
}
my $state;
if ($request->{scripttype}) { $state = $request->{scripttype}->[0]; }
require xCAT::Postage;
my $args = $request->{arg};
my @scriptcontents;
my $version = 0;
if (defined($args) && grep(/version2/, @$args)) {
$version = 2
}
my $notmpfiles;
my $nofiles;
# If not version=2, then we return the mypostscript file in an array.
if ($version != 2) {
$notmpfiles = 1; # no tmp files and no files
$nofiles = 1; # do not create /tftpboot/mypostscript/mypostscript.<nodename>
@scriptcontents = xCAT::Postage::makescript([$client], $state, $callback, $notmpfiles, $nofiles);
xCAT::MsgUtils->trace(0, "I", "getpostscript: Sending scripts data to $client...");
$rsp->{data} = \@scriptcontents;
$callback->($rsp);
} else { # version 2, make files, do not return array
# make the mypostscript.<nodename> file
# or the mypostscript.<nodename>.tmp file if precreatemypostscripts=0
# xcatdsklspost will wget the file
$notmpfiles = 0;
$nofiles = 0;
xCAT::Postage::makescript([$client], $state, $callback, $notmpfiles, $nofiles);
}
return 0;
}