#!/bin/sh
#
# chkconfig: - 92 34
# description: Starts and stops the Samba Winbindd daemon \
#	       used to provide seamless NT domain integration.

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

# Source networking configuration.
# Check that networking is up.
# Check that smb.conf exists.
SourceIfNotEmpty /etc/sysconfig/network && [ "$NETWORKING" != no ] && [ -s /etc/samba/smb.conf ] || exit

# Check that Winbind usage is requested through /etc/nsswitch.conf
test -f /etc/nsswitch.conf && grep -q winbind /etc/nsswitch.conf || exit

export TMPDIR=/tmp
LOCKFILE=/var/lock/subsys/winbind
RETVAL=0

start()
{
	echo -n "Starting Winbind services: "
	daemon winbindd 
	RETVAL=$?
	echo

	[ $RETVAL -eq 0 ] &&
		touch "$LOCKFILE" ||
		RETVAL=1
	return $RETVAL
}

stop()
{
	echo -n "Shutting down Winbind services: "
	killproc winbindd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
	echo
	return $RETVAL
}	

restart()
{
	stop
	start
}	

reload()
{
        echo -n "Reloading smb.conf file: "
	killproc winbindd -HUP
	RETVAL=$?
	echo
	return $RETVAL
}	

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status winbindd
		RETVAL=$?
		[ $RETVAL -eq 0 ] ||
		RETVAL=1
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|reload|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
