#!/bin/sh
#
# sfcmilter    This shell script takes care of starting and stopping
#              sfcmilter.
#
# chkconfig: 2345 79 31
# description: sfcmilter is a mail filter that runs in conjunction with \
#              sendmail to check for forged sender addresses in incoming \
#              mail.
# processname: sfcmilter
# config: /etc/mail/sendmail.cf

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

# Source networking configuration.
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network

# Source sfcmilter configuration.
SFCMILTER_OPTIONS=""
SFCMILTER_SOCKET=unix:/var/run/sfcmilter/sfcmilter.sock
SFCMILTER_PIDFILE=/var/run/sfcmilter.pid
export SFCMILTER_OPTIONS SFCMILTER_SOCKET SFCMILTER_PIDFILE

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f /usr/sbin/sendmail ] || exit 0
[ -f /usr/sbin/sfcmilter ] || exit 0

RETVAL=0

start() {
	if [ ! -f "$SFCMILTER_PIDFILE" ]; then
		echo -n $"Starting sfcmilter: "
		touch "$SFCMILTER_PIDFILE"
		chown sfcmilt:sfcmilt "$SFCMILTER_PIDFILE"
		daemon /usr/sbin/sfcmilter \
			-user sfcmilt \
			-pidfile "$SFCMILTER_PIDFILE" \
			$SFCMILTER_OPTIONS $SFCMILTER_SOCKET
		RETVAL=$?
		echo
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/sfcmilter
	fi
	return $RETVAL
}

stop() {
	# Stop daemons
	echo -n $"Shutting down sfcmilter: "
	killproc sfcmilter
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$SFCMILTER_PIDFILE"
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sfcmilter
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  condrestart)
	if [ -f /var/lock/subsys/sfcmilter ]; then
	    stop
	    start
	    RETVAL=$?
	fi
	;;
  status)
	status sfcmilter
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	exit 1
	;;
esac

exit $RETVAL
