From 5eb8bbe3a84c6ad741bc123ccaec5bddfa5d9961 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 6 Mar 2008 19:56:38 +0000 Subject: * improved setting a password such that is able to cope with a non-existing /etc/shadow git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1609 95ad53e4-c205-0410-b2fa-d234c58c8868 --- installer/OpenSLX/OSSetup/Distro/Base.pm | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'installer') diff --git a/installer/OpenSLX/OSSetup/Distro/Base.pm b/installer/OpenSLX/OSSetup/Distro/Base.pm index b05e5cfe..a3753b1f 100644 --- a/installer/OpenSLX/OSSetup/Distro/Base.pm +++ b/installer/OpenSLX/OSSetup/Distro/Base.pm @@ -233,29 +233,31 @@ sub setPasswordForUser my $writePasswordFunction = sub { # now read, change and write shadow-file in atomic manner: my $shadowFile = '/etc/shadow'; + if (!-e $shadowFile) { + spitFile( $shadowFile, ''); + } 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 $lastChanged = int(time()/24/60/60); + my $newEntry + = "$username:$hashedPassword:$lastChanged:0:99999:7:::"; 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 - ); + $content .= "$newEntry\n"; } + seek($shadowFH, 0, 0) + or croak _tr("could not seek file '%s'! (%s)", $shadowFile, $!); + print $shadowFH $content + or croak _tr("could not write to file '%s'! (%s)", $shadowFile, $!); close($shadowFH) or croak _tr("could not close file '%s'! (%s)", $shadowFile, $!); -# unlink "$shadowFile~"; + unlink "$shadowFile~"; }; $self->{engine}->callChrootedFunctionForVendorOS($writePasswordFunction); } -- cgit v1.2.3-55-g7522