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