From ec6154e11efa8687933e639485718496246cd11c Mon Sep 17 00:00:00 2001 From: wanghuaz Date: Tue, 29 Dec 2009 11:42:49 +0000 Subject: [PATCH] Change passwds or set the initial passwords for FSP/BPA git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4853 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/PPCcfg.pm | 71 ++++++++++++++++++++++++++++++++++++++-- perl-xCAT/xCAT/PPCcli.pm | 19 ++++++++--- perl-xCAT/xCAT/PPCdb.pm | 24 ++++++++++++++ 3 files changed, 107 insertions(+), 7 deletions(-) diff --git a/perl-xCAT/xCAT/PPCcfg.pm b/perl-xCAT/xCAT/PPCcfg.pm index 15a2db5ec..7d021bf46 100644 --- a/perl-xCAT/xCAT/PPCcfg.pm +++ b/perl-xCAT/xCAT/PPCcfg.pm @@ -37,11 +37,17 @@ sub parse_args { "autopower", "sysdump", "spdump", - "network" + "network", + "HMC_passwd", + "admin_passwd", + "general_passwd" ); my @bpa = ( - "network", - "frame" + "password", + "newpassword", + "HMC_passwd", + "admin_passwd", + "general_passwd" ); my @ppc = ( "sshcfg" @@ -122,6 +128,7 @@ sub parse_args { } $cmds{$command} = $value; } + #################################### # Check command arguments #################################### @@ -148,6 +155,16 @@ sub parse_args { $request->{method} = "cfg"; return( \%opt ); } + + #################################### + # Return method to invoke + #################################### + if ( exists($cmds{HMC_passwd}) or exists($cmds{general_passwd}) or exists($cmds{admin_passwd}) ) { + $request->{hcp} = "hmc"; + $request->{method} = "passwd"; + return( \%opt ); + } + $request->{method} = \%cmds; return( \%opt ); } @@ -228,10 +245,58 @@ sub parse_option { } } + if ( $command eq 'admin_passwd' or $command eq 'general_passwd' ){ + my ($passwd,$newpasswd) = split /,/, $value; + if ( !$passwd or !$newpasswd) { + return( "Current password and new password couldn't be empty for user 'admin' and 'general'" ); + } + } + + if ( $command eq 'HMC_passwd' ) { + my ($passwd,$newpasswd) = split /,/, $value; + if ( !$newpasswd ) { + return( "New password couldn't be empty for user 'HMC'" ); + } + } + return undef; } +########################################################################## +# Update passwords for different users on FSP/BPA +########################################################################## +sub passwd { + my $request = shift; + my $hash = shift; + my $exp = shift; + my $args = $request->{arg}; + my $result; + + foreach my $arg ( @$args ) { + my ($user,$value) = split /=/, $arg; + my ($passwd,$newpasswd) = split /,/, $value; + $user =~ s/_passwd$//; + + while ( my ($cec,$h) = each(%$hash) ) { + while ( my ($node,$d) = each(%$h) ) { + my $type = @$d[4]; + my $data = xCAT::PPCcli::chsyspwd( $exp, $user, $type, $cec, $newpasswd, $passwd ); + my $Rc = shift(@$data); + push @$result, [$node,@$data[0],$Rc]; + + ################################## + # Write the new password to table + ################################## + if ( $Rc == SUCCESS ) { + xCAT::PPCdb::update_credentials( $node, $type, $user, $newpasswd ); + } + } + } + } + + return( [@$result] ); +} ########################################################################## # Handles all PPC rspconfig commands diff --git a/perl-xCAT/xCAT/PPCcli.pm b/perl-xCAT/xCAT/PPCcli.pm index f38472d70..bc65d34e7 100644 --- a/perl-xCAT/xCAT/PPCcli.pm +++ b/perl-xCAT/xCAT/PPCcli.pm @@ -101,8 +101,10 @@ my %lssysconn = ( # or frames ############################################## my %chsyspwd = ( - fsp => "chsyspwd -t %s -m %s --passwd %s --newpasswd %s", - bpa => "chsyspwd -t %s -e %s --passwd %s --newpasswd %s" + initial_fsp => "chsyspwd -t %s -m %s --newpasswd %s", + initial_bpa => "chsyspwd -t %s -e %s --newpasswd %s", + fsp => "chsyspwd -t %s -m %s --newpasswd %s --passwd %s", + bpa => "chsyspwd -t %s -e %s --newpasswd %s --passwd %s" ); @@ -1248,11 +1250,20 @@ sub chsyspwd my $user = shift; my $type = shift; my $mtms = shift; - my $passwd = shift; my $newpwd = shift; + my $pwd = shift; + my $cmd; + + $user =~ s/^HMC$/access/; + + if ( !$pwd ) { + $cmd = sprintf( $chsyspwd{"initial_$type"}, $user, $mtms, $newpwd ); + } else { + $cmd = sprintf( $chsyspwd{$type}, $user, $mtms, $newpwd, $pwd ); + } - my $cmd = sprintf( $chsyspwd{$type}, $user, $mtms, $passwd, $newpwd ); my $result = send_cmd( $exp, $cmd); + return ( $result ); } diff --git a/perl-xCAT/xCAT/PPCdb.pm b/perl-xCAT/xCAT/PPCdb.pm index 46f8d360c..6c27feaee 100644 --- a/perl-xCAT/xCAT/PPCdb.pm +++ b/perl-xCAT/xCAT/PPCdb.pm @@ -673,5 +673,29 @@ sub credentials { return( $user,$pass ); } +########################################################################## +# Set userids and passwords to tables +########################################################################## +sub update_credentials +{ + + my $server = shift; + my $hwtype = shift; + my $user = shift; + my $pass = shift; + + ########################################## + # Set password to specific table + ########################################## + my $tab = xCAT::Table->new( $hcptab{$hwtype} ); + if ( $tab ) { + my $ent; + $tab->setAttribs( {hcp=>$server, username=>$user},{password=>$pass} ); + } + + return undef; +} + + 1;