#!/bin/sh
#
# yppasswdd	NIS password changing server
#
# chkconfig:	345 43 62
#
# description:	yppasswdd is the RPC server that lets users change their \
#		passwords in the presence of NIS (a.k.a. YP).  It must be \
#		run on the NIS master server for that NIS domain.  The client \
#		program is knwon as yppasswd in most cases.
# processname:	rpc.yppasswdd


# Source function library
. /etc/rc.d/init.d/functions

# Get network config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/yppasswdd ] && . /etc/sysconfig/yppasswdd

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down "NIS passwd"
		exit 1
	fi
else
	exit 0
fi

if [ "$YPFILEDIR" ]; then
	YPSTRING=" -D $YPFILEDIR"
fi

if [ "$YPEDITPROG" ]; then
	YPSTRING="$YPSTRING -E $YPEDITPROG"
fi

if [ "$YPPWDFILE" ]; then
	YPSTRING="$YPSTRING -p $YPPWDFILE"
fi

if [ "$YPSHADOWFILE" ]; then
	YPSTRING="$YPSTRING -s $YPSHADOWFILE"
fi

if [ "$YPMODPROG" ]; then
	YPSTRING="$YPSTRING -x $YPMODPROG"
fi

check_nisdomain()
{
	if [ -n "$NISDOMAIN" ]; then
		return 0
	else
		nls "Setup /etc/sysconfig/network::NISDOMAIN before use %s." yppasswdd >&2
		exit 6
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	check_nisdomain
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/yppasswdd ]; then
		msg_starting "NIS passwd"
		if [ "$YPSTRING" ]; then
			daemon rpc.yppasswdd $YPSTRING
		else
			daemon rpc.yppasswdd
		fi
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/yppasswdd
	else
		msg_already_running "NIS passwd"
	fi
	;;
  stop)
	check_nisdomain
	if [ -f /var/lock/subsys/yppasswdd ]; then
		msg_stopping "NIS passwd"
		killproc rpc.yppasswdd
		rm -f /var/lock/subsys/yppasswdd
	else
		msg_not_running "NIS passwd"
	fi
	;;
  status)
	check_nisdomain
	status rpc.yppasswdd
	exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
