xref: /netbsd-src/crypto/external/bsd/heimdal/dist/tests/gss/check-ntlm.in (revision 929c70cba110089af68ff46da658d45500ef61a1)
1#!/bin/sh
2#
3# Copyright (c) 2006 - 2007 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#
34# Id
35#
36
37env_setup="@env_setup@"
38srcdir="@srcdir@"
39objdir="@objdir@"
40
41. ${env_setup}
42
43# If there is no useful db support compiled in, disable test
44../db/have-db || exit 77
45
46R=TEST.H5L.SE
47
48port=@port@
49
50keytabfile=${objdir}/server.keytab
51keytab="FILE:${keytabfile}"
52cache="FILE:krb5ccfile"
53cacheds="FILE:krb5ccfile-ds"
54
55kinit="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache ${afs_no_afslog}"
56kinitds="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cacheds ${afs_no_afslog}"
57kadmin="${TESTS_ENVIRONMENT} ../../kadmin/kadmin -l -r $R"
58kdc="${TESTS_ENVIRONMENT} ../../kdc/kdc --addresses=localhost -P $port"
59kdigest="${TESTS_ENVIRONMENT} ../../kuser/kdigest"
60
61context="${TESTS_ENVIRONMENT} ../../lib/gssapi/test_context"
62
63KRB5_CONFIG="${objdir}/krb5.conf"
64export KRB5_CONFIG
65
66KRB5_KTNAME="${keytab}"
67export KRB5_KTNAME
68KRB5CCNAME="${cache}"
69export KRB5CCNAME
70NTLM_ACCEPTOR_CCACHE="${cacheds}"
71export NTLM_ACCEPTOR_CCACHE
72NTLM_USER_FILE="${srcdir}/ntlm-user-file.txt"
73export NTLM_USER_FILE
74
75GSSAPI_SPNEGO_NAME=host@host.test.h5l.se
76export GSSAPI_SPNEGO_NAME
77
78rm -f ${keytabfile}
79rm -f current-db*
80rm -f out-*
81rm -f mkey.file*
82
83> messages.log
84
85echo Creating database
86${kadmin} \
87    init \
88    --realm-max-ticket-life=1day \
89    --realm-max-renewable-life=1month \
90    ${R} || exit 1
91
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
94
95${kadmin} add -p kaka --use-defaults digest/${R}@${R} || exit 1
96
97${kadmin} add -p ds --use-defaults digestserver@${R} || exit 1
98${kadmin} modify --attributes=+allow-digest digestserver@${R} || exit 1
99
100${kadmin} add -p u1 --use-defaults user1@${R} || exit 1
101
102echo "Doing database check"
103${kadmin} check ${R} || exit 1
104
105echo u1 > ${objdir}/foopassword
106echo ds > ${objdir}/barpassword
107
108echo Starting kdc
109${kdc} --detach --testing || { echo "kdc failed to start"; exit 1; }
110kdcpid=`getpid kdc`
111
112trap "kill ${kdcpid}; echo signal killing kdc; exit 1;" EXIT
113
114exitcode=0
115
116echo "Getting client initial tickets"
117${kinit} --password-file=${objdir}/foopassword user1@${R} || exitcode=1
118echo "Getting digestserver initial tickets"
119${kinitds} --password-file=${objdir}/barpassword digestserver@${R} || exitcode=1
120
121echo "======probe"
122KRB5CCNAME="$cacheds"
123
124 ${kdigest} digest-probe --realm=${R} > /dev/null || \
125     { exitcode=1; echo "test failed"; }
126
127echo "======context building ntlm"
128
129NTLM_USER_FILE="${srcdir}/ntlm-user-file.txt-no"
130KRB5CCNAME="$cache"
131
132echo "no NTLM initiator creds"
133${context} --mech-type=ntlm \
134	--mutual \
135        --name-type=hostbased-service \
136        --ret-mech-type=ntlm \
137        host@host.test.h5l.se 2> /dev/null && \
138        { exitcode=1 ; echo "test failed"; }
139
140echo "Getting client initial tickets (with ntlm creds)"
141${kinit} --password-file=${objdir}/foopassword --ntlm-domain=TEST user1@${R} || exitcode=1
142
143echo "NTLM initiator krb5 creds"
144${context} --mech-type=ntlm \
145	--mutual \
146        --name-type=hostbased-service \
147        --ret-mech-type=ntlm \
148        host@host.test.h5l.se || \
149        { exitcode=1 ; echo "test failed"; }
150
151echo "NTLM initiator krb5 creds (getverifymic, wrapunwrap)"
152${context} --mech-type=ntlm \
153	--mutual \
154        --name-type=hostbased-service \
155        --ret-mech-type=ntlm \
156        --getverifymic --wrapunwrap \
157        host@host.test.h5l.se || \
158        { exitcode=1 ; echo "test failed"; }
159
160trap "" EXIT
161
162echo "killing kdc (${kdcpid})"
163kill ${kdcpid} 2> /dev/null
164
165exit $exitcode
166
167
168