diff --git a/perl-xCAT-2.0/xCAT/Utils.pm b/perl-xCAT-2.0/xCAT/Utils.pm index c634f681d..30f976f2f 100644 --- a/perl-xCAT-2.0/xCAT/Utils.pm +++ b/perl-xCAT-2.0/xCAT/Utils.pm @@ -8,6 +8,41 @@ require xCAT::Schema; require Data::Dumper; require xCAT::NodeRange; require DBI; +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(genpassword); + +#-------------------------------------------------------------------------------- +=head3 genpassword + returns a random string of specified length or 8 if none given + Arguments: + length of string requested + Returns: + string of requested length or 8 + Globals: + none + Error: + none + Example: + my $salt = genpassword(8); + Comments: + none +=cut + +#-------------------------------------------------------------------------------- +sub genpassword { +#Generate a pseudo-random password of specified length + my $length = shift; + unless ($length) { $length = 8; } + my $password=''; + my $characters= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890'; + srand; #have to reseed, rand is not rand otherwise + while (length($password) < $length) { + $password .= substr($characters,int(rand 63),1); + } + return $password; +} + + #-------------------------------------------------------------------------------- diff --git a/xCAT-server-2.0/lib/xcat/plugins/packimage.pm b/xCAT-server-2.0/lib/xcat/plugins/packimage.pm index 99ff819ef..3bf557261 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/packimage.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/packimage.pm @@ -5,6 +5,7 @@ use File::Path; use File::Copy; use Cwd; use File::Temp; +use xCAT::Utils qw(genpassword); Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); @@ -83,6 +84,21 @@ sub process_request { # add the xCAT post scripts to the image copybootscript($installroot, $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 $shadow; + open($shadow,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/shadow"); + unless ($pass =~ /^\$1\$/) { + $pass = crypt($pass,'$1$'.genpassword(8)); + } + print $shadow "root:$pass:13880:0:99999:7:::\n"; + close($shadow); + } + } + my $verb = "Packing"; if ($method =~ /nfs/) { diff --git a/xCAT-server-2.0/share/xcat/netboot/rh/genimage b/xCAT-server-2.0/share/xcat/netboot/rh/genimage index 6d26d4c83..e748465a4 100755 --- a/xCAT-server-2.0/share/xcat/netboot/rh/genimage +++ b/xCAT-server-2.0/share/xcat/netboot/rh/genimage @@ -397,6 +397,22 @@ sub generic_post { #This function is meant to leave the image in a state approxi print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n"; close($cfgfile); } + open($cfgfile,">>","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/securetty"); + print $cfgfile "ttyS0\n"; + print $cfgfile "ttyS1\n"; + close($cfgfile); + my @passwd; + open($cfgfile,"<","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/passwd"); + @passwd = <$cfgfile>; + close($cfgfile); + open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/passwd"); + foreach (@passwd) { + if (/^root:/) { + s/^root:\*/root:x/ + } + print $cfgfile $_; + } + close($cfgfile); open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc3.d/S60gettyset"); print $cfgfile "#!/bin/bash\n"; print $cfgfile "for i in `cat /proc/cmdline`; do\n";