#!/bin/sh
#
# cntlmd: Start/stop the cntlm proxy.
#
# chkconfig:  2345 26 89 
# Description:       Cntlm is meant to be given your proxy address and becomming
#                    the primary proxy then, listening on a selected local port. 
#                    You point all your proxy-aware programs to it and don't ever
#                    have to deal with proxy authentication again.
#
### BEGIN INIT INFO
# Provides:          cntlm
# Required-Start:    $syslog $network $time
# Required-Stop:     $syslog $network $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Authenticating HTTP accelerator for NTLM secured proxies
# Description:       Cntlm is meant to be given your proxy address and becomming
#                    the primary proxy then, listening on a selected local port. 
#                    You point all your proxy-aware programs to it and don't ever
#                    have to deal with proxy authentication again.
### END INIT INFO
PIDFILE=/var/run/cntlm/cntlmd.pid
LOCKFILE=/var/lock/subsys/cntlmd
RUNAS=cntlm
OPTARGS="-U $RUNAS -P $PIDFILE"

. /etc/init.d/functions

# Source networking configuration.
SourceIfNotEmpty /etc/sysconfig/network 

RETVAL=0

start() {
        is_yes "$NETWORKING" || return 0
        start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- /usr/bin/cntlm $OPTARGS
        RETVAL=$?
        return $RETVAL
}

stop() {
        stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user $RUNAS -- /usr/bin/cntlm
        RETVAL=$?
        return $RETVAL
}


# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
        ;;
  restart)
        stop
        start
        ;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user $RUNAS cntlm
		RETVAL=$?
		;;
  *)
		msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
