OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / utils / _plutoload
1 #!/bin/sh
2 # Pluto database-loading 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: _plutoload,v 1.2 2001/10/31 01:39:03 henry Exp $
16 #
17 # exit status is 13 for protocol violation, that of Pluto otherwise
18
19 me='ipsec _plutoload'           # for messages
20
21 for dummy
22 do
23         case "$1" in
24         --load) plutoload="$2" ; shift  ;;
25         --start)        plutostart="$2" ; shift ;;
26         --wait) plutowait="$2" ; shift  ;;
27         --post) postpluto="$2" ; shift  ;;
28         --)     shift ; break   ;;
29         -*)     echo "$me: unknown option \`$1'" >&2 ; exit 2   ;;
30         *)      break   ;;
31         esac
32         shift
33 done
34
35 # searches, if needed
36 if test " $plutoload" = " %search"
37 then
38         eval `ipsec _confread --varprefix PLUTO --search auto add route start`
39         if test " $PLUTO_confreadstatus" != " "
40         then
41                 echo "auto=add/route/start search: $PLUTO_confreadstatus"
42                 echo "unable to determine what conns to add -- adding none"
43                 plutoload=
44         else
45                 plutoload="$PLUTO_confreadnames"
46         fi
47 fi
48 if test " $plutostart" = " %search"
49 then
50         eval `ipsec _confread --varprefix PLUTO --search auto route start`
51         if test " $PLUTO_confreadstatus" != " "
52         then
53                 echo "auto=route/start search: $PLUTO_confreadstatus"
54                 echo "unable to determine what conns to route -- routing none"
55                 plutoroute=
56         else
57                 plutoroute="$PLUTO_confreadnames"
58         fi
59         eval `ipsec _confread --varprefix PLUTO --search auto start`
60         if test " $PLUTO_confreadstatus" != " "
61         then
62                 echo "auto=start search: $PLUTO_confreadstatus"
63                 echo "unable to determine what conns to start -- starting none"
64                 plutostart=
65         else
66                 plutostart="$PLUTO_confreadnames"
67         fi
68 fi
69
70 # the way the searches were done ensures plutoload >= plutoroute >= plutostart
71
72 # await Pluto's readiness (not likely to be an issue, but...)
73 eofed=y
74 while read saying
75 do
76         case "$saying" in
77         'Pluto initialized')    eofed= ; break  ;;      # NOTE BREAK OUT
78         *)      echo "pluto unexpectedly said \`$saying'"       ;;
79         esac
80 done
81 if test "$eofed"
82 then
83         echo "pluto died unexpectedly!?!"
84         exit 13
85 fi
86
87 # database load
88 for tu in $plutoload
89 do
90         ipsec auto --add $tu ||
91                 echo "...could not add conn \"$tu\""
92 done
93
94 # enable listening
95 ipsec auto --ready
96
97 # execute any post-startup cleanup
98 if test " $postpluto" != " "
99 then
100         $postpluto
101         st=$?
102         if test " $st" -ne 0
103         then
104                 echo "...postpluto command exited with status $st"
105         fi
106 fi
107
108 # quickly establish routing
109 for tu in $plutoroute
110 do
111         ipsec auto --route $tu ||
112                 echo "...could not route conn \"$tu\""
113 done
114
115 # tunnel initiation, which may take a while
116 async=
117 if test " $plutowait" = " no"
118 then
119         async="--asynchronous"
120 fi
121 for tu in $plutostart
122 do
123         ipsec auto --up $async $tu ||
124                 echo "...could not start conn \"$tu\""
125 done
126
127 # report any further utterances, and watch for exit status
128 eofed=y
129 while read saying
130 do
131         case "$saying" in
132         exit)   eofed= ; break  ;;              # NOTE BREAK OUT
133         *)      echo "pluto unexpectedly says \`$saying'"       ;;
134         esac
135 done
136 if test "$eofed"
137 then
138         echo "pluto died without exit status!?!"
139         exit 13
140 fi
141 if read status
142 then
143         exit $status
144 else
145         echo "pluto yielded no exit status!?!"
146         exit 13
147 fi