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# Portions Copyright (c) 2009 - 2010 Apple Inc. All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without 
10# modification, are permitted provided that the following conditions 
11# are met: 
12#
13# 1. Redistributions of source code must retain the above copyright 
14#    notice, this list of conditions and the following disclaimer. 
15#
16# 2. Redistributions in binary form must reproduce the above copyright 
17#    notice, this list of conditions and the following disclaimer in the 
18#    documentation and/or other materials provided with the distribution. 
19#
20# 3. Neither the name of the Institute nor the names of its contributors 
21#    may be used to endorse or promote products derived from this software 
22#    without specific prior written permission. 
23#
24# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
25# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
26# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
27# ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
28# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
29# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
30# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
31# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
32# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
33# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
34# SUCH DAMAGE. 
35
36env_setup="@env_setup@"
37confdir="@confdir@"
38testdir="@testdir@"
39
40if [ "$UID" != 0 ] ; then
41    echo "must run script as root since it create users"
42    exit 1
43fi
44
45mkdir -p $testdir 2> /dev/null
46
47R="HEIMDAL-SERVERNAME-TEST.APPLE.COM"
48
49. ${env_setup}
50
51KRB5_CONFIG="${1-${confdir}/krb5.conf}"
52export KRB5_CONFIG
53
54logfile=${testdir}/messages.log
55cache="FILE:${testdir}/cache.krb5"
56
57testfailed="echo test failed; cat ${logfile}; exit 1"
58
59kinit="${kinit} -c $cache"
60slapconfig="/usr/sbin/slapconfig"
61
62launchctl setenv MallocStackLoggingNoCompact 1
63launchctl setenv MallocErrorAbort 1
64
65
66rm -f ${testdir}/out-*
67
68> ${logfile}
69
70
71echo admin > ${testdir}/foopassword
72
73
74echo "Removing existing domain"
75${slapconfig} -destroyldapserver || exit 1
76
77pw=admin
78
79echo "Creating domain"
80cat > ${testdir}/setup.txt <<EOF
81expect Password
82password ${pw}\n
83EOF
84
85${rkpty} ${testdir}/setup.txt ${slapconfig} -createldapmasterandadmin diradmin ${pw} 1000 dc=heimdal-servername-test,dc=apple,dc=com ${R} || exit 1
86
87ec=0
88
89killall -9 kdc
90sleep 5
91
92for a in 1 2 3 4 5 6 7 8 9 10 ; do
93echo "Getting client initial tickets ${a}"; > ${logfile}
94    ${kinit} --password-file=${testdir}/foopassword diradmin@${R} ||
95	{ ec=1 ; eval "${testfailed}"; }
96done
97
98oldpw="${pw}"
99pw=ak4unandsop39NuJ
100
101echo "Changing password"
102cat > cpw.tmp <<EOF
103expect Password
104password ${oldpw}\n
105expect New password
106send ${pw}\n
107expect New password
108send ${pw}\n
109expect Success
110EOF
111
112${rkpty} cpw.tmp env ${kpasswd} diradmin@${R} || \
113{ ec=$? ; eval "${testfailed}"; }
114
115rm cpw.tmp
116
117echo ${pw} > ${testdir}/foopassword
118
119echo "Getting client initial tickets"; > ${logfile}
120${kinit} --password-file=${testdir}/foopassword diradmin@${R} ||  \
121   { ec=1 ; eval "${testfailed}"; }
122
123
124kdcpid=$(ps -ax -o pid,comm  | grep kdc | awk '{print $1}')
125echo "killing kdc (${kdcpid})"
126#kill $kdcpid
127#sleep 3
128#kill -9 $kdcpid
129sh ${leaks_kill} kdc $kdcpid || exit 1
130
131launchctl unsetenv MallocStackLoggingNoCompact
132launchctl unsetenv MallocErrorAbort
133
134trap "" EXIT
135
136exit $ec
137