# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#ident	"$Header: syspasswd 1.3 89/10/10 $@(#)sadmin:admin/menu/syssetup/syspasswd	2.4"
#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.
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

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}
		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
