1 #!/bin/sh /etc/rc.common
2 # IPsec startup and shutdown script
3 # Copyright (C) 1998, 1999, 2001 Henry Spencer.
4 # Copyright (C) 2002 Michael Richardson <mcr@freeswan.org>
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2 of the License, or (at your
9 # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # ipsec init.d script for starting and stopping
18 # the IPsec security subsystem (KLIPS and Pluto).
20 # This script becomes /etc/rc.d/init.d/ipsec (or possibly /etc/init.d/ipsec)
21 # and is also accessible as "ipsec setup" (the preferred route for human
24 # The startup and shutdown times are a difficult compromise (in particular,
25 # it is almost impossible to reconcile them with the insanely early/late
26 # times of NFS filesystem startup/shutdown). Startup is after startup of
27 # syslog and pcmcia support; shutdown is just before shutdown of syslog.
29 # chkconfig: 2345 47 76
30 # description: IPsec provides encrypted and authenticated communications; \
31 # KLIPS is the kernel half of it, Pluto is the user-level management daemon.
35 EXTRA_HELP=" status Show the status of the service"
38 me='ipsec setup' # for messages
40 # where the private directory and the config files are
41 IPSEC_EXECDIR="${IPSEC_EXECDIR-/usr/libexec/ipsec}"
42 IPSEC_LIBDIR="${IPSEC_LIBDIR-/usr/lib/ipsec}"
43 IPSEC_SBINDIR="${IPSEC_SBINDIR-/usr/sbin}"
44 IPSEC_CONFS="${IPSEC_CONFS-/etc}"
46 if test " $IPSEC_DIR" = " " # if we were not called by the ipsec command
48 # we must establish a suitable PATH ourselves
49 PATH="${IPSEC_SBINDIR}":/sbin:/usr/sbin:/usr/local/bin:/bin:/usr/bin
52 IPSEC_DIR="$IPSEC_LIBDIR"
53 export IPSEC_DIR IPSEC_CONFS IPSEC_LIBDIR IPSEC_EXECDIR
56 # Check that the ipsec command is available.
58 for dir in `echo $PATH | tr ':' ' '`
60 if test -f $dir/ipsec -a -x $dir/ipsec
63 break # NOTE BREAK OUT
68 echo "cannot find ipsec command -- \`$1' aborted" |
69 logger -s -p daemon.error -t ipsec_setup
75 export IPSEC_setupflags
83 --showonly|--show) IPSEC_setupflags="$1" ;;
84 --config) config="--config $2" ; shift ;;
91 # Pick up IPsec configuration (until we have done this, successfully, we
92 # do not know where errors should go, hence the explicit "daemon.error"s.)
93 # Note the "--export", which exports the variables created.
94 variables=`ipsec addconn $config --varprefix IPSEC --configsetup`
97 echo "Failed to parse config setup portion of ipsec.conf"
102 if test " $IPSEC_confreadstatus" != " "
105 stop|--stop|_autostop)
106 echo "$IPSEC_confreadstatus -- \`$1' may not work" |
107 logger -s -p daemon.error -t ipsec_setup;;
109 *) echo "$IPSEC_confreadstatus -- \`$1' aborted" |
110 logger -s -p daemon.error -t ipsec_setup;
115 IPSEC_confreadsection=${IPSEC_confreadsection:-setup}
116 export IPSEC_confreadsection
118 IPSECsyslog=${IPSECsyslog-daemon.error}
124 mkdir -p /var/run/pluto
130 start|--start|stop|--stop|_autostop|_autostart)
131 # remove for: @cygwin_START@
132 # portable way for checking for root
136 echo "permission denied (must be superuser)" |
137 logger -s -p $IPSECsyslog -t ipsec_setup 2>&1
140 # remove for: @cygwin_END@
141 tmp=/var/run/pluto/ipsec_setup.st
142 outtmp=/var/run/pluto/ipsec_setup.out
153 if [ -f ${outtmp} ]; then
154 cat ${outtmp} | logger -s -p $IPSECsyslog -t ipsec_setup 2>&1
159 restart|--restart|force-reload)
160 $0 $IPSEC_setupflags stop
161 $0 $IPSEC_setupflags start
164 _autorestart) # for internal use only
165 $0 $IPSEC_setupflags _autostop
166 $0 $IPSEC_setupflags _autostart
175 echo "$me $IPSEC_VERSION"
180 echo "Usage: $me [ --showonly ] {--start|--stop|--restart}"
186 echo "Usage: $me [ --showonly ] {--start|--stop|--restart}"
192 script_init start "$@"
193 script_command start "$@"
197 script_init stop "$@"
198 script_command stop "$@"
202 script_init stop "$@"
203 script_command stop "$@"
204 script_command start "$@"
208 script_init status "$@"
209 ipsec _realsetup status