tet setting policy
[heimdal.git] / tests / kdc / check-iprop.in
blob71fa0917eea9c73fef21c986de431fb9a9f1fe99
1 #!/bin/sh
3 # Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
4 # (Royal Institute of Technology, Stockholm, Sweden).
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # 3. Neither the name of the Institute nor the names of its contributors
19 # may be used to endorse or promote products derived from this software
20 # without specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 # ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 # SUCH DAMAGE.
34 top_builddir="@top_builddir@"
35 env_setup="@env_setup@"
36 objdir="@objdir@"
38 . ${env_setup}
40 # If there is no useful db support compile in, disable test
41 ${have_db} || exit 77
44 # Dont run this test in AFS, since it lacks support for AF_UNIX
45 expr "X`/bin/pwd || pwd`" : "X/afs/.*" > /dev/null 2>/dev/null && exit 77
47 R=TEST.H5L.SE
49 port=@port@
51 cache="FILE:${objdir}/cache.krb5"
52 keytabfile=${objdir}/iprop.keytab
53 keytab="FILE:${keytabfile}"
55 kdc="${kdc} --addresses=localhost -P $port"
56 kadmin="${kadmin} -r $R"
57 kinit="${kinit} -c $cache ${afs_no_afslog}"
59 KRB5_CONFIG="${objdir}/krb5.conf"
60 export KRB5_CONFIG
62 rm -f ${keytabfile}
63 rm -f current-db*
64 rm -f current*.log
65 rm -f out-*
66 rm -f mkey.file*
67 rm -f messages.log
69 > messages.log
71 echo Creating database
72 ${kadmin} -l \
73 init \
74 --realm-max-ticket-life=1day \
75 --realm-max-renewable-life=1month \
76 ${R} || exit 1
78 ${kadmin} -l add -p foo --use-defaults user@${R} || exit 1
80 ${kadmin} -l add --random-key --use-defaults iprop/localhost@${R} || exit 1
81 ${kadmin} -l ext -k ${keytab} iprop/localhost@${R} || exit 1
82 ${kadmin} -l add --random-key --use-defaults iprop/slave.test.h5l.se@${R} || exit 1
83 ${kadmin} -l ext -k ${keytab} iprop/slave.test.h5l.se@${R} || exit 1
85 echo foo > ${objdir}/foopassword
87 # -- foo
88 ipds=
89 ipdm=
90 kdcpid=
92 > iprop-stats
93 rm -f iprop-slave-status
95 ipropd_slave="${ipropd_slave} --status-file=iprop-slave-status"
97 trap "echo 'killing ipropd s + m + kdc'; kill -9 \${ipdm} \${ipds} \${kdcpid} >/dev/null 2>/dev/null; tail messages.log ; tail iprop-stats; exit 1;" EXIT
99 echo Starting kdc ; > messages.log
100 ${kdc} &
101 kdcpid=$!
103 sh ${wait_kdc} || exit 1
105 echo "starting master" ; > messages.log
106 env ${HEIM_MALLOC_DEBUG} \
107 ${ipropd_master} --hostname=localhost -k ${keytab} \
108 --database=${objdir}/current-db &
109 ipdm=$!
110 sh ${wait_kdc} ipropd-master || exit 1
112 echo "starting slave" ; > messages.log
113 env ${HEIM_MALLOC_DEBUG} \
114 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
115 ${ipropd_slave} --hostname=slave.test.h5l.se -k ${keytab} localhost &
116 ipds=$!
117 sh ${wait_kdc} ipropd-slave messages.log 'slave status change: up-to-date' || exit 1
118 sleep 1
120 echo "checking slave is up"
121 ${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Up' iprop-stats >/dev/null || exit 1
122 ${EGREP} 'up-to-date with version' iprop-slave-status >/dev/null || { echo "slave to up to date" ; cat iprop-slave-status ; exit 1; }
124 # ----------------- checking: pushing lives changes
126 echo "Add host"
127 ${kadmin} -l add --random-key --use-defaults host/foo@${R} || exit 1
128 sleep 2
129 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
130 ${kadmin} -l get host/foo@${R} > /dev/null || exit 1
132 echo "Rollover host keys"
133 ${kadmin} -l cpw -r --keepold host/foo@${R} || exit 1
134 ${kadmin} -l cpw -r --keepold host/foo@${R} || exit 1
135 ${kadmin} -l cpw -r --keepold host/foo@${R} || exit 1
136 sleep 2
137 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
138 ${kadmin} -l get host/foo@${R} | \
139 ${EGREP} Keytypes: | cut -d: -f2 | tr ' ' '
140 ' | sed 's/^.*[[]\(.*\)[]].*$/\1/' | grep '[0-9]' | sort -nu | tr -d '
141 ' | ${EGREP} 1234 > /dev/null || exit 1
143 echo "Delete 3DES keys"
144 ${kadmin} -l del_enctype host/foo@${R} des3-cbc-sha1
145 sleep 2
146 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
147 ${kadmin} -l get host/foo@${R} | \
148 ${EGREP} Keytypes: | cut -d: -f2 | tr ' ' '
149 ' | sed 's/^.*[[]\(.*\)[]].*$/\1/' | grep '[0-9]' | sort -nu | tr -d '
150 ' | ${EGREP} 1234 > /dev/null || exit 1
151 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
152 ${kadmin} -l get host/foo@${R} | \
153 ${EGREP} 'Keytypes:.*des3-cbc-sha1' > /dev/null && exit 1
155 echo "Change policy host"
156 ${kadmin} -l modify --policy=default host/foo@${R} || exit 1
157 sleep 2
158 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
159 ${kadmin} -l get host/foo@${R} > /dev/null 2>/dev/nill || exit 1
161 echo "Rename host"
162 ${kadmin} -l rename host/foo@${R} host/bar@${R} || exit 1
163 sleep 2
164 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
165 ${kadmin} -l get host/foo@${R} > /dev/null 2>/dev/null && exit 1
166 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
167 ${kadmin} -l get host/bar@${R} > /dev/null || exit 1
169 echo "Delete host"
170 ${kadmin} -l delete host/bar@${R} || exit 1
171 sleep 2
172 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
173 ${kadmin} -l get host/bar@${R} > /dev/null 2>/dev/null && exit 1
175 echo "kill slave"
176 > iprop-stats
177 sh ${leaks_kill} ipropd-slave $ipds || exit 1
178 rm -f iprop-slave-status
180 ${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Down' iprop-stats >/dev/null || exit 1
182 # ----------------- checking: slave is missing changes while down
184 echo "doing changes while slave is down"
185 ${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1
186 ${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1
188 echo "Makeing a copy of the master log file"
189 cp ${objdir}/current.log ${objdir}/current.log.tmp
191 # ----------------- checking: checking that master and slaves resyncs
193 echo "starting slave again" ; > messages.log
194 > iprop-stats
195 env ${HEIM_MALLOC_DEBUG} \
196 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
197 ${ipropd_slave} --hostname=slave.test.h5l.se -k ${keytab} localhost &
198 ipds=$!
199 sh ${wait_kdc} ipropd-slave messages.log 'slave status change: up-to-date' || exit 1
200 sleep 1
202 echo "checking slave is up again"
203 ${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Up' iprop-stats >/dev/null || exit 1
204 ${EGREP} 'up-to-date with version' iprop-slave-status >/dev/null || { echo "slave not up to date" ; cat iprop-slave-status ; exit 1; }
205 echo "checking for replay problems"
206 ${EGREP} 'Entry already exists in database' messages.log && exit 1
208 echo "kill slave and remove log and database"
209 sh ${leaks_kill} ipropd-slave $ipds || exit 1
210 sleep 2
212 rm current.slave.log current-db.slave* || exit 1
213 > iprop-stats
214 rm -f iprop-slave-status
215 echo "starting slave" ; > messages.log
216 env ${HEIM_MALLOC_DEBUG} \
217 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
218 ${ipropd_slave} --hostname=slave.test.h5l.se -k ${keytab} localhost &
219 ipds=$!
220 sh ${wait_kdc} ipropd-slave messages.log 'slave status change: up-to-date' || exit 1
221 sleep 1
223 echo "checking slave is up again"
224 ${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Up' iprop-stats >/dev/null || exit 1
225 ${EGREP} 'up-to-date with version' iprop-slave-status >/dev/null || { echo "slave not up to date" ; cat iprop-slave-status ; exit 1; }
226 echo "checking for replay problems"
227 ${EGREP} 'Entry already exists in database' messages.log && exit 1
229 # ----------------- checking: checking live truncation of master log
231 ${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1
232 sleep 2
234 echo "live truncate on master log"
235 ${iprop_log} truncate || exit 1
236 sleep 2
238 echo "Killing master and slave"
239 sh ${leaks_kill} ipropd-master $ipdm || exit 1
240 sh ${leaks_kill} ipropd-slave $ipds || exit 1
242 rm -f iprop-slave-status
244 #sleep 2
245 #${EGREP} "^master down at " iprop-stats > /dev/null || exit 1
247 echo "compare versions on master and slave logs"
248 KRB5_CONFIG=${objdir}/krb5-slave.conf \
249 ${iprop_log} last-version > slave-last.tmp
250 ${iprop_log} last-version > master-last.tmp
251 cmp master-last.tmp slave-last.tmp || exit 1
253 # ----------------- checking: master going backward
254 > iprop-stats
255 > messages.log
257 echo "Going back to old version of the master log file"
258 cp ${objdir}/current.log.tmp ${objdir}/current.log
260 echo "starting master" ; > messages.log
261 env ${HEIM_MALLOC_DEBUG} \
262 ${ipropd_master} --hostname=localhost -k ${keytab} \
263 --database=${objdir}/current-db &
264 ipdm=$!
265 sh ${wait_kdc} ipropd-master || exit 1
267 echo "starting slave" ; > messages.log
268 env ${HEIM_MALLOC_DEBUG} \
269 KRB5_CONFIG="${objdir}/krb5-slave.conf" \
270 ${ipropd_slave} --hostname=slave.test.h5l.se -k ${keytab} localhost &
271 ipds=$!
272 sh ${wait_kdc} ipropd-slave messages.log 'slave status change: up-to-date' || exit 1
273 sleep 1
275 echo "checking slave is up again"
276 ${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Up' iprop-stats >/dev/null || exit 1
277 ${EGREP} 'up-to-date with version' iprop-slave-status >/dev/null || { echo "slave to up to date" ; cat iprop-slave-status ; exit 1; }
278 echo "checking for replay problems"
279 ${EGREP} 'Entry already exists in database' messages.log && exit 1
281 echo "pushing one change"
282 ${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1
283 sleep 2
285 echo "Killing master"
286 sh ${leaks_kill} ipropd-master $ipdm || exit 1
288 sleep 4
290 ${EGREP} 'disconnected' iprop-slave-status >/dev/null && { echo "slave still think its connected" ; cat iprop-slave-status ; exit 1; }
292 if ! tail -30 messages.log | grep 'disconnected for server' > /dev/null; then
293 echo "client didnt disconnect"
294 exit 1
297 echo "probing for slave pid"
298 kill -0 ${ipds} || { echo "slave no longer there"; exit 1; }
300 > messages.log
302 echo "Staring master again" ; > messages.log
303 env ${HEIM_MALLOC_DEBUG} \
304 ${ipropd_master} --hostname=localhost -k ${keytab} \
305 --database=${objdir}/current-db &
306 ipdm=$!
307 sh ${wait_kdc} ipropd-master || exit 1
309 echo "probing for slave pid"
310 kill -0 ${ipds} || { echo "slave no longer there"; exit 1; }
312 sh ${wait_kdc} ipropd-slave messages.log "connection successful to master" || exit 1
314 sh ${wait_kdc} ipropd-slave messages.log "ipropd-slave started at version" || exit 1
316 echo "pushing one change"
317 ${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1
318 sleep 2
320 echo "shutting down all services"
322 trap "" EXIT
323 sh ${leaks_kill} kdc $kdcpid || exit 1
324 sh ${leaks_kill} ipropd-master $ipdm || exit 1
325 sh ${leaks_kill} ipropd-slave $ipds || exit 1
327 rm -f iprop-slave-status
329 echo "compare versions on master and slave logs"
330 KRB5_CONFIG=${objdir}/krb5-slave.conf \
331 ${iprop_log} last-version > slave-last.tmp
332 ${iprop_log} last-version > master-last.tmp
333 cmp master-last.tmp slave-last.tmp || exit 1
335 exit $ec