:
#	@(#) mkchtype 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.
#
# chtype	--  Helper script for unretire to change the type field
#		    of a retired account in the protected password database
#
# Usage: chtype usertype account
#
# where usertype is one of sso admin pseudo operator or retired.  
# If the usertype is retired then set user type to 'retired' and set the
# encrypted password string (if any) to a star '*'.  Otherwise the
# account is being unretired, if the account is not owned then
# set the user type to 'general' otherwise set the user type to usertype
# specified.
#
# NOTE this script is not intended to be called directly but via unretire
# so that the necessary lock file is created beforehand.
#

# generate name of the protected password file for the account
prpw="/tcb/files/auth/`expr $2 : '\(.\)'`/$2"

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

# change the account type
if [ "$1" = "retired" ]
then
	if /bin/grep retired "$prpw" >/dev/null
	then
		/bin/echo "$0: $2 is already retired"
		exit 2
	else
		sed "s/u_type=general/u_type=$1/; \
		s/u_type=pseudo/u_type=$1/; \
		s/u_type=sso/u_type=$1/; \
		s/u_type=admin/u_type=$1/; \
		s/u_type=operator/u_type=$1/; \
		s/u_pwd=.*:/u_pwd=*:/" < "$prpw" > "$prpw-t"
	fi

elif /bin/grep retired "$prpw" >/dev/null
then
	if /bin/grep u_owner "$prpw" >/dev/null
	then
		sed "s/u_type=retired/u_type=$1/; \
		s/u_pwd=.*:/u_pwd=*UNRETIRED*:/" < "$prpw" > "$prpw-t"
	else
		sed "s/u_type=retired/u_type=general/; \
		s/u_pwd=.*:/u_pwd=*UNRETIRED*:/" < "$prpw" > "$prpw-t"
	fi
else
	/bin/echo "$0: $2 is not retired"
	exit 2
fi

exit 0
