moved auth_method to policy
[strongswan.git] / src / ipsec / ipsec.in
1 #! /bin/sh
2 # prefix command to run stuff from our programs directory
3 # Copyright (C) 1998-2002  Henry Spencer.
4 # Copyright (C) 2006 Andreas Steffen
5 # Copyright (C) 2006 Martin Willi 
6
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
11
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 # for more details.
16 #
17 # RCSID $Id: ipsec.in,v 1.13 2006/03/09 20:09:33 as Exp $
18
19 # name and version of the ipsec implementation
20 IPSEC_NAME="@IPSEC_NAME@"
21 IPSEC_VERSION="U@IPSEC_VERSION@/K`uname -r`"
22
23 # where the private directory and the config files are
24 IPSEC_DIR="@IPSEC_DIR@"
25 IPSEC_SBINDIR="@IPSEC_SBINDIR@"
26 IPSEC_CONFDIR="@IPSEC_CONFDIR@"
27 IPSEC_PIDDIR="@IPSEC_PIDDIR@"
28
29 IPSEC_STARTER_PID="${IPSEC_PIDDIR}/starter.pid"
30 IPSEC_PLUTO_PID="${IPSEC_PIDDIR}/pluto.pid"
31 IPSEC_CHARON_PID="${IPSEC_PIDDIR}/charon.pid"
32
33 IPSEC_WHACK="${IPSEC_DIR}/whack"
34 IPSEC_STROKE="${IPSEC_DIR}/stroke"
35 IPSEC_STARTER="${IPSEC_DIR}/starter"
36
37 export IPSEC_DIR IPSEC_SBINDIR IPSEC_CONFDIR IPSEC_PIDDIR IPSEC_VERSION IPSEC_NAME IPSEC_STARTER_PID IPSEC_PLUTO_PID IPSEC_CHARON_PID
38
39 IPSEC_DISTRO="Distributed by the Institute of Internet Technologies and Applications
40               University of Applied Sciences Rapperswil, Switzerland (ITA-HSR)"
41
42 case "$1" in
43 '')
44         echo "Usage: ipsec command argument ..."
45         echo "Use --help for list of commands, or see ipsec(8) manual page"
46         echo "or the $IPSEC_NAME documentation for names of the common ones."
47         echo "Most have their own manual pages, e.g. ipsec_auto(8)."
48         echo "See <http://www.strongswan.org> for more general info."
49         exit 0
50         ;;
51 --help)
52         echo "Usage: ipsec command argument ..."
53         echo "where command is one of:"
54         echo "  start|restart  arguments..."
55         echo "  update|reload|stop"
56         echo "  up|down|route|unroute <connectionname>"
57         echo "  status|statusall [<connectionname>]"
58         echo "  ready"
59         echo "  listalgs|listpubkeys|listcerts [--utc]"
60         echo "  listcacerts|listaacerts|listocspcerts [--utc]"
61         echo "  listacerts|listgroups|listcainfos [--utc]"
62         echo "  listcrls|listocsp|listcards|listall [--utc]"
63         echo "  rereadsecrets|rereadgroups"
64         echo "  rereadcacerts|rereadaacerts|rereadocspcerts"
65         echo "  rereadacerts|rereadcrls|rereadall"
66         echo "  purgeocsp"
67         echo "  scencrypt|scdecrypt <value> [--inbase <base>] [--outbase <base>] [--keyid <id>]"
68         echo "  barf"
69         echo "  openac"
70         echo "  pluto"
71         echo "  scepclient"
72         echo "  secrets"
73         echo "  starter"
74         echo "  version"
75         echo "  whack"
76         echo "  stoke"
77         echo
78         echo "Some of these functions have their own manual pages, e.g. ipsec_scepclient(8)."
79         exit 0
80         ;;
81 --versioncode)
82         echo "$IPSEC_VERSION"
83         exit 0
84         ;;
85 --copyright)
86         set _copyright
87         # and fall through, invoking "ipsec _copyright"
88         ;;
89 --directory)
90         echo "$IPSEC_DIR"
91         exit 0
92         ;;
93 --confdir)
94         echo "$IPSEC_CONFDIR"
95         exit 0
96         ;;
97 down)
98         shift
99         if [ "$#" -ne 1 ]
100         then
101             echo "Usage: ipsec down <connection name>"
102             exit 1
103         fi
104         if test -e $IPSEC_PLUTO_PID
105         then
106                 $IPSEC_WHACK --name "$1" --terminate
107         fi
108         if test -e $IPSEC_CHARON_PID
109         then
110                 $IPSEC_STROKE down "$1"
111         fi
112         exit 0
113         ;;
114 listalgs|listpubkeys|listaacerts|\
115 listocspcerts|listacerts|listgroups|\
116 listcainfos|listocsp|listcards|\
117 purgeocsp|rereadsecrets|rereadgroups|\
118 rereadaacerts|rereadocspcerts|rereadacerts)
119         op="$1"
120         shift
121         if test -e $IPSEC_PLUTO_PID
122         then
123                 $IPSEC_WHACK "$@" "--$op"
124         fi
125         ;;
126 listcerts|listcacerts|listcrls|listall|\
127 rereadcacerts|rereadcrls|rereadall)
128         op="$1"
129         shift
130         if test -e $IPSEC_PLUTO_PID
131         then
132                 $IPSEC_WHACK "$@" "--$op"
133         fi
134         if test -e $IPSEC_CHARON_PID
135         then
136                 $IPSEC_STROKE "$op" "$@"
137         fi
138         exit 0
139         ;;
140 ready)
141         shift
142         if test -e $IPSEC_PLUTO_PID
143         then
144                 $IPSEC_WHACK --listen
145         fi
146         exit 0
147         ;;
148 reload)
149         if test -e $IPSEC_STARTER_PID 
150         then
151             echo "Reloading strongSwan IPsec configuration..." >&2
152             kill -s USR1 `cat $IPSEC_STARTER_PID`
153         else
154             echo "ipsec starter is not running" >&2
155         fi
156         exit 0
157         ;;
158 restart)
159         $IPSEC_SBINDIR/ipsec stop
160         sleep 2
161         shift
162         $IPSEC_SBINDIR/ipsec start "$@"
163         exit 0
164         ;;
165 route|unroute)
166         op="$1"
167         shift
168         if [ "$#" -ne 1 ]
169         then
170             echo "Usage: ipsec $op <connection name>"
171             exit 1
172         fi
173         if test -e $IPSEC_PLUTO_PID
174         then
175                 $IPSEC_WHACK --name "$1" "--$op"
176         fi
177         if test -e $IPSEC_CHARON_PID
178         then
179                 $IPSEC_STROKE "$op" "$1"
180         fi
181         exit 0
182         ;;
183 scencrypt|scdecrypt)
184         op="$1"
185         shift
186         if test -e $IPSEC_PLUTO_PID
187         then
188                 $IPSEC_WHACK "--$op" "$@"
189         fi
190         exit 0
191         ;;
192 secrets)
193         if test -e $IPSEC_PLUTO_PID
194         then
195                 $IPSEC_WHACK --rereadsecrets
196         fi
197         exit 0
198         ;;
199 start)
200         shift
201         exec $IPSEC_STARTER "$@"
202         ;;
203 status|statusall)
204         op="$1"
205         shift
206         if test $# -eq 0
207         then
208                 if test -e $IPSEC_PLUTO_PID
209                 then
210                         $IPSEC_WHACK "--$op"
211                 fi
212                 if test -e $IPSEC_CHARON_PID
213                 then
214                         $IPSEC_STROKE "$op"
215                 fi
216         else
217                 if test -e $IPSEC_PLUTO_PID
218                 then
219                         $IPSEC_WHACK --name "$1" "--$op"
220                 fi
221                 if test -e $IPSEC_CHARON_PID
222                 then
223                         $IPSEC_STROKE "$op" "$1"
224                 fi
225         fi
226         exit 0
227         ;;
228 stop)
229         if test -e $IPSEC_STARTER_PID 
230         then
231             echo "Stopping strongSwan IPsec..." >&2
232             kill `cat $IPSEC_STARTER_PID`
233         else
234             echo "ipsec starter is not running" >&2
235         fi
236         exit 0
237         ;;
238 up)
239         shift
240         if [ "$#" -ne 1 ]
241         then
242             echo "Usage: ipsec up <connection name>"
243             exit 1
244         fi
245         if test -e $IPSEC_PLUTO_PID
246         then
247                 $IPSEC_WHACK --name "$1" --initiate
248         fi
249         if test -e $IPSEC_CHARON_PID
250         then
251             $IPSEC_STROKE up "$1"
252         fi
253         exit 0
254         ;;
255 update)
256         if test -e $IPSEC_STARTER_PID 
257         then
258                 echo "Updating strongSwan IPsec configuration..." >&2
259                 kill -s HUP `cat $IPSEC_STARTER_PID`
260         else
261                 echo "ipsec starter is not running" >&2
262         fi
263         exit 0
264         ;;
265 version|--version)
266         echo "Linux $IPSEC_NAME $IPSEC_VERSION"
267         echo "See \`ipsec --copyright' for copyright information."
268         echo $IPSEC_DISTRO
269         exit 0
270         ;;
271 --*)
272         echo "$0: unknown option \`$1' (perhaps command name was omitted?)" >&2
273         exit 1
274         ;;
275 esac
276
277 cmd="$1"
278 shift
279
280 path="$IPSEC_DIR/$cmd"
281
282 if test ! -x "$path" 
283 then
284     path="$IPSEC_DIR/$cmd"
285     if test ! -x "$path"
286     then
287         echo "$0: unknown IPsec command \`$cmd' (\`ipsec --help' for list)" >&2
288         exit 1
289     fi
290 fi
291
292 exec $path "$@"