diff --git a/perl-xCAT/xCAT/PPCdb.pm b/perl-xCAT/xCAT/PPCdb.pm index 8b50563b7..0bf2a2d7d 100644 --- a/perl-xCAT/xCAT/PPCdb.pm +++ b/perl-xCAT/xCAT/PPCdb.pm @@ -769,26 +769,31 @@ sub credentials { ########################################### # Check passwd tab ########################################### - my $tab = xCAT::Table->new( 'passwd' ); - if ( $tab ) { - 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}; } - } + #my $tab = xCAT::Table->new( 'passwd' ); + #if ( $tab ) { + #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}; } + # } + #} + my ($ent) = get_usr_passwd($hwtype, $user); + if ($ent) { + if (defined($ent->{password})) { $pass = $ent->{password};} + if (defined($ent->{username})) { $user = $ent->{username};} } ########################################## # Check table based on specific node ########################################## - $tab = xCAT::Table->new( $hcptab{$hwtype} ); + my $tab = xCAT::Table->new( $hcptab{$hwtype} ); if ( $tab ) { my $ent; if ( $user_specified) @@ -825,6 +830,60 @@ sub credentials { return( $user,$pass ); } +########################################################################## +# Get password for user in 'passwd' table, if doesn't exist, use default +# password for this user. +########################################################################## +my %power_accounts = ( + HMC => 'abc123', + general => 'general', + admin => 'admin', +); +my %default_passwd_accounts = ( + system => { root => 'cluster',}, + hmc => { hscroot => 'abc123',}, + fsp => \%power_accounts, + bpa => \%power_accounts, + frame => \%power_accounts, + cec => \%power_accounts, + blade => { USERID => 'PASSW0RD',}, + ipmi => { USERID => 'PASSW0RD',}, + ivm => { padmin => 'padmin',}, + vmware => { root => '',}, + vcenter => { Administrator => ''}, +); + +sub get_usr_passwd { + my $key = shift; + if ($key && ($key =~ /xCAT::/)) { + $key = shift; + } + my $user = shift; + my $ent; + my $passwdtab = xCAT::Table->new('passwd'); + if (!$passwdtab) { + return undef; + } + if ($user) { + ($ent) = $passwdtab->getAttribs({key => $key, username => $user}, qw(password cryptmethod)); + } else { + ($ent) = $passwdtab->getNodeAttribs($key, qw(username password)); + } + if (!$ent or !$ent->{password}) { + my $hash = $default_passwd_accounts{$key}; + if (!$hash or ($user and !defined($hash->{$user}))) { + return undef; + } + if (!$user) { + my @tmp_keys = keys (%$hash); + $user = $tmp_keys[0]; + } + $ent->{username} = $user; + $ent->{password} = $hash->{$user}; + } + return $ent; +} + ########################################################################## # Set userids and passwords to tables ########################################################################## diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 1d661d682..7945769c4 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -308,19 +308,22 @@ sub makescript #$os =~ tr/A-Z/a-z/; # Convert to lowercase if ($os eq "aix" || $os eq "AIX") { - my $passwdtab = xCAT::Table->new('passwd'); - unless ($passwdtab) - { - my $rsp; - push @{$rsp->{data}}, "Unable to open passwd table."; - xCAT::MsgUtils->message("E", $rsp, $callback); - } + # my $passwdtab = xCAT::Table->new('passwd'); + # unless ($passwdtab) + # { + # my $rsp; + # push @{$rsp->{data}}, "Unable to open passwd table."; + # xCAT::MsgUtils->message("E", $rsp, $callback); + # } - if ($passwdtab) + # if ($passwdtab) + # { + # my $et = + # $passwdtab->getAttribs({key => 'system', username => 'root'}, + # 'password', 'cryptmethod'); { - my $et = - $passwdtab->getAttribs({key => 'system', username => 'root'}, - 'password', 'cryptmethod'); + use xCAT::PPCdb qw(get_usr_passwd); + my $et = xCAT::PPCdb::get_usr_passwd('system', 'root'); if ($et and defined($et->{'password'})) { push @scriptd, "ROOTPW=" . $et->{'password'} . "\n"; diff --git a/xCAT-server/lib/xcat/plugins/aixinstall.pm b/xCAT-server/lib/xcat/plugins/aixinstall.pm index 33a1753d0..a71d421f7 100644 --- a/xCAT-server/lib/xcat/plugins/aixinstall.pm +++ b/xCAT-server/lib/xcat/plugins/aixinstall.pm @@ -3531,7 +3531,7 @@ sub mknimimage # # Set root password in diskless images # - my $rootpw; + my $rootpw = 'cluster'; my $method; if (($::NIMTYPE eq "diskless") || ($::NIMTYPE eq "dataless")) { diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index 0cff3afeb..10e5164bd 100644 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -292,27 +292,28 @@ sub process_request { copybootscript($installroot, $rootimg_dir, $osver, $arch, $profile, $callback); my $passtab = xCAT::Table->new('passwd'); if ($passtab) { - (my $pent) = $passtab->getAttribs({key=>'system',username=>'root'},'password'); - if ($pent and defined ($pent->{password})) { - my $pass = $pent->{password}; - my $oldmask=umask(0077); - my $shadow; - open($shadow,"<","$rootimg_dir/etc/shadow"); - my @shadents = <$shadow>; - close($shadow); - open($shadow,">","$rootimg_dir/etc/shadow"); - unless ($pass =~ /^\$1\$/) { - $pass = crypt($pass,'$1$'.genpassword(8)); - } - print $shadow "root:$pass:13880:0:99999:7:::\n"; - foreach (@shadents) { - unless (/^root:/) { - print $shadow "$_"; - } - } - close($shadow); - umask($oldmask); - } + my $pass = 'cluster'; + (my $pent) = $passtab->getAttribs({key=>'system',username=>'root'},'password'); + if ($pent and defined ($pent->{password})) { + $pass = $pent->{password}; + } + my $oldmask=umask(0077); + my $shadow; + open($shadow,"<","$rootimg_dir/etc/shadow"); + my @shadents = <$shadow>; + close($shadow); + open($shadow,">","$rootimg_dir/etc/shadow"); + unless ($pass =~ /^\$1\$/) { + $pass = crypt($pass,'$1$'.genpassword(8)); + } + print $shadow "root:$pass:13880:0:99999:7:::\n"; + foreach (@shadents) { + unless (/^root:/) { + print $shadow "$_"; + } + } + close($shadow); + umask($oldmask); } # sync fils configured in the synclist to the rootimage diff --git a/xCAT-server/lib/xcat/plugins/statelite.pm b/xCAT-server/lib/xcat/plugins/statelite.pm index 94665a1a0..eb87aa265 100644 --- a/xCAT-server/lib/xcat/plugins/statelite.pm +++ b/xCAT-server/lib/xcat/plugins/statelite.pm @@ -163,9 +163,11 @@ sub process_request { #get the root password for the node my $passtab = xCAT::Table->new('passwd'); if ($passtab) { + my $pass = 'cluster'; (my $pent) = $passtab->getAttribs({key=>'system',username=>'root'},'password'); if ($pent and defined ($pent->{password})) { - my $pass = $pent->{password}; + $pass = $pent->{password}; + } my $oldmask=umask(0077); my $shadow; open($shadow,"<","$rootimg_dir/etc/shadow"); @@ -183,7 +185,6 @@ sub process_request { } close($shadow); umask($oldmask); - } } # sync fils configured in the synclist to the rootimage