From b385455b18ec7ada8ec8c9c5cc467fcf46bb5dfc Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Wed, 26 Sep 2007 11:05:33 +0000 Subject: * fixed problems with respect to installation of prerequired packages * added support for setting the root-password: + slxos-setup now queries for the root-password + 'busybox cryptpw' is used to determine the hashed password as required by the specific distribution (MD5 or Blowfish) git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1349 95ad53e4-c205-0410-b2fa-d234c58c8868 --- installer/OpenSLX/OSSetup/Distro/Base.pm | 51 ++++++++++++++++++++++++++++++ installer/OpenSLX/OSSetup/Distro/Debian.pm | 16 ++++++++++ installer/OpenSLX/OSSetup/Distro/SUSE.pm | 11 +++++++ installer/OpenSLX/OSSetup/Engine.pm | 45 +++++++++++++++++++++++--- installer/slxos-setup | 3 +- 5 files changed, 120 insertions(+), 6 deletions(-) (limited to 'installer') diff --git a/installer/OpenSLX/OSSetup/Distro/Base.pm b/installer/OpenSLX/OSSetup/Distro/Base.pm index d87f3d27..23f1e038 100644 --- a/installer/OpenSLX/OSSetup/Distro/Base.pm +++ b/installer/OpenSLX/OSSetup/Distro/Base.pm @@ -18,6 +18,7 @@ use warnings; our $VERSION = 1.01; # API-version . implementation-version +use Fcntl qw(:DEFAULT :flock); use File::Basename; use OpenSLX::Basics; use OpenSLX::Utils; @@ -216,6 +217,56 @@ sub postSystemInstallationHook { } +sub setPasswordForUser +{ + my $self = shift; + my $username = shift; + my $password = shift; + + my $hashedPassword = $self->hashPassword($password); + + my $writePasswordFunction = sub { + # now read, change and write shadow-file in atomic manner: + my $shadowFile = '/etc/shadow'; + slxsystem("cp -r $shadowFile $shadowFile~"); + my $shadowFH; + open($shadowFH, '+<', $shadowFile) + or croak _tr("could not open file '%s'! (%s)", $shadowFile, $!); + flock($shadowFH, LOCK_EX) + or croak _tr("could not lock file '%s'! (%s)", $shadowFile, $!); + my $content = do { local $/; <$shadowFH> }; + if ($content =~ m{^$username:}ims) { + my $lastChanged = int(time()/24/60/60); + my $newEntry + = "$username:$hashedPassword:$lastChanged:0:99999:7:::"; + $content =~ s{^$username:.+?$}{$newEntry}ms; + seek($shadowFH, 0, 0); + print $shadowFH $content; + } else { + warn _tr( + "user '%s' doesn't exist - unable to set password! (%s)", + $username + ); + } + close($shadowFH) + or croak _tr("could not close file '%s'! (%s)", $shadowFile, $!); +# unlink "$shadowFile~"; + }; + $self->{engine}->callChrootedFunctionForVendorOS($writePasswordFunction); +} + +sub hashPassword +{ + my $self = shift; + my $password = shift; + + my $busyboxBin = $self->{engine}->{'busybox-binary'}; + my $hashedPassword = qx{$busyboxBin cryptpw -a md5 $password}; + chomp $hashedPassword; + + return $hashedPassword; +} + 1; ################################################################################ diff --git a/installer/OpenSLX/OSSetup/Distro/Debian.pm b/installer/OpenSLX/OSSetup/Distro/Debian.pm index 4cd921de..e430abd4 100644 --- a/installer/OpenSLX/OSSetup/Distro/Debian.pm +++ b/installer/OpenSLX/OSSetup/Distro/Debian.pm @@ -96,4 +96,20 @@ sub postSystemInstallationHook $self->SUPER::postSystemInstallationHook(); } +sub setPasswordForUser +{ + my $self = shift; + my $username = shift; + my $password = shift; + + # activate shadow passwords + my $activateShadowFunction = sub { + slxsystem('/sbin/shadowconfig', 'on'); + }; + $self->{engine}->callChrootedFunctionForVendorOS($activateShadowFunction); + + # invoke default behaviour + $self->SUPER::setPasswordForUser($username, $password); +} + 1; \ No newline at end of file diff --git a/installer/OpenSLX/OSSetup/Distro/SUSE.pm b/installer/OpenSLX/OSSetup/Distro/SUSE.pm index 2ea20fc3..c6d81747 100644 --- a/installer/OpenSLX/OSSetup/Distro/SUSE.pm +++ b/installer/OpenSLX/OSSetup/Distro/SUSE.pm @@ -70,5 +70,16 @@ sub updateDistroConfig return; } +sub hashPassword +{ + my $self = shift; + my $password = shift; + + my $busyboxBin = $self->{engine}->{'busybox-binary'}; + my $hashedPassword = qx{$busyboxBin cryptpw -a blowfish '$password'}; + chomp $hashedPassword; + + return $hashedPassword; +} 1; diff --git a/installer/OpenSLX/OSSetup/Engine.pm b/installer/OpenSLX/OSSetup/Engine.pm index 46bccc75..a3092b24 100644 --- a/installer/OpenSLX/OSSetup/Engine.pm +++ b/installer/OpenSLX/OSSetup/Engine.pm @@ -263,6 +263,7 @@ sub initialize sub installVendorOS { my $self = shift; + my $vendorOSSettings = shift; my $installInfoFile = "$self->{'vendor-os-path'}/.openslx-install-info"; if (-e $installInfoFile) { @@ -301,11 +302,16 @@ sub installVendorOS ); # create the install-info file, in order to indicate a proper installation: - spitFile($installInfoFile, - "SLX_META_PACKAGER=$self->{distro}->{'meta-packager-type'}\n"); + spitFile( + $installInfoFile, + "SLX_META_PACKAGER=$self->{distro}->{'meta-packager-type'}\n" + ); + + # base system info file is no longer needed, we have a full system now slxsystem("rm $baseSystemFile"); - # no longer needed, we have a full system now + $self->_applyVendorOSSettings($vendorOSSettings) unless !$vendorOSSettings; + vlog( 0, _tr( @@ -950,6 +956,22 @@ sub _expandSelection return; } +sub _applyVendorOSSettings +{ + my $self = shift; + my $vendorOSSettings = shift; + + if (exists $vendorOSSettings->{'root-password'}) { + # hashes password according to requirements of current distro and + # writes it to /etc/shadow + $self->{distro}->setPasswordForUser( + 'root', $vendorOSSettings->{'root-password'} + ); + } + + return; +} + sub _createVendorOSPath { my $self = shift; @@ -1320,7 +1342,12 @@ sub _stage1B_chrootAndBootstrap ); $self->{'baseURL-index'} = 0; my @pkgs = string2Array($self->{'distro-info'}->{'prereq-packages'}); + vlog( + 2, + "downloading these prereq packages:\n\t" . join("\n\t", @pkgs) + ); my @prereqPkgs = $self->_downloadBaseFiles(\@pkgs); + $self->{'prereq-packages'} = \@prereqPkgs; $self->{packager}->bootstrap(\@prereqPkgs); @pkgs = string2Array($self->{'distro-info'}->{'bootstrap-packages'}); @@ -1328,9 +1355,13 @@ sub _stage1B_chrootAndBootstrap @pkgs, string2Array( $self->{'distro-info'}->{'metapackager'} - ->{$self->{distro}->{'meta-packager-type'}} + ->{$self->{distro}->{'meta-packager-type'}}->{packages} ) ); + vlog( + 2, + "downloading bootstrap packages:\n\t" . join("\n\t", @pkgs) + ); my @bootstrapPkgs = $self->_downloadBaseFiles(\@pkgs); $self->{'bootstrap-packages'} = \@bootstrapPkgs; }, @@ -1368,7 +1399,11 @@ sub _stage1C_chrootAndInstallBasicVendorOS $self->{packager}->importTrustedPackageKeys(\@keyFiles, $stage1cDir); } - # install all bootstrap packages + # install prerequired packages (if distro requires it) + $self->{packager}->installPrerequiredPackages( + $self->{'prereq-packages'}, $stage1cDir + ); + # install bootstrap packages $self->{packager}->installPackages( $self->{'bootstrap-packages'}, $stage1cDir ); diff --git a/installer/slxos-setup b/installer/slxos-setup index b7461deb..4ad9f0c8 100755 --- a/installer/slxos-setup +++ b/installer/slxos-setup @@ -121,7 +121,8 @@ if ($action =~ m[^import]i) { chdir($FindBin::RealBin) or die _tr("can't chdir to script-path <%> (%s)", $FindBin::RealBin, $!); $engine->initialize($vendorOSName, 'install'); - $engine->installVendorOS(); + my $rootPassword = readPassword("root-password for new system> "); + $engine->installVendorOS({ 'root-password' => $rootPassword }); } elsif ($action =~ m[^clone]i) { my $source = shift @ARGV; my $vendorOSName = shift @ARGV; -- cgit v1.2.3-55-g7522