s4:torture: Adapt KDC canon test to Heimdal upstream changes
[Samba.git] / source4 / heimdal / tests / gss / check-spnego.in
blob3cf5608960216e745233858f43a79072a2d4afc5
1 #!/bin/sh
3 # Copyright (c) 2006 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 # $Id$
37 env_setup="@env_setup@"
38 srcdir="@srcdir@"
39 objdir="@objdir@"
41 . ${env_setup}
43 # If there is no useful db support compiled in, disable test
44 ../db/have-db || exit 77
46 R=TEST.H5L.SE
48 port=@port@
50 keytabfile=${objdir}/server.keytab
51 keytab="FILE:${keytabfile}"
52 cache="FILE:krb5ccfile"
53 cacheds="FILE:krb5ccfile-ds"
55 kinit="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache ${afs_no_afslog} --forwardable"
56 kinitds="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cacheds ${afs_no_afslog}"
57 kadmin="${TESTS_ENVIRONMENT} ../../kadmin/kadmin -l -r $R"
58 kdc="${TESTS_ENVIRONMENT} ../../kdc/kdc --addresses=localhost -P $port"
60 context="${TESTS_ENVIRONMENT} ../../lib/gssapi/test_context"
62 KRB5_CONFIG="${objdir}/krb5.conf"
63 export KRB5_CONFIG
65 KRB5CCNAME=${cache}
66 KRB5_KTNAME="${keytab}"
67 export KRB5_KTNAME
68 KRB5CCNAME="${cache}"
69 export KRB5CCNAME
70 NTLM_ACCEPTOR_CCACHE="${cacheds}"
71 export NTLM_ACCEPTOR_CCACHE
72 NTLM_USER_FILE="${srcdir}/ntlm-user-file.txt"
73 export NTLM_USER_FILE
75 GSSAPI_SPNEGO_NAME=host@host.test.h5l.se
76 export GSSAPI_SPNEGO_NAME
78 rm -f ${keytabfile}
79 rm -f current-db*
80 rm -f out-*
81 rm -f mkey.file*
83 > messages.log
85 echo Creating database
86 ${kadmin} \
87 init \
88 --realm-max-ticket-life=1day \
89 --realm-max-renewable-life=1month \
90 ${R} || exit 1
92 ${kadmin} add -p p1 --use-defaults host/host.test.h5l.se@${R} || exit 1
93 ${kadmin} ext -k ${keytab} host/host.test.h5l.se@${R} || exit 1
95 ${kadmin} add -p kaka --use-defaults digest/${R}@${R} || exit 1
97 ${kadmin} add -p ds --use-defaults digestserver@${R} || exit 1
98 ${kadmin} modify --attributes=+allow-digest digestserver@${R} || exit 1
100 ${kadmin} add -p u1 --use-defaults user1@${R} || exit 1
102 echo "Doing database check"
103 ${kadmin} check ${R} || exit 1
105 echo u1 > ${objdir}/foopassword
106 echo ds > ${objdir}/barpassword
108 echo Starting kdc
109 ${kdc} --detach --testing || { echo "kdc failed to start"; exit 1; }
110 kdcpid=`getpid kdc`
112 trap "kill ${kdcpid}; echo signal killing kdc; exit 1;" EXIT
114 exitcode=0
116 echo "Getting client initial tickets"
117 ${kinit} --password-file=${objdir}/foopassword user1@${R} || exitcode=1
118 echo "Getting digestserver initial tickets"
119 ${kinitds} --password-file=${objdir}/barpassword digestserver@${R} || exitcode=1
121 echo "======context building for each mech"
123 for mech in ntlm krb5 ; do
124 echo "${mech}"
125 ${context} --mech-type=${mech} --ret-mech-type=${mech} \
126 --client-ccache="${cache}" \
127 --gsskrb5-acceptor-identity="${keytab}" \
128 --name-type=hostbased-service host@host.test.h5l.se || \
129 { exitcode=1 ; echo test failed; }
130 done
132 echo "spnego"
133 ${context} \
134 --client-ccache="${cache}" \
135 --mech-type=spnego \
136 --ret-mech-type=krb5 \
137 --name-type=hostbased-service \
138 --export-import-context \
139 host@host.test.h5l.se || \
140 { exitcode=1 ; echo test failed; }
142 echo "spnego (split tokens)"
143 ${context} \
144 --token-split=128 \
145 --client-ccache="${cache}" \
146 --mech-type=spnego \
147 --ret-mech-type=krb5 \
148 --name-type=hostbased-service \
149 --export-import-context \
150 host@host.test.h5l.se || \
151 { exitcode=1 ; echo test failed; }
153 echo "test failure cases"
154 ${context} --mech-type=ntlm --ret-mech-type=krb5 \
155 --client-ccache="${cache}" \
156 --name-type=hostbased-service host@host.test.h5l.se 2> /dev/null && \
157 { exitcode=1 ; echo test failed; }
159 ${context} --mech-type=krb5 --ret-mech-type=ntlm \
160 --client-ccache="${cache}" \
161 --name-type=hostbased-service host@host.test.h5l.se 2> /dev/null && \
162 { exitcode=1 ; echo test failed; }
164 echo "======spnego variants context building"
166 for arg in \
167 "" \
168 "--mutual" \
169 "--delegate" \
170 "--mutual --delegate" \
171 "--getverifymic --wrapunwrap" \
172 "--mutual --getverifymic --wrapunwrap" \
173 ; do
175 echo "no NTLM acceptor cred ${arg}"
176 NTLM_ACCEPTOR_CCACHE="${cacheds}-no"
177 ${context} --mech-type=spnego \
178 $arg \
179 --name-type=hostbased-service \
180 --ret-mech-type=krb5 \
181 host@host.test.h5l.se || \
182 { exitcode=1 ; echo test failed; }
183 NTLM_ACCEPTOR_CCACHE="${cacheds}"
185 echo "no NTLM initiator cred ${arg}"
186 NTLM_USER_FILE="${srcdir}/ntlm-user-file.txt-no"
187 ${context} --mech-type=spnego \
188 $arg \
189 --name-type=hostbased-service \
190 --ret-mech-type=krb5 \
191 host@host.test.h5l.se || \
192 { exitcode=1 ; echo test failed; }
193 NTLM_USER_FILE="${srcdir}/ntlm-user-file.txt"
195 echo "no krb5 acceptor cred ${arg}"
196 KRB5_KTNAME="${keytab}-no"
197 ${context} --mech-type=spnego \
198 $arg \
199 --server-no-delegate \
200 --name-type=hostbased-service \
201 --ret-mech-type=ntlm \
202 host@host.test.h5l.se || \
203 { exitcode=1 ; echo test failed; }
204 KRB5_KTNAME="${keytab}"
206 echo "no explicit krb5 acceptor cred ${arg}"
207 ${context} --mech-type=spnego \
208 $arg \
209 --gsskrb5-acceptor-identity="${keytab}-no" \
210 --server-no-delegate \
211 --name-type=hostbased-service \
212 --ret-mech-type=krb5 \
213 host@host.test.h5l.se 2>/dev/null && \
214 { exitcode=1 ; echo test failed; }
216 echo "no krb5 initiator cred ${arg}"
217 KRB5CCNAME="${cache}-no"
218 ${context} --mech-type=spnego \
219 $arg \
220 --server-no-delegate \
221 --name-type=hostbased-service \
222 --ret-mech-type=ntlm \
223 host@host.test.h5l.se || \
224 { exitcode=1 ; echo test failed; }
225 KRB5CCNAME="${cache}"
227 echo "no explicit krb5 initiator cred ${arg}"
228 ${context} --mech-type=spnego \
229 $arg \
230 --client-ccache="${cache}-no" \
231 --server-no-delegate \
232 --name-type=hostbased-service \
233 --ret-mech-type=krb5 \
234 host@host.test.h5l.se 2>/dev/null && \
235 { exitcode=1 ; echo test failed; }
237 done
239 trap "" EXIT
241 echo "killing kdc (${kdcpid})"
242 kill ${kdcpid} 2> /dev/null
244 exit $exitcode