Index: sudoshell-in =================================================================== RCS file: /cvsroot/sudoscript/sudoscript/sudoshell-in,v retrieving revision 1.3 retrieving revision 1.5 diff -u -r1.3 -r1.5 --- sudoshell 18 Jun 2003 21:10:15 -0000 1.3 +++ sudoshell 4 Jun 2004 00:54:40 -0000 1.5 @@ -1,5 +1,5 @@ #/usr/bin/perl -#$Id: sudoshell-in,v 1.3 2003/06/18 21:10:15 hbo Exp $ +#$Id: sudoshell-in,v 1.5 2004/06/04 00:54:40 hbo Exp $ use Fcntl qw(O_RDWR O_WRONLY); use POSIX qw(pause); @@ -12,9 +12,10 @@ my $ss=Sudoscript->new(); exit if (! defined $ss); -my ($user); +my ($user,$newenv); GetOptions( "user:s" => \$user, + "" => \$newenv, ); my $GREP = $ss->GREP(); @@ -39,11 +40,15 @@ if ($uid != $>){ # We have not become the requested user yet # Call sudo to give us the right identity. - exec "$SUDO -u $user $0 -u $user"; + my $reexec="$SUDO -u $user $0 -u $user"; + $reexec .= " -" if ($newenv); + exec $reexec; } # Otherwise, check if we are root. } elsif ($>){ # No -u and not run as root. Try sudo - exec "$SUDO $0"; + my $reexec= "$SUDO $0"; + $reexec .= " -" if ($newenv); + exec $reexec; } # We are either root or the -u user here forward @@ -64,9 +69,15 @@ } # Get the name we came from, if available. -# (SUDO_UID could be blank, if root ran us to start with. In that case we get the name from the first getpwuid above.) -($name) =getpwuid $ENV{SUDO_UID} if ($ENV{SUDO_UID}); - +# (SUDO_UID could be blank, if root ran us to start with. In that +# case we get the name from the first getpwuid above.) +($name) = getpwuid $ENV{SUDO_UID} if ($ENV{SUDO_UID}); + +# Get the home directory of the effective uid, if we need it. +if ($newenv){ + my ($n,$p,$u,$g,$q,$c,$gc,$home) = getpwuid $>; + $ENV{HOME} = $home; +} # Open the master daemon's front-end FIFO if it exists # (This is why we need rwx perms for group to $fifodir.) @@ -111,6 +122,7 @@ # Here we go my $script=$ss->SCRIPT(); + system "$script $fifo2"; # script(1) session has finished