--- freeswan-2.00-rc2/programs/setup/setup.in.org Mon Mar 24 14:51:14 2003 +++ freeswan-2.00-rc2/programs/setup/setup.in Mon Mar 24 15:19:32 2003 @@ -31,6 +31,24 @@ # description: IPsec provides encrypted and authenticated communications; \ # KLIPS is the kernel half of it, Pluto is the user-level management daemon. + +# Source function library +. /etc/rc.d/init.d/functions + +# Get network config +. /etc/sysconfig/network + +# Check that networking is up. +if is_yes "${NETWORKING}"; then + if [ ! -f /var/lock/subsys/network ]; then + # nls "ERROR: Networking is down. %s can't be run." ipsec + msg_network_down ipsec + exit 1 + fi +else + exit 0 +fi + me='ipsec setup' # for messages @@ -63,7 +81,7 @@ if ! test "$found" then echo "cannot find ipsec command -- \`$1' aborted" | - logger -s -p daemon.error -t ipsec_setup + logger -p daemon.error -t ipsec_setup exit 1 fi @@ -92,7 +110,7 @@ if test " $IPSEC_confreadstatus" != " " then echo "$IPSEC_confreadstatus -- \`$1' aborted" | - logger -s -p daemon.error -t ipsec_setup + logger -p daemon.error -t ipsec_setup exit 1 fi @@ -108,26 +126,77 @@ # do it case "$1" in - start|--start|stop|--stop|_autostop|_autostart) - if test " `id -u`" != " 0" - then - echo "permission denied (must be superuser)" | - logger -s -p $IPSECsyslog -t ipsec_setup 2>&1 - exit 1 - fi - tmp=/var/run/ipsec_setup.st - ( - ipsec _realsetup $1 - echo "$?" >$tmp - ) 2>&1 | logger -s -p $IPSECsyslog -t ipsec_setup 2>&1 - st=$? - if test -f $tmp - then - st=`cat $tmp` - rm -f $tmp + start|--start|_autostart) + # Check if the service is already running? + if [ ! -f /var/lock/subsys/ipsec ]; then + # show "Starting %s service" ipsec + msg_starting ipsec + busy + if test " `id -u`" != " 0" + then + echo "permission denied (must be superuser)" | + logger -p $IPSECsyslog -t ipsec_setup 2>&1 + fail + exit 1 + fi + { + ipsec _realsetup $1 ; + RETVAL=$?; + } | logger -p $IPSECsyslog -t ipsec_setup 2>&1 + + if [ "$RETVAL" -eq 0 ]; + then + touch /var/lock/subsys/ipsec + ok + exit $RETVAL; + fi + fail + exit $RETVAL + + else + # show "%s service is already running." ipsec + msg_already_running ipsec + + + + exit 1 fi - exit $st ;; + stop|--stop|_autostop) + # Stop daemons. + # show "Stopping %s service" ipsec + if [ -f /var/lock/subsys/ipsec ]; then + msg_stopping ipsec + busy + if test " `id -u`" != " 0" + then + echo "permission denied (must be superuser)" | + logger -p $IPSECsyslog -t ipsec_setup 2>&1 + fail + exit 1 + fi + { + ipsec _realsetup $1 ; + RETVAL=$?; + } 2>&1 | logger -p $IPSECsyslog -t ipsec_setup 2>&1 + + rm -f /var/lock/subsys/ipsec + + if [ "$RETVAL" -eq 0 ]; + then + ok + exit $RETVAL; + fi + fail + exit $RETVAL + else + # show "%s service is not running." ipsec + msg_not_running ipsec + exit 1 + fi + ;; + + restart|--restart) $0 $IPSEC_setupflags stop