xref: /netbsd-src/crypto/external/bsd/heimdal/dist/tests/kdc/check-kinit.in (revision 929c70cba110089af68ff46da658d45500ef61a1)
1#!/bin/bash
2#
3# Copyright (c) 2006 - 2008 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
34env_setup="@env_setup@"
35objdir="@objdir@"
36
37. ${env_setup}
38
39KRB5_CONFIG="${objdir}/krb5-kinit.conf"
40export KRB5_CONFIG
41KRB5CCNAME="${objdir}/foocc"
42export KRB5CCNAME
43
44testfailed="echo test failed; exit 1"
45
46# If there is no useful db support compiled in, disable test
47${have_db} || exit 77
48
49R=TEST.H5L.SE
50
51port=@port@
52pwport=@pwport@
53
54kinit="${kinit} --password-file=${objdir}/foopassword ${afs_no_afslog} -c ${objdir}/foocc"
55klist="${klist} -c ${objdir}/foocc"
56kgetcred="${kgetcred} -c ${objdir}/foocc"
57kdestroy="${kdestroy} ${afs_no_unlog}"
58kadmin="${kadmin} -l -r $R"
59kdc="${kdc} --addresses=localhost -P $port"
60
61
62cache="FILE:${objdir}/cache.krb5"
63keytabfile=${objdir}/server.keytab
64keytab="FILE:${keytabfile}"
65
66> messages.log
67
68num_concurrent=50
69num_princs=20
70torture_time=200
71cred_life=$((torture_time / 10))
72cred_renew_life=$((torture_time / 2))
73out=${objdir}/out-kinit-torture-kgetcred
74kinit_out=${objdir}/out-kinit-torture-kinit
75
76parent_shell_proc=$$
77
78if (($# == 0)); then
79
80    echo "This is a MANUAL test."
81
82    rm -f ${keytabfile}
83    rm -f current-db*
84    rm -f out-*
85    rm -f mkey.file*
86
87    cp "${objdir}/krb5.conf" "${objdir}/krb5-kinit.conf"
88
89    echo "Creating database"
90    ${kadmin} \
91	init \
92	--realm-max-ticket-life=1day \
93	--realm-max-renewable-life=1month \
94	${R} || exit 1
95
96    echo "Adding foo"
97    ${kadmin} add -p foo --use-defaults foo@${R} || exit 1
98
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
103
104    echo "Doing database check"
105    ${kadmin} check ${R} || exit 1
106
107    echo foo > ${objdir}/foopassword
108
109    echo Starting kdc ; > messages.log
110    ${kdc} --detach --testing || { echo "kdc failed to start"; exit 1; }
111    kdcpid=`getpid kdc`
112
113    trap "kill -9 ${kdcpid}; echo signal killing kdc; exit 1;" EXIT
114
115    ec=0
116else
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"
131	fi
132	sleep 5
133    done
134    ${klist} -v
135    exit 0
136fi
137
138echo "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}"; }
141echo "torturing"
142${kinit} -l $cred_life -r $cred_renew_life foo@${R} "$0" torture-me || { ec=1 ; eval "${testfailed}"; }
143
144echo "killing kdc (${kdcpid})"
145sh ${leaks_kill} kdc $kdcpid || exit 1
146
147trap "" EXIT
148
149exit $ec
150