test: When kdc fails to start, show the log
[heimdal.git] / tests / kdc / check-kinit.in
blobc6cb23ff6f8cadd27ecdc7132b0ce041ec370a53
1 #!/bin/bash
3 # Copyright (c) 2006 - 2008 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 env_setup="@env_setup@"
35 objdir="@objdir@"
37 . ${env_setup}
39 KRB5_CONFIG="${objdir}/krb5-kinit.conf"
40 export KRB5_CONFIG
41 KRB5CCNAME="${objdir}/foocc"
42 export KRB5CCNAME
44 testfailed="echo test failed; exit 1"
46 # If there is no useful db support compiled in, disable test
47 ${have_db} || exit 77
49 R=TEST.H5L.SE
51 port=@port@
52 pwport=@pwport@
54 kinit="${kinit} --password-file=${objdir}/foopassword ${afs_no_afslog} -c ${objdir}/foocc"
55 klist="${klist} -c ${objdir}/foocc"
56 kgetcred="${kgetcred} -c ${objdir}/foocc"
57 kdestroy="${kdestroy} ${afs_no_unlog}"
58 kadmin="${kadmin} -l -r $R"
59 kdc="${kdc} --addresses=localhost -P $port"
62 cache="FILE:${objdir}/cache.krb5"
63 keytabfile=${objdir}/server.keytab
64 keytab="FILE:${keytabfile}"
66 > messages.log
68 num_concurrent=50
69 num_princs=20
70 torture_time=200
71 cred_life=$((torture_time / 10))
72 cred_renew_life=$((torture_time / 2))
73 out=${objdir}/out-kinit-torture-kgetcred
74 kinit_out=${objdir}/out-kinit-torture-kinit
76 parent_shell_proc=$$
78 if (($# == 0)); then
80 echo "This is a MANUAL test."
82 rm -f ${keytabfile}
83 rm -f current-db*
84 rm -f out-*
85 rm -f mkey.file*
87 cp "${objdir}/krb5.conf" "${objdir}/krb5-kinit.conf"
89 echo "Creating database"
90 ${kadmin} \
91 init \
92 --realm-max-ticket-life=1day \
93 --realm-max-renewable-life=1month \
94 ${R} || exit 1
96 echo "Adding foo"
97 ${kadmin} add -p foo --use-defaults foo@${R} || exit 1
99 echo "Creating torture principals"
100 for i in $(seq 0 $((num_princs - 1)) ); do
101 ${kadmin} add -r --use-defaults svc${i}@${R} || exit 1
102 done
104 echo "Doing database check"
105 ${kadmin} check ${R} || exit 1
107 echo foo > ${objdir}/foopassword
109 echo Starting kdc ; > messages.log
110 ${kdc} --detach --testing || { echo "kdc failed to start"; cat messages.log; exit 1; }
111 kdcpid=`getpid kdc`
113 trap "kill -9 ${kdcpid}; echo signal killing kdc; exit 1;" EXIT
115 ec=0
116 else
117 echo "begin torture (output in $out)"
118 secs=$(date +%s)
119 cat /dev/null > "$out"
120 while (($(date +%s) < (secs + torture_time) )); do
121 echo .
122 for i in $(seq 0 1000); do
123 printf '%d\n' $((i % num_princs))
124 done | xargs -P $num_concurrent -I '{}' ${kgetcred} "svc{}@${R}"
125 ${klist} -v || exit 1
126 if ! kill -0 $parent_shell_proc; then
127 printf 'Parent shell script exited; exiting'
128 exit 1
129 grep 'Matching credential .* not found' messages.log > /dev/null &&
130 echo "THAT DID NOT WORK RIGHT"
132 sleep 5
133 done
134 ${klist} -v
135 exit 0
138 echo "checking that we have tickets"
139 ${kinit} -l $cred_life -r $cred_renew_life foo@${R} || { ec=1 ; eval "${testfailed}"; }
140 ${klist} -v || { ec=1 ; eval "${testfailed}"; }
141 echo "torturing"
142 ${kinit} -l $cred_life -r $cred_renew_life foo@${R} "$0" torture-me || { ec=1 ; eval "${testfailed}"; }
144 echo "killing kdc (${kdcpid})"
145 sh ${leaks_kill} kdc $kdcpid || exit 1
147 trap "" EXIT
149 exit $ec