#! /bin/sh
#
# identd	Start/Stop RFC 1413 identd server
#
# chkconfig: - 35 65
# description:	The identd server provides a means to determine the identity \
#		of a user of a particular TCP connection.  Given a TCP port \
#		number pair, it returns a character string which identifies \
#		the owner of that connection on the server's system.
# processname: identd
# pidfile: /var/run/identd.pid
# config: /etc/identd.conf

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

# Get config.
. /etc/sysconfig/network

# Get identd config

[ -f /etc/sysconfig/identd ] && . /etc/sysconfig/identd

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

# Check that we're a priviledged user
[ `id -u` -ne 0 ] && exit 1

[ -x /usr/sbin/identd ] || exit 0

RETVAL=0
prog="identd"

start() {
        if [ ! -f /etc/identd.key ]; then
	  action $"Generating ident key: " /usr/sbin/ikeygen 
	  ret=$?
	  chown root.root /etc/identd.key
	  chmod 0600 /etc/identd.key
	  if [ $ret -ne 0 ] ; then
	      return $ret
	  fi
	fi
        echo -n $"Starting $prog: "
        daemon identd $IDENTDOPTS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/identd
	return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: " 
        killproc identd
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/identd
	return $RETVAL
}

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

exit $RETVAL