cf/largefile.m4: Fix build with autoconf-2.72
[heimdal.git] / tests / kdc / check-kinit.in
blobc85701c040fccc18cb0d4502a20c94bb6b2ff3a4
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 cleanup() {
79 echo signal killing kdc
80 kill -9 ${kdcpid}
81 trap '' EXIT INT TERM
82 cat messages.log
83 exit 1
86 if (($# == 0)); then
88 echo "This is a MANUAL test."
90 rm -f ${keytabfile}
91 rm -f current-db*
92 rm -f out-*
93 rm -f mkey.file*
95 cp "${objdir}/krb5.conf" "${objdir}/krb5-kinit.conf"
97 echo "Creating database"
98 ${kadmin} \
99 init \
100 --realm-max-ticket-life=1day \
101 --realm-max-renewable-life=1month \
102 ${R} || exit 1
104 echo "Adding foo"
105 ${kadmin} add -p foo --use-defaults foo@${R} || exit 1
107 echo "Creating torture principals"
108 for i in $(seq 0 $((num_princs - 1)) ); do
109 ${kadmin} add -r --use-defaults svc${i}@${R} || exit 1
110 done
112 echo "Doing database check"
113 ${kadmin} check ${R} || exit 1
115 echo foo > ${objdir}/foopassword
117 echo Starting kdc ; > messages.log
118 ${kdc} --detach --testing || { echo "kdc failed to start"; cat messages.log; exit 1; }
119 kdcpid=`getpid kdc`
121 trap cleanup EXIT INT TERM
123 ec=0
124 else
125 echo "begin torture (output in $out)"
126 secs=$(date +%s)
127 cat /dev/null > "$out"
128 while (($(date +%s) < (secs + torture_time) )); do
129 echo .
130 for i in $(seq 0 1000); do
131 printf '%d\n' $((i % num_princs))
132 done | xargs -P $num_concurrent -I '{}' ${kgetcred} "svc{}@${R}"
133 ${klist} -v || exit 1
134 if ! kill -0 $parent_shell_proc; then
135 printf 'Parent shell script exited; exiting'
136 exit 1
137 grep 'Matching credential .* not found' messages.log > /dev/null &&
138 echo "THAT DID NOT WORK RIGHT"
140 sleep 5
141 done
142 ${klist} -v
143 exit 0
146 echo "checking that we have tickets"
147 ${kinit} -l $cred_life -r $cred_renew_life foo@${R} || { ec=1 ; eval "${testfailed}"; }
148 ${klist} -v || { ec=1 ; eval "${testfailed}"; }
149 echo "torturing"
150 ${kinit} -l $cred_life -r $cred_renew_life foo@${R} "$0" torture-me || { ec=1 ; eval "${testfailed}"; }
152 echo "killing kdc (${kdcpid})"
153 sh ${leaks_kill} kdc $kdcpid || exit 1
155 trap "" EXIT
157 exit $ec