cvsdist 5d711fc
#!/bin/bash
cvsdist 4760d43
#
cvsdist 4760d43
# ypbind:       Starts the ypbind Daemon
cvsdist 4760d43
#
cvsdist e4e7a5e
# Version:      @(#) /etc/init.d/ypbind.init 1.3
cvsdist 4760d43
#
cvsdist 5d711fc
# chkconfig: - 27 73
cvsdist 4760d43
# description: This is a daemon which runs on NIS/YP clients and binds them \
cvsdist 4760d43
#              to a NIS domain. It must be running for systems based on glibc \
cvsdist 4760d43
#              to work as NIS clients, but it should not be enabled on systems \
cvsdist 4760d43
#              which are not using NIS.
cvsdist 4760d43
# processname: ypbind
cvsdist 4760d43
# config: /etc/yp.conf
cvsdist 4760d43
cvsdist 4760d43
OTHER_YPBIND_OPTS=""
cvsdist 4760d43
cvsdist 4760d43
# Source function library.
cvsdist 4760d43
. /etc/init.d/functions
cvsdist 4760d43
cvsdist 89f8fe4
. /etc/sysconfig/network
cvsdist 89f8fe4
ba6a769
# Check for and source configuration file otherwise set defaults
ba6a769
[ -f /etc/sysconfig/ypbind ] && . /etc/sysconfig/ypbind
ba6a769
713c992
# NISTIMEOUT should be a multiple of 15 since
713c992
# ypwhich has a hardcoded 15sec timeout
713c992
[ -z "$NISTIMEOUT" ] && NISTIMEOUT=45
c06376c
cvsdist 5d711fc
# Check that networking is configured.
441536a
[ "${NETWORKING}" = "no" ] && exit 0
cvsdist 5d711fc
26d8418
selinux_on() {
26d8418
        [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return
713c992
	#echo $"Turning on allow_ypbind SELinux boolean"
26d8418
        setsebool allow_ypbind=1
26d8418
}
26d8418
26d8418
selinux_off() {
26d8418
        [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return
26d8418
	allow_ypbind=0
26d8418
	.  /etc/selinux/config
2fb6b54
	if [ -e /etc/selinux/${SELINUXTYPE}/modules/active/booleans.local ]; then
26d8418
		. /etc/selinux/${SELINUXTYPE}/modules/active/booleans.local
26d8418
	fi
26d8418
	if [ $allow_ypbind == 0 ]; then
713c992
		#echo $"Turning off allow_ypbind SELinux boolean"
26d8418
		setsebool allow_ypbind=$allow_ypbind
26d8418
	fi
26d8418
}
26d8418
cvsdist 4760d43
start() {
cvsdist 89f8fe4
	DOMAINNAME=`domainname`
cvsdist 89f8fe4
	if [ "$DOMAINNAME" = "(none)" -o "$DOMAINNAME" = "" ]; then
2ca3c2a
		echo -n $"Setting NIS domain: "
713c992
		if [ -n "$NISDOMAIN" ]; then
713c992
			action $"domain is '$NISDOMAIN' " domainname $NISDOMAIN
713c992
		else # See if the domain is set in config file
713c992
			NISDOMAIN=`grep "domain" /etc/yp.conf | grep -v ^# | \
713c992
				awk '{print $2}'`
713c992
	   		if [ -n "$NISDOMAIN" ]; then
713c992
				action $"domain is '$NISDOMAIN' " \
713c992
					domainname $NISDOMAIN
713c992
	   		else
713c992
				action $"domain not found" /bin/false
713c992
				logger -t ypbind $"domain not found"
713c992
	        		return 1
713c992
			fi
713c992
		fi
cvsdist 89f8fe4
	fi
713c992
	echo -n $"Starting NIS service: "
713c992
	selinux_on
cvsdist 4760d43
	daemon ypbind $OTHER_YPBIND_OPTS
cvsdist a2190fb
	RETVAL=$?
cvsdist 4760d43
	echo
cvsdist a2190fb
	if [ $RETVAL -ne 0 ]; then
26d8418
	    selinux_off
713c992
	    logger -t ypbind "failed to start!"
cvsdist a2190fb
	    return $RETVAL
cvsdist a2190fb
	fi
2ca3c2a
	echo -n $"Binding NIS service: "
cvsdist a2190fb
	# the following fixes problems with the init scripts continuing
cvsdist 4760d43
	# even when we are really not bound yet to a server, and then things
cvsdist 4760d43
	# that need NIS fail.
d5fb252
	timeout=10
74c49f9
	firsttime=1
74c49f9
        SECONDS=0
74c49f9
	while [ $SECONDS -lt $timeout ]; do
d5fb252
		if /usr/sbin/rpcinfo -p | LC_ALL=C fgrep -q ypbind
d5fb252
		then
74c49f9
			if [ $firsttime -eq 1 ]; then
d5fb252
				# reset timeout
d5fb252
				timeout=$NISTIMEOUT
74c49f9
				firsttime=0
d5fb252
			fi
713c992
			/usr/bin/ypwhich > /dev/null 2>&1
74c49f9
		    	RETVAL=$?
74c49f9
	    		if [ $RETVAL -eq 0 ]; then
d5fb252
				break;
74c49f9
	    		fi
d5fb252
		fi
74c49f9
		sleep 2
d5fb252
		echo -n "..."
cvsdist a2190fb
	done
cvsdist 5d711fc
	if [ $RETVAL -eq 0 ]; then
713c992
	    logger -t ypbind \
713c992
	    	"NIS domain: `domainname`, NIS server: `ypwhich 2> /dev/null`"
cvsdist 5d711fc
	    touch /var/lock/subsys/ypbind
713c992
	    success
cvsdist 5d711fc
	else
713c992
	    logger -t ypbind \
713c992
	    	"NIS server for domain `domainname` is not responding."
713c992
	    failure
65ae590
	    selinux_off
713c992
		RETVAL=100
cvsdist 5d711fc
	fi
cvsdist 5d711fc
	echo
cvsdist 4760d43
	return $RETVAL
cvsdist 4760d43
}
cvsdist 4760d43
cvsdist 4760d43
stop() {
713c992
	echo -n $"Shutting down NIS service: "
cvsdist 4760d43
	killproc ypbind
cvsdist 4760d43
	RETVAL=$?
cvsdist 4760d43
	if [ $RETVAL -eq 0 ] ; then
713c992
		rm -f /var/lock/subsys/ypbind
713c992
		# if  we used brute force (like kill -9) we don't want those around
713c992
		if [ x$(domainname) != x ] ; then
713c992
			rm -f /var/yp/binding/$(domainname)*
713c992
		fi
cvsdist 4760d43
	fi
cvsdist 4760d43
	echo
713c992
	selinux_off
cvsdist 4760d43
	return $RETVAL
cvsdist 4760d43
}
cvsdist 4760d43
cvsdist 4760d43
restart() {
cvsdist 4760d43
	stop
cvsdist 4760d43
	start
cvsdist 4760d43
}
cvsdist 4760d43
cvsdist 4760d43
RETVAL=0
cvsdist 4760d43
cvsdist 4760d43
# See how we were called.
cvsdist 4760d43
case "$1" in
cvsdist 4760d43
  start)
713c992
	start 
713c992
	[ $? -eq 100 ] && stop
cvsdist 4760d43
	;;
cvsdist 4760d43
  stop)
cvsdist 4760d43
	stop
cvsdist 4760d43
	;;
cvsdist 4760d43
  status)
cvsdist 4760d43
	status ypbind
2ca3c2a
	RETVAL=$?
cvsdist 4760d43
	;;
cvsdist 4760d43
  restart|reload)
cvsdist 4760d43
	restart
cvsdist 4760d43
	;;
cvsdist 4760d43
  condrestart)
cvsdist 4760d43
        [ -f /var/lock/subsys/ypbind ] && restart || :
cvsdist 4760d43
	;;
cvsdist 4760d43
  *)
cvsdist 5d711fc
	echo $"Usage: $0 {start|stop|status|restart|condrestart}"
cvsdist 4760d43
	exit 1
cvsdist 4760d43
esac
cvsdist 4760d43
cvsdist 4760d43
exit $?