1
0
mirror of synced 2026-01-21 17:55:25 +00:00

2006-03-29 07:33:13 by steve

Only mess with /etc/shadow + /etc/passwd if --passwd is *not* used.
This commit is contained in:
steve 2006-03-29 07:33:13 +00:00
parent ff8a8e6d0f
commit 8cc0a3732e

View File

@ -4,7 +4,8 @@
# system.
#
# At the same time it tries to copy all non-system accounts from
# the host system into the new guest.
# the host system into the new guest unless the root password is
# being setup with --passwd.
#
# Steve
# --
@ -31,7 +32,6 @@ die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" );
# Copy some files literally.
#
my @files = ( "/etc/hosts",
"/etc/shadow",
"/etc/resolv.conf"
);
@ -41,6 +41,15 @@ foreach my $file ( @files )
}
#
# Only copy the /etc/shadow file if --passwd is *not* specified.
#
if ( !$ENV{'passwd'} )
{
File::Copy::copy( "/etc/shadow", $prefix . "/etc/" );
}
#
# If sudo is installed upon the host then install it upon the guest,
@ -57,27 +66,33 @@ if ( ( -e "/etc/sudoers" ) && ( -x $prefix . "/usr/bin/apt-get" ) )
#
# Now modify the password file.
# Now modify the password file *unless* the "--passwd" option
# was given.
#
#
open( ORIG, "<", "/etc/passwd" ) or die "Failed to open /etc/passwd - $!";
open( NEW, ">>", $prefix . "/etc/passwd" ) or die "Failed to open $prefix/etc/passwd - $!";
foreach my $line ( <ORIG> )
if ( ! ENV{'passwd'} )
{
chomp( $line );
if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ )
open( ORIG, "<", "/etc/passwd" )
or die "Failed to open /etc/passwd - $!";
open( NEW, ">>", $prefix . "/etc/passwd" )
or die "Failed to open $prefix/etc/passwd - $!";
foreach my $line ( <ORIG> )
{
my $user = $1;
my $pass = $2;
my $uid = $3;
if ( ( $uid >= 1000 ) &&
( $user ne "nobody" ) )
chomp( $line );
if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ )
{
print NEW $line . "\n";
my $user = $1;
my $pass = $2;
my $uid = $3;
if ( ( $uid >= 1000 ) &&
( $user ne "nobody" ) )
{
print NEW $line . "\n";
}
}
}
close( NEW );
close( ORIG );
}
close( NEW );
close( ORIG );