
#	ATT: ident	"sadmin:admin/menu/syssetup/syspasswd	2.2"

#ident	"@(#)sadmin/admin/menu/syssetup:syspasswd	25.1"

#menu# assign system passwords
#help# 
#help#	Syspasswd lets you set system passwords normally reserved for the
#help#	very knowledgeable user.  For this reason, this procedure may assign
#help#	those passwords, but may not change or clear them.  Once set, they
#help#	may only be changed by the specific login or the "root" login, using
#help#	the passwd command to change the password.  Therefore, set them with
#help#	care!

#	system logins are those in the /etc/passwd file with user ID < 100
#	and that are not Simple Administration logins.

#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 syspasswd\n"
		rm /tmp/t1
		exit 1
	fi
fi
rm /tmp/t1
admlogins=`ls -p ${MENUTOP:?}`
syslogs=`sed -n '/^[^:]*:[^:]*:.\{1,2\}:/s/:.*//p' /etc/passwd  |
		fgrep -vx "${admlogins}"`

# get system logins which do not have a password
syslogins=`
	for sys in $syslogs
	do
		if /bin/passwd -s $sys 2>/dev/null | grep "^$sys  *NP" >/dev/null
		then
			echo $sys
		fi
	done`

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

if [ -z "${syslogins}" ]
then
	echo >&2 '
	All the system logins on this machine have passwords.
To change the password of one of those logins, you must either login as
that ID, which means you must know the current password, or as "root",
which means you must know the root password.  Use the passwd command to
change the password.
'
	exit 0
fi

echo 0 > /tmp/t0
if  checkyn ${flags} -H "!sed -n '/^#help#/s///p' $0" \
	'Do you want to give passwords to system logins?'
then
	for login in ${syslogins}
	{
		if  checkyn ${flags} \
			-H "!echo 'This login is identified in the password file as:\\n\\t\\c'
			grep '^${login}:' /etc/passwd  |  cut -d: -f5" \
			"Do you want to give the '${login}' login a password?"
		then
			/bin/passwd ${login}
			echo 1 > /tmp/t0
		fi
	}
fi


#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

syslogins=`
	for sys in $syslogs
	do
		if /bin/passwd -s $sys 2>/dev/null | grep "^$sys  *NP" >/dev/null
		then
			echo $sys
		fi
	done`

if [ -n "${syslogins}" ]
then
	echo "${syslogins}" | sort  |
		sed '1i\
	echo "The following system logins still do not have passwords:"\
	pr -t -5 -o5 -w75 <<!
		$a\
!
		'  |
		sh
fi
