:
#	@(#) mkrmpasswd 23.3 91/08/29 
#
#	Copyright (C) 1990-1991 The Santa Cruz Operation, Inc.
#	and SecureWare, Inc.	All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
# rmpasswd	--  Helper script for rmuser to remove account names
#		    from /etc/passwd and from the protected password database.
#
# Usage: rmpasswd 
#
# The account names to be removed are read from standard in
#
# NOTE this script is not intended to be called directly but via rmuser
# so that the necessary lock file is created beforehand.

# cleanup() - remove working copy of /etc/passwd
cleanup() { rm -f /tmp/passwd.ip; exit 1; }

trap 'echo "$0: Stopped"; cleanup' 1 2 3 15

# check the lock file has been created by ale
[ -f /etc/passwd-t ] || { echo "$0:/etc/passwd-t not created"; exit 1; }

# make working copy of /etc/passwd
cp /etc/passwd /tmp/passwd.ip

# check awk is executable
[ -x /usr/bin/awk ] || { echo "$0:/usr/bin/awk is not executable"; cleanup; }
# delete each account name read from stdin
while read account 
do awk '
	BEGIN 	{ FS=":"; none=1; }
		{ if ($1 == account) none=0; else print $0; }
	END 	{ if (none)
		  printf"%s: %s was not in /etc/passwd\n",name,account | \
		  "sh -c cat 1>&2"; }
' account=$account name=$0 /tmp/passwd.ip > /tmp/passwd.op

# reset working copy of /etc/passwd for next iteration
mv /tmp/passwd.op /tmp/passwd.ip

# remove the account's protected password entry
rm /tcb/files/auth/`expr $account : '\(.\)'`/"$account"
if [ -f /tcb/files/auth/`expr $account : '\(.\)'`/"$account"-o ]
then
	rm /tcb/files/auth/`expr $account : '\(.\)'`/"$account"-o
fi
if [ -f /tcb/files/auth/`expr $account : '\(.\)'`/"$account"-t ]
then
	rm /tcb/files/auth/`expr $account : '\(.\)'`/"$account"-t
fi
done

# cp the input file to the lock file
cp /tmp/passwd.ip /etc/passwd-t
rm /tmp/passwd.ip

exit 0
