OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / utils / setup
1 #!/bin/sh
2 # IPsec startup and shutdown script
3 # Copyright (C) 1998, 1999, 2001  Henry Spencer.
4
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
9
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 # for more details.
14 #
15 # RCSID $Id: setup,v 1.110 2001/06/20 15:55:13 henry Exp $
16 #
17 # ipsec         init.d script for starting and stopping
18 #               the IPsec security subsystem (KLIPS and Pluto).
19 #
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
22 # invocation).
23 #
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.
28 #
29 # chkconfig: 2345 47 68
30 # description: IPsec provides encrypted and authenticated communications; \
31 # KLIPS is the kernel half of it, Pluto is the user-level management daemon.
32
33 me='ipsec setup'                # for messages
34
35
36
37 if test " $IPSEC_DIR" = " "     # if we were not called by the ipsec command
38 then
39         # we must establish a suitable PATH ourselves
40         PATH=/usr/local/sbin:/sbin:/usr/sbin:/usr/local/bin:/bin:/usr/bin
41         export PATH
42 fi
43
44 # Check that the ipsec command is available.
45 found=
46 for dir in `echo $PATH | tr ':' ' '`
47 do
48         if test -f $dir/ipsec -a -x $dir/ipsec
49         then
50                 found=yes
51                 break                   # NOTE BREAK OUT
52         fi
53 done
54 if ! test "$found"
55 then
56         echo "cannot find ipsec command -- \`$1' aborted" |
57                 logger -s -p daemon.error -t ipsec_setup
58         exit 1
59 fi
60
61 # Pick up IPsec configuration (until we have done this, successfully, we
62 # do not know where errors should go, hence the explicit "daemon.error"s.)
63 # Note the "--export", which exports the variables created.
64 eval `ipsec _confread --varprefix IPSEC --export --type config setup`
65 if test " $IPSEC_confreadstatus" != " "
66 then
67         echo "$IPSEC_confreadstatus -- \`$1' aborted" |
68                 logger -s -p daemon.error -t ipsec_setup
69         exit 1
70 fi
71 IPSECsyslog=${IPSECsyslog-daemon.error}
72 export IPSECsyslog
73
74 # misc setup
75 umask 022
76
77
78
79 # do it
80 case "$1" in
81   start|--start|stop|--stop|_autostop|_autostart)
82         if test " `id -u`" != " 0"
83         then
84                 echo "permission denied (must be superuser)" |
85                         logger -s -p $IPSECsyslog -t ipsec_setup 2>&1
86                 exit 1
87         fi
88         tmp=/var/run/ipsec_setup.st
89         (
90                 ipsec _realsetup $1
91                 echo "$?" >$tmp
92         ) 2>&1 | logger -s -p $IPSECsyslog -t ipsec_setup 2>&1
93         st=`cat $tmp`
94         rm -f $tmp
95         exit $st
96         ;;
97
98   restart|--restart)
99         $0 stop
100         $0 start
101         ;;
102
103   _autorestart)                 # for internal use only
104         $0 _autostop
105         $0 _autostart
106         ;;
107
108   status|--status)
109         ipsec _realsetup $1
110         exit
111         ;;
112
113   --version)
114         echo "$me $IPSEC_VERSION"
115         exit 0
116         ;;
117
118   --help)
119         echo "Usage: $me {--start|--stop|--restart|--status}"
120         exit 0
121         ;;
122
123   *)
124         echo "Usage: $me {--start|--stop|--restart|--status}" >&2
125         exit 2
126 esac
127
128 exit 0