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 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'installer/OpenSLX/OSSetup/Distro/Base.pm') 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; ################################################################################ -- cgit v1.2.3-55-g7522