From 8cc0a3732ea04865b42a85f9748321564496508a Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 29 Mar 2006 07:33:13 +0000 Subject: [PATCH] 2006-03-29 07:33:13 by steve Only mess with /etc/shadow + /etc/passwd if --passwd is *not* used. --- etc/hook.d/60-copy-host-files | 51 ++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/etc/hook.d/60-copy-host-files b/etc/hook.d/60-copy-host-files index 9fa7d3b..5da109a 100755 --- a/etc/hook.d/60-copy-host-files +++ b/etc/hook.d/60-copy-host-files @@ -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 ( ) +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 ( ) { - 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 );