:
#	@(#) mkrmshadow 23.2 91/08/29 
#
#	Copyright (C) 1991 The Santa Cruz Operation, 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.
#
# rmshadow	--  Helper script for rmuser to remove account names
#		    from /etc/shadow.
#
# Usage: rmshadow 
#
# 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/shadow
cleanup() { rm -f /tmp/shadow.ip; exit 1; }

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

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

# make working copy of /etc/shadow
cp /etc/shadow /tmp/shadow.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/shadow\n",name,account | \
		  "sh -c cat 1>&2"; }
' account=$account name=$0 /tmp/shadow.ip > /tmp/shadow.op

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

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

exit 0
