From 78075854cc1c6903a5978be8667f615443d2aa82 Mon Sep 17 00:00:00 2001 From: zhanx Date: Fri, 11 Sep 2009 10:54:39 +0000 Subject: [PATCH] Fix defect 2832802 mkhwconn not properly working with password authentication git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4121 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/PPCconn.pm | 10 +++++++-- perl-xCAT/xCAT/PPCdb.pm | 44 +++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/perl-xCAT/xCAT/PPCconn.pm b/perl-xCAT/xCAT/PPCconn.pm index 4441addbe..0361ca4c6 100644 --- a/perl-xCAT/xCAT/PPCconn.pm +++ b/perl-xCAT/xCAT/PPCconn.pm @@ -412,11 +412,17 @@ sub mkhwconn my ($user, $passwd); if ( exists $opt->{P}) { - ($user, $passwd) = ('admin', $opt->{P}); + ($user, $passwd) = ('HMC', $opt->{P}); } else { - ($user, $passwd) = xCAT::PPCdb::credentials( $node_name, $type); + ($user, $passwd) = xCAT::PPCdb::credentials( $node_name, $type,'HMC'); + if ( !$passwd) + { + push @value, [$node_name, "Cannot get password of userid 'HMC'. Please check table 'passwd' or 'ppcdirect'.",1]; + next; + } + } my $res = xCAT::PPCcli::mksysconn( $exp, $node_ip, $type, $passwd); diff --git a/perl-xCAT/xCAT/PPCdb.pm b/perl-xCAT/xCAT/PPCdb.pm index 08454d0ad..1b7868525 100644 --- a/perl-xCAT/xCAT/PPCdb.pm +++ b/perl-xCAT/xCAT/PPCdb.pm @@ -300,15 +300,29 @@ sub credentials { my $server = shift; my $hwtype = shift; - my $user = @{$logon{$hwtype}}[0]; - my $pass = @{$logon{$hwtype}}[1]; + my $user = shift; + my $pass = undef; + my $user_specified = $user; + if ( !$user_specified or $user eq @{$logon{$hwtype}}[0]) + { + $user = @{$logon{$hwtype}}[0]; + $pass = @{$logon{$hwtype}}[1]; + } ########################################### # Check passwd tab ########################################### my $tab = xCAT::Table->new( 'passwd' ); if ( $tab ) { - my ($ent) = $tab->getAttribs( {key=>$hwtype}, qw(username password)); + my $ent; + if ( $user_specified) + { + ($ent) = $tab->getAttribs( {key=>$hwtype,username=>$user},qw(password)); + } + else + { + ($ent) = $tab->getAttribs( {key=>$hwtype}, qw(username password)); + } if ( $ent ) { if (defined($ent->{password})) { $pass = $ent->{password}; } if (defined($ent->{username})) { $user = $ent->{username}; } @@ -319,7 +333,15 @@ sub credentials { ########################################## $tab = xCAT::Table->new( $hcptab{$hwtype} ); if ( $tab ) { - my ($ent) = $tab->getAttribs( {hcp=>$server}, qw(username password)); + my $ent; + if ( $user_specified) + { + ($ent) = $tab->getAttribs( {hcp=>$server,username=>$user},qw(password)); + } + else + { + ($ent) = $tab->getAttribs( {hcp=>$server}, qw(username password)); + } if ( $ent){ if (defined($ent->{password})) { $pass = $ent->{password}; } if (defined($ent->{username})) { $user = $ent->{username}; } @@ -329,8 +351,18 @@ sub credentials { ############################################################## elsif( ($ent) = $tab->getAttribs( {hcp=>$defaultgrp{$hwtype}}, qw(username password))) { - if (defined($ent->{password})) { $pass = $ent->{password}; } - if (defined($ent->{username})) { $user = $ent->{username}; } + if ( $user_specified) + { + ($ent) = $tab->getAttribs( {hcp=>$defaultgrp{$hwtype},username=>$user},qw(password)); + } + else + { + ($ent) = $tab->getAttribs( {hcp=>$defaultgrp{$hwtype}}, qw(username password)); + } + if ( $ent){ + if (defined($ent->{password})) { $pass = $ent->{password}; } + if (defined($ent->{username})) { $user = $ent->{username}; } + } } } return( $user,$pass );