roken: Windows ELOOP definition
[heimdal.git] / tests / kdc / check-kinit.in
blob168f3a2e81a3e7785a928993d34a3307b018170e
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 compile 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} &
111 kdcpid=$!
113 sh ${wait_kdc}
114 if [ "$?" != 0 ] ; then
115 kill -9 ${kdcpid}
116 exit 1
119 trap "kill -9 ${kdcpid}; echo signal killing kdc; exit 1;" EXIT
121 ec=0
122 else
123 echo "begin torture (output in $out)"
124 secs=$(date +%s)
125 cat /dev/null > "$out"
126 while (($(date +%s) < (secs + torture_time) )); do
127 echo .
128 for i in $(seq 0 1000); do
129 printf '%d\n' $((i % num_princs))
130 done | xargs -P $num_concurrent -I '{}' ${kgetcred} "svc{}@${R}"
131 ${klist} -v || exit 1
132 if ! kill -0 $parent_shell_proc; then
133 printf 'Parent shell script exited; exiting'
134 exit 1
135 grep 'Matching credential .* not found' messages.log > /dev/null &&
136 echo "THAT DID NOT WORK RIGHT"
138 sleep 5
139 done
140 ${klist} -v
141 exit 0
144 echo "checking that we have tickets"
145 ${kinit} -l $cred_life -r $cred_renew_life foo@${R} || { ec=1 ; eval "${testfailed}"; }
146 ${klist} -v || { ec=1 ; eval "${testfailed}"; }
147 echo "torturing"
148 ${kinit} -l $cred_life -r $cred_renew_life foo@${R} "$0" torture-me || { ec=1 ; eval "${testfailed}"; }
150 echo "killing kdc (${kdcpid})"
151 sh ${leaks_kill} kdc $kdcpid || exit 1
153 trap "" EXIT
155 exit $ec