1#!/bin/sh 2# 3# Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan 4# (Royal Institute of Technology, Stockholm, Sweden). 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 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. 17# 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. 21# 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. 33 34top_builddir="@top_builddir@" 35env_setup="@env_setup@" 36objdir="@objdir@" 37 38. ${env_setup} 39 40# If there is no useful db support compile in, disable test 41${have_db} || exit 77 42 43 44# Dont run this test in AFS, since it lacks support for AF_UNIX 45expr "X`/bin/pwd || pwd`" : "X/afs/.*" > /dev/null 2>/dev/null && exit 77 46 47R=TEST.H5L.SE 48 49port=@port@ 50 51cache="FILE:${objdir}/cache.krb5" 52keytabfile=${objdir}/iprop.keytab 53keytab="FILE:${keytabfile}" 54 55kdc="${kdc} --addresses=localhost -P $port" 56kadmin="${kadmin} -r $R" 57kinit="${kinit} -c $cache ${afs_no_afslog}" 58 59KRB5_CONFIG="${objdir}/krb5.conf" 60export KRB5_CONFIG 61 62rm -f ${keytabfile} 63rm -f current-db* 64rm -f current*.log 65rm -f out-* 66rm -f mkey.file* 67rm -f messages.log 68 69> messages.log 70 71echo Creating database 72${kadmin} -l \ 73 init \ 74 --realm-max-ticket-life=1day \ 75 --realm-max-renewable-life=1month \ 76 ${R} || exit 1 77 78${kadmin} -l add -p foo --use-defaults user@${R} || exit 1 79 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 84 85echo foo > ${objdir}/foopassword 86 87# -- foo 88ipds= 89ipdm= 90kdcpid= 91 92> iprop-stats 93trap "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 94 95echo Starting kdc 96${kdc} & 97kdcpid=$! 98 99sh ${wait_kdc} || exit 1 100 101echo "starting master" 102env ${HEIM_MALLOC_DEBUG} \ 103${ipropd_master} --hostname=localhost -k ${keytab} \ 104 --database=${objdir}/current-db & 105ipdm=$! 106sh ${wait_kdc} ipropd-master || exit 1 107 108echo "starting slave" 109env ${HEIM_MALLOC_DEBUG} \ 110KRB5_CONFIG="${objdir}/krb5-slave.conf" \ 111${ipropd_slave} --hostname=slave.test.h5l.se -k ${keytab} localhost & 112ipds=$! 113sh ${wait_kdc} ipropd-slave || exit 1 114 115echo "checking slave is up" 116${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Up' iprop-stats >/dev/null || exit 1 117 118# ----------------- checking: pushing lives changes 119 120echo "Add host" 121${kadmin} -l add --random-key --use-defaults host/foo@${R} || exit 1 122sleep 2 123KRB5_CONFIG="${objdir}/krb5-slave.conf" \ 124${kadmin} -l get host/foo@${R} > /dev/null || exit 1 125 126echo "Rename host" 127${kadmin} -l rename host/foo@${R} host/bar@${R} || exit 1 128sleep 2 129KRB5_CONFIG="${objdir}/krb5-slave.conf" \ 130${kadmin} -l get host/foo@${R} > /dev/null 2>/dev/null && exit 1 131KRB5_CONFIG="${objdir}/krb5-slave.conf" \ 132${kadmin} -l get host/bar@${R} > /dev/null || exit 1 133 134echo "Delete host" 135${kadmin} -l delete host/bar@${R} || exit 1 136sleep 2 137KRB5_CONFIG="${objdir}/krb5-slave.conf" \ 138${kadmin} -l get host/bar@${R} > /dev/null 2>/dev/null && exit 1 139 140echo "kill slave" 141> iprop-stats 142sh ${leaks_kill} ipropd-slave $ipds || exit 1 143sleep 2 144 145${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Down' iprop-stats >/dev/null || exit 1 146 147# ----------------- checking: slave is missing changes while down 148 149echo "doing changes while slave is down" 150${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1 151${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1 152 153echo "Makeing a copy of the master log file" 154cp ${objdir}/current.log ${objdir}/current.log.tmp 155 156# ----------------- checking: checking that master and slaves resyncs 157 158echo "starting slave again" 159> iprop-stats 160> messages.log 161env ${HEIM_MALLOC_DEBUG} \ 162KRB5_CONFIG="${objdir}/krb5-slave.conf" \ 163${ipropd_slave} --hostname=slave.test.h5l.se -k ${keytab} localhost & 164ipds=$! 165sh ${wait_kdc} ipropd-slave || exit 1 166 167echo "checking slave is up again" 168${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Up' iprop-stats >/dev/null || exit 1 169echo "checking for replay problems" 170${EGREP} 'Entry already exists in database' messages.log && exit 1 171 172echo "kill slave and remove log and database" 173sh ${leaks_kill} ipropd-slave $ipds || exit 1 174sleep 2 175 176rm current.slave.log current-db.slave* || exit 1 177> iprop-stats 178> messages.log 179env ${HEIM_MALLOC_DEBUG} \ 180KRB5_CONFIG="${objdir}/krb5-slave.conf" \ 181${ipropd_slave} --hostname=slave.test.h5l.se -k ${keytab} localhost & 182ipds=$! 183sh ${wait_kdc} ipropd-slave || exit 1 184 185echo "checking slave is up again" 186${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Up' iprop-stats >/dev/null || exit 1 187echo "checking for replay problems" 188${EGREP} 'Entry already exists in database' messages.log && exit 1 189 190# ----------------- checking: checking live truncation of master log 191 192${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1 193sleep 2 194 195echo "live truncate on master log" 196${iprop_log} truncate || exit 1 197sleep 2 198 199echo "Killing master and slave" 200sh ${leaks_kill} ipropd-master $ipdm || exit 1 201sh ${leaks_kill} ipropd-slave $ipds || exit 1 202 203#sleep 2 204#${EGREP} "^master down at " iprop-stats > /dev/null || exit 1 205 206echo "compare versions on master and slave logs" 207KRB5_CONFIG=${objdir}/krb5-slave.conf \ 208${iprop_log} last-version > slave-last.tmp 209${iprop_log} last-version > master-last.tmp 210cmp master-last.tmp slave-last.tmp || exit 1 211 212# ----------------- checking: master going backward 213> iprop-stats 214> messages.log 215 216echo "Going back to old version of the master log file" 217cp ${objdir}/current.log.tmp ${objdir}/current.log 218 219echo "starting master" 220env ${HEIM_MALLOC_DEBUG} \ 221${ipropd_master} --hostname=localhost -k ${keytab} \ 222 --database=${objdir}/current-db & 223ipdm=$! 224sh ${wait_kdc} ipropd-master || exit 1 225 226echo "starting slave" 227env ${HEIM_MALLOC_DEBUG} \ 228KRB5_CONFIG="${objdir}/krb5-slave.conf" \ 229${ipropd_slave} --hostname=slave.test.h5l.se -k ${keytab} localhost & 230ipds=$! 231sh ${wait_kdc} ipropd-slave || exit 1 232 233echo "checking slave is up again" 234${EGREP} 'iprop/slave.test.h5l.se@TEST.H5L.SE.*Up' iprop-stats >/dev/null || exit 1 235echo "checking for replay problems" 236${EGREP} 'Entry already exists in database' messages.log && exit 1 237 238echo "pushing one change" 239${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1 240sleep 2 241 242echo "Killing master" 243sh ${leaks_kill} ipropd-master $ipdm || exit 1 244 245sleep 4 246 247if ! tail -30 messages.log | grep 'disconnected for server' > /dev/null; then 248 echo "client didnt disconnect" 249 exit 1 250fi 251 252echo "probing for slave pid" 253kill -0 ${ipds} || { echo "slave no longer there"; exit 1; } 254 255> messages.log 256 257echo "Staring master again" 258env ${HEIM_MALLOC_DEBUG} \ 259${ipropd_master} --hostname=localhost -k ${keytab} \ 260 --database=${objdir}/current-db & 261ipdm=$! 262sh ${wait_kdc} ipropd-master || exit 1 263 264echo "probing for slave pid" 265kill -0 ${ipds} || { echo "slave no longer there"; exit 1; } 266 267sh ${wait_kdc} ipropd-slave messages.log "connection successful to master" || exit 1 268 269sh ${wait_kdc} ipropd-slave messages.log "ipropd-slave started at version" || exit 1 270 271echo "pushing one change" 272${kadmin} -l cpw --random-password user@${R} > /dev/null || exit 1 273sleep 2 274 275echo "shutting down all services" 276 277trap "" EXIT 278sh ${leaks_kill} kdc $kdcpid || exit 1 279sh ${leaks_kill} ipropd-master $ipdm || exit 1 280sh ${leaks_kill} ipropd-slave $ipds || exit 1 281 282echo "compare versions on master and slave logs" 283KRB5_CONFIG=${objdir}/krb5-slave.conf \ 284${iprop_log} last-version > slave-last.tmp 285${iprop_log} last-version > master-last.tmp 286cmp master-last.tmp slave-last.tmp || exit 1 287 288exit $ec 289