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
This commit is contained in:
wanghuaz 2009-12-29 11:42:49 +00:00
parent c67a44d85f
commit ec6154e11e
3 changed files with 107 additions and 7 deletions

View File

@ -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

View File

@ -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 );
}

View File

@ -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;