xref: /netbsd-src/crypto/external/bsd/heimdal/dist/tests/kdc/check-canon.in (revision 929c70cba110089af68ff46da658d45500ef61a1)
1#!/bin/sh
2#
3# Copyright (c) 2011, Secure Endpoints Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11#   notice, this list of conditions and the following disclaimer.
12#
13# - Redistributions in binary form must reproduce the above copyright
14#   notice, this list of conditions and the following disclaimer in
15#   the documentation and/or other materials provided with the
16#   distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29# OF THE POSSIBILITY OF SUCH DAMAGE.
30
31env_setup="@env_setup@"
32objdir="@objdir@"
33
34. ${env_setup}
35
36# If there is no useful db support compiled in, disable test
37# (krb5_kt_get_entry() is tested in another test)
38${have_db} || exit 77
39
40R1=TEST.H5L.SE
41R2=TEST2.H5L.SE
42R3=TEST3.H5L.SE
43
44port=@port@
45
46kadmin="${kadmin} -l -r ${R1}"
47kdc="${kdc} --addresses=localhost -P $port"
48
49cache="FILE:${objdir}/cache.krb5"
50
51kinit="${kinit} -c $cache ${afs_no_afslog}"
52klist="${klist} -c $cache"
53kgetcred="${kgetcred} -c $cache"
54kdestroy="${kdestroy} -c $cache ${afs_no_unlog}"
55
56KRB5_CONFIG="${objdir}/krb5-canon.conf"
57export KRB5_CONFIG
58
59testfailed="echo test failed; ${klist}; exit 1"
60
61rm -f ${keytabfile}
62rm -f current-db*
63rm -f out-*
64rm -f mkey.file*
65
66> messages.log
67
68echo "Creating database"
69initflags="init --realm-max-ticket-life=1day --realm-max-renewable-life=1month"
70
71${kadmin} ${initflags} ${R1} || exit 1
72${kadmin} ${initflags} ${R2} || exit 1
73${kadmin} ${initflags} ${R3} || exit 1
74
75${kadmin} add -p foo --use-defaults foo@${R1} || exit 1
76
77${kadmin} add -p cross1 --use-defaults krbtgt/${R1}@${R2} || exit 1
78${kadmin} add -p cross2 --use-defaults krbtgt/${R2}@${R1} || exit 1
79${kadmin} add -p cross3 --use-defaults krbtgt/${R3}@${R1} || exit 1
80${kadmin} add -p cross4 --use-defaults krbtgt/${R1}@${R3} || exit 1
81${kadmin} add -p cross5 --use-defaults krbtgt/${R3}@${R2} || exit 1
82${kadmin} add -p cross6 --use-defaults krbtgt/${R2}@${R3} || exit 1
83
84${kadmin} add -p foo --use-defaults host/t1@${R1} || exit 1
85${kadmin} add -p foo --use-defaults host/t2@${R2} || exit 1
86${kadmin} add -p foo --use-defaults host/t3@${R3} || exit 1
87${kadmin} add -p foo --use-defaults host/t11.test1.h5l.se@${R1} || exit 1
88${kadmin} add -p foo --use-defaults host/t12.test1.h5l.se@${R2} || exit 1
89${kadmin} add -p foo --use-defaults host/t22.test2.h5l.se@${R2} || exit 1
90${kadmin} add -p foo --use-defaults host/t23.test2.h5l.se@${R3} || exit 1
91${kadmin} add -p foo --use-defaults host/t33.test3.h5l.se@${R3} || exit 1
92
93
94echo "Doing database check"
95${kadmin} check ${R1} || exit 1
96${kadmin} check ${R2} || exit 1
97${kadmin} check ${R3} || exit 1
98
99echo foo > ${objdir}/foopassword
100
101echo "Starting kdc" ; > messages.log
102${kdc} --detach --testing || { echo "kdc failed to start"; exit 1; }
103kdcpid=`getpid kdc`
104
105trap "kill -9 ${kdcpid}; echo signal killing kdc; exit 1;" EXIT
106
107ec=0
108
109echo "Getting client initial tickets";
110${kinit} --password-file=${objdir}/foopassword foo@${R1} || \
111	{ ec=1 ; eval "${testfailed}"; }
112
113echo "get service tickets (success)"
114for host in t1 t2 t3 t11 t12 t22 t33 ; do
115    echo "    $host"
116    ${kgetcred} --name-type=SRV_HST host $host || { ec=1 ; eval "${testfailed}"; }
117done
118echo "get service tickets (failure)"
119for host in t23 ; do
120    echo "    $host"
121    ${kgetcred} --name-type=SRV_HST host $host 2>/dev/null && { ec=1 ; eval "${testfailed}"; }
122done
123
124echo "check result"
125${klist} | grep 'host/t1@$' > /dev/null ||
126    { ec=1 ; echo "t1 referral entry not present";  eval "${testfailed}"; }
127${klist} | grep "host/t1@${R1}" > /dev/null ||
128    { ec=1 ; echo "canonicalized t1 entry not present";  eval "${testfailed}"; }
129${klist} | grep 'host/t2@$' > /dev/null ||
130    { ec=1 ; echo "t2 referral entry not present";  eval "${testfailed}"; }
131${klist} | grep "host/t2@${R2}" > /dev/null ||
132    { ec=1 ; echo "canonicalized t2 entry not present";  eval "${testfailed}"; }
133${klist} | grep 'host/t3@$' > /dev/null ||
134    { ec=1 ; echo "t3 referral entry not present";  eval "${testfailed}"; }
135${klist} | grep "host/t3@${R3}" > /dev/null ||
136    { ec=1 ; echo "canonicalized t3 entry not present";  eval "${testfailed}"; }
137${klist} | grep 'host/t11@$' > /dev/null ||
138    { ec=1 ; echo "t11 referral entry not present";  eval "${testfailed}"; }
139${klist} | grep "host/t11.test1.h5l.se@${R1}" > /dev/null ||
140    { ec=1 ; echo "canonicalized t11 entry not present";  eval "${testfailed}"; }
141${klist} | grep 'host/t12@$' > /dev/null ||
142    { ec=1 ; echo "t12 referral entry not present";  eval "${testfailed}"; }
143${klist} | grep "host/t12.test1.h5l.se@${R2}" > /dev/null ||
144    { ec=1 ; echo "canonicalized t12 entry not present";  eval "${testfailed}"; }
145${klist} | grep 'host/t22@$' > /dev/null ||
146    { ec=1 ; echo "t22 referral entry not present";  eval "${testfailed}"; }
147${klist} | grep "host/t22.test2.h5l.se@${R2}" > /dev/null ||
148    { ec=1 ; echo "canonicalized t22 entry not present";  eval "${testfailed}"; }
149${klist} | grep 'host/t33@$' > /dev/null ||
150    { ec=1 ; echo "t33 referral entry not present";  eval "${testfailed}"; }
151${klist} | grep "host/t33.test3.h5l.se@${R3}" > /dev/null ||
152    { ec=1 ; echo "canonicalized t33 entry not present";  eval "${testfailed}"; }
153
154
155${kdestroy}
156
157if false; then
158
159    # This may not be portable.  It'd be nice to be able to set more of the
160    # resolver configuration via the environment!
161    LOCALDOMAIN=test1.h5l.se
162    export LOCALDOMAIN
163    KRB5_CONFIG="${objdir}/krb5-canon2.conf"
164    export KRB5_CONFIG
165
166    echo "Getting client initial tickets (round 2)";
167    ${kinit} --password-file=${objdir}/foopassword foo@${R1} || \
168    	{ ec=1 ; eval "${testfailed}"; }
169
170    echo "get service tickets (success)"
171    for host in t1 t2 t3 t11 ; do
172        echo "    $host"
173        ${kgetcred} --name-type=SRV_HST host $host || { ec=1 ; eval "${testfailed}"; }
174    done
175    echo "get service tickets (failure)"
176    for host in t12 t22 t23 t33 ; do
177        echo "    $host"
178        ${kgetcred} --name-type=SRV_HST host $host 2> /dev/null &&
179            { ec=1 ; eval "${testfailed}"; }
180    done
181
182    echo "check result"
183    ${klist} | grep 'host/t1@$' > /dev/null ||
184        { ec=1 ; echo "t1 referral entry not present";  eval "${testfailed}"; }
185    ${klist} | grep "host/t1@${R1}" > /dev/null ||
186        { ec=1 ; echo "canonicalized t1 entry not present";  eval "${testfailed}"; }
187    ${klist} | grep 'host/t2@$' > /dev/null ||
188        { ec=1 ; echo "t2 referral entry not present";  eval "${testfailed}"; }
189    ${klist} | grep "host/t2@${R2}" > /dev/null ||
190        { ec=1 ; echo "canonicalized t2 entry not present";  eval "${testfailed}"; }
191    ${klist} | grep 'host/t3@$' > /dev/null ||
192        { ec=1 ; echo "t3 referral entry not present";  eval "${testfailed}"; }
193    ${klist} | grep "host/t3@${R3}" > /dev/null ||
194        { ec=1 ; echo "canonicalized t3 entry not present";  eval "${testfailed}"; }
195    ${klist} | grep 'host/t11@$' > /dev/null ||
196        { ec=1 ; echo "t11 referral entry not present";  eval "${testfailed}"; }
197    ${klist} | grep "host/t11.test1.h5l.se@${R1}" > /dev/null ||
198        { ec=1 ; echo "canonicalized t11 entry not present";  eval "${testfailed}"; }
199
200
201    ${kdestroy}
202fi
203
204
205echo "killing kdc (${kdcpid})"
206sh ${leaks_kill} kdc $kdcpid || exit 1
207
208trap "" EXIT
209
210exit $ec
211