-Fix race condition where make_slave_controlling_terminal could fail because pty is already closed (surprised this was a race...)

-Fix issue where '-nokeycheck' SSHInteract option was passed into Net::Telnet mistakenly
-Fix problem where Match specification was incorrectly done in SSHInteracte
-Fix problem where rspconfig could hang if the ssh session landed at a prompt
-Fix argument syntax in blade.pm to clicmds

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.7@12797 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2012-05-18 15:43:47 +00:00
parent 6546665c29
commit 7e0871c456
2 changed files with 21 additions and 10 deletions

View File

@ -1,8 +1,10 @@
package xCAT::SSHInteract;
use Exporter;
use Net::Telnet;
BEGIN {
our @ISA = qw/Exporter Net::Telnet/;
};
use strict;
our @ISA = qw/Exporter Net::Telnet/;
our @EXPORT_OK = ();
use IO::Pty;
use POSIX;
@ -21,11 +23,11 @@ sub _startssh {
}
#in child
$tty = $pty->slave or die "$!";
$pty->make_slave_controlling_terminal();
$tty_fd = $tty->fileno or die "$!";
close($pty);
open STDIN, "<&", $tty_fd;
open STDOUT,">&",$tty_fd;
$pty->make_slave_controlling_terminal();
close($tty);
my @cmd = ("ssh","-o","StrictHostKeyChecking=no");
if ($args{"-nokeycheck"}) {
@ -50,10 +52,13 @@ sub new {
delete $args{"-username"};
delete $args{"-password"};
my $nokeycheck = $args{"-nokeycheck"};
if ($nokeycheck) { delete $args{"-nokeycheck"}; }
my $self = Net::Telnet->new(%args);
delete $args{"-nokeycheck"};
my $self = $class->Net::Telnet::new(%args);
_startssh($self,$pty,$username,$host,"-nokeycheck"=>$nokeycheck);
my ($prematch,$match) = $self->waitfor([Match => $args{prompt},'/password:/i',]) or die "Login Failed: ",$self->lastline;
my $promptex = $args{Prompt};
$promptex =~ s!^/!!;
$promptex =~ s!/\z!!;
my ($prematch,$match) = $self->waitfor(Match => $args{Prompt},Match=>'/password:/i') or die "Login Failed: ",$self->lastline;
if ($match =~ /password:/i) {
#$self->waitfor("-match" => '/password:/i', -errmode => "return") or die "Unable to reach host ",$self->lastline;
$self->print($password);
@ -64,7 +69,13 @@ sub new {
if ($nextline =~ /^password:/ or $nextline =~ /Permission denied, please try again/) {
die "Incorrect Password";
}
}
} elsif ($match =~ /$promptex/) {
*$self->{_xcatsshinteract}->{_atprompt}=1;
}
return bless($self,$class);
}
sub atprompt {
my $self=shift;
return *$self->{_xcatsshinteract}->{_atprompt};
}
1;

View File

@ -4038,7 +4038,7 @@ sub clicmds {
Prompt=>'/system> $/'
);
my $Rc=1;
if ($t) { #we sshed in, but we may be forced to deal with initial password set
if ($t and not $t->atprompt) { #we sshed in, but we may be forced to deal with initial password set
my $output = $t->get();
if ($output =~ /Enter current password/) {
$t->print($currpass);
@ -4058,7 +4058,7 @@ sub clicmds {
}
}
$t->waitfor(match=>"/system> /");
} else {#ssh failed.. fallback to a telnet attempt for older AMMs with telnet disabled by default
} elsif (not $t) {#ssh failed.. fallback to a telnet attempt for older AMMs with telnet disabled by default
require Net::Telnet;
$t = new Net::Telnet(
Timeout=>15,
@ -4973,7 +4973,7 @@ sub dompa {
$rc = 1;
$args = [];
} else {
$result = clicmds($mpa,$user,$pass,$node,$slot,args=>\@exargs);
$result = clicmds($mpa,$user,$pass,$node,$slot,cmds=>\@exargs);
$rc |= @$result[0];
$args = @$result[1];
}
@ -5024,7 +5024,7 @@ sub dompa {
if ($mptype eq "cmm") {
# For the cmm, call the rscanfsp to discover the fsp for ppc blade
my @telargs = ("rscanfsp");
clicmds($mpa,$user,$pass,$node,$slot,args=>\@telargs);
clicmds($mpa,$user,$pass,$node,$slot,cmds=>\@telargs);
}
}
}