-Have stateless setup root login from console

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1305 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2008-05-07 14:51:12 +00:00
parent e9457c3914
commit 806b5ce7ce
3 changed files with 67 additions and 0 deletions

View File

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

View File

@ -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/) {

View File

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