#!/usr/local/bin/perl5 -T

$OSH = "/usr/local/bin/osh";

# Just in case we need to clear the IFS for the system call below.
$ENV{'IFS'} = '' if $ENV{'IFS'};
$ENV{'PATH'} = '/bin:/sbin';

# These are programs that no checking needs to be done for them as far
# as I can tell.

# First we need to figure out which program it is.

if ($#ARGV ge 0) {
  print "Paramaters to GASH are not allowed.\n";
  exit(1);
}

# Get the user, which is the owner of the parent process since the
# current process was setuid(0) before spawning off.
#
# Btw, this is how `ps` gets the info for printing as well.
# By name.
#$USER=(getpwuid((stat("/proc/". getppid))[4]))[0];
# By UID.
$USER=(getpwuid((stat("/proc/". getppid))[4]))[2];

# Set the previously gotten UID.
$> = $< = $USER;

exit(system("/sbin/su", "- @ARGV") >> 8);
