
#	ATT ident	"sadmin:admin/menu/usermgmt/moduser/chgpasswd	2.3"

#ident	"@(#)sadmin/admin/menu/usermgmt/moduser:chgpasswd	25.1"

#menu# menu of commands to modify a user's login
#menu# change a user's password
#help# 
#help#	This procedure allows you to remove or change a user's password.
#help#	You cannot change the passwords of the administrative and system
#help#	logins.  To do that, see the system setup menu:  sysadm syssetup

#test if yellow page is up
ps -e > /tmp/t1
if grep ypbind /tmp/t1 > /dev/null
then
# if so, is this the yp master server?
	host=`uname -n`					
	master=`ypwhich`
	if test $host = $master; then
		flag=`cat /tmp/t1`
	else
		echo "Must be YP master server to execute chgpasswd\n"
		rm /tmp/t1
		exit 1
	fi
fi
rm /tmp/t1

minid=100	# Minimum user and group ID

trap 'exit 0' 1 2 15
flags="-qq -k$$"

echo 0 > /tmp/t0
while  true
do
	loginid=`checkre ${flags} -H'
	This is the "name" that the computer uses to identify the user.
	It also is used to identify data that belongs to the user.' \
		-fe "Enter user's login ID [?, q]:  " \
		-R ':' '":" is an illegal character.' \
		-r '.' 'You must enter a value.'`
	uid=`sed -n "/^${loginid}:/s/[^:]*:[^:]*:\([0-9]*\):.*/\1/p" /etc/passwd`
	if [ -z "${uid}" ]
	then
		echo "\\tLogin ID '${loginid}' does not exist.  Choose another."
		continue
	elif [ "${uid}" -lt ${minid} ]
	then
		echo "\\tThis login has user ID ${uid}, which is less than ${minid}.
This procedure will not change its password.  See the \"syssetup\" menu."
		continue
	fi

	if  /bin/passwd -s ${loginid} 2>/dev/null | grep "^${loginid}  *NP" 2>/dev/null 1>&2
	then
		/bin/passwd ${loginid}
		echo 1 > /tmp/t0
	else
		a=`checklist ${flags} -efp \
			'Do you want to change or delete the password? [c, d, q]' \
			change delete`
		case ${a} in
		change )
			/bin/passwd ${loginid}
			echo 1 > /tmp/t0
			;;
		delete )
			/bin/passwd -d ${loginid} 2>/dev/null
			if [ $? -ne 0 ]
			then
				admerr $0 'Cannot edit /etc/passwd.'
				exit 1
			fi
			echo 1 > /tmp/t0
		esac
	fi

	checkyn ${flags} -f \
		'Do you want to change the password on another login?'  ||
		break
done


#test if yellow page is up
ps -e > /tmp/t1
if grep ypbind /tmp/t1 > /dev/null
then
	flag=`cat /tmp/t0`
	rm /tmp/t0
	if test $flag -gt 0; then
		make -eif /etc/yp/Makefile
	fi
fi
