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
45uid=82367356
46u=heimdaltestuser
47s=heimdalserveruser
48r=FOO.H5L.SE
49d=foo.h5l.se
50
51. ${env_setup}
52
53KRB5_CONFIG="${1-${confdir}/krb5.conf}"
54export KRB5_CONFIG
55
56logfile=${testdir}/messages.log
57cache="FILE:${testdir}/cache.krb5"
58
59testfailed="echo test failed; cat ${logfile}; exit 1"
60
61dscl . -delete /Users/$u > /dev/null 2>/dev/null
62dscl . -create /Users/$u || exit 1
63dscl . -create /Users/$u/UniqueID $uid
64dscl . -create /Users/$u/PrimaryGroupID 20
65dscl . -append /Users/$u RealName "Heimdal testuser" || exit 1
66
67dscl . -delete /Users/$s > /dev/null 2>/dev/null
68dscl . -create /Users/$s || exit 1
69dscl . -create /Users/$s/UniqueID $(expr $uid + 1)
70dscl . -create /Users/$s/PrimaryGroupID 20
71dscl . -append /Users/$s RealName "Heimdal test server" || exit 1
72
73
74defaults write com.apple.Kerberos ForceHeimODServerMode -bool YES
75
76trap "defaults delete com.apple.Kerberos ForceHeimODServerMode" EXIT
77
78$hodadmin . principal-create $u $u@$r || exit 1
79$hodadmin . password $u foo || exit 1
80$hodadmin . password $u foo || exit 1
81$hodadmin . principal-clearflags $u Invalid Forwardable || exit 1
82$hodadmin . principal-setflags $u Forwardable || exit 1
83
84$hodadmin . principal-create $s $s@$r || exit 1
85$hodadmin . password $s foo || exit 1
86$hodadmin . principal-clearflags $s Invalid Forwardable || exit 1
87$hodadmin . principal-setflags $s Forwardable || exit 1
88
89$hodadmin . alias-add $s host/$s.$d@$r || exit 1
90$hodadmin . password --append $s foo host/$s.$d@$r || exit 1
91
92$hodadmin . alias-add $s cifs/$s.$d@$r || exit 1
93$hodadmin . password --append $s foo cifs/$s.$d@$r || exit 1
94$hodadmin . alias-remove $s cifs/$s.$d@$r || exit 1
95
96
97defaults delete com.apple.Kerberos ForceHeimODServerMode
98trap - EXIT
99
100dscl . -delete /Users/$u
101dscl . -delete /Users/$s
102
103exit $ec
104