#! /bin/sh
#
# |-----------------------------------------------------------|
# | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
# | All Rights Reserved                                       |
# |-----------------------------------------------------------|
# |          Restricted Rights Legend                         |
# | Use, duplication, or disclosure by the Government is      |
# | subject to restrictions as set forth in                   |
# | subparagraph (c)(1)(ii) of the Rights in Technical        |
# | Data and Computer Software Clause of DFARS 252.227-7013.  |
# |         MIPS Computer Systems, Inc.                       |
# |         950 DeGuigne Avenue                               |
# |         Sunnyvale, California 94088-3650, USA             |
# |-----------------------------------------------------------|
#
# $Header: unixadmin.sh,v 1.7.2.1 92/06/24 13:47:19 marker Exp $
#	General purpose hook into administrative logins used as commands,
#	so that the commands can have passwords on them.

set -f
PATH=${PATH:-/bin:/usr/bin}:/usr/lbin
export PATH
cmd=`basename $0`
if  grep "^${cmd}:" /etc/passwd >/dev/null
then
	# Magic here!
	# The problem is that we want the commands to (potentially) have a
	# password, so that they can be restricted if the user likes, and
	# to be within the restricted shell so that the user can not break out
	# and become super-user.  The complication is that we want the command
	# to have arguments, but /bin/su will not permit arguments to something
	# that has /bin/rsh as its login shell and /bin/su clears out the
	# environment when the - argument is used.  So we open another File
	# Descriptor and ship the arguments in via a pipe.
	#	make File Descriptor 4 the same as 0 (standard input)
	exec 4<&0
	#	echo the arguments down a pipe.  On the receiving end,
	#	connect the pipe to File Descriptor 3 and connect the original
	#	standard input, available on FD 4, to FD 0.  Lastly, close FD 4.
	#	See the .profile file (admin profile.dot) for how the arguments
	#	are read.
	echo $*  |  3<&0 0<&4 4<&- /bin/su - ${cmd}
else
	admerr $0 Command ${cmd} does not exist in /etc/passwd.
	exit 1
fi
