ctdb-daemon: Consolidate basic CTDB context initialisation
[samba.git] / testprogs / blackbox / test_kinit_heimdal.sh
1 #!/bin/sh
2 # Blackbox tests for kinit and kerberos integration with smbclient etc
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
5
6 if [ $# -lt 5 ]; then
7 cat <<EOF
8 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX ENCTYPE SMBCLIENT
9 EOF
10 exit 1;
11 fi
12
13 SERVER=$1
14 USERNAME=$2
15 PASSWORD=$3
16 REALM=$4
17 DOMAIN=$5
18 PREFIX=$6
19 ENCTYPE=$7
20 smbclient=$8
21 shift 8
22 failed=0
23
24 samba4bindir="$BINDIR"
25 samba4srcdir="$SRCDIR/source4"
26 samba4kinit=kinit
27 if test -x $BINDIR/samba4kinit; then
28         samba4kinit=$BINDIR/samba4kinit
29 fi
30
31 samba_tool="$samba4bindir/samba-tool"
32 texpect="$samba4bindir/texpect"
33 samba4kpasswd=kpasswd
34 if test -x $BINDIR/samba4kpasswd; then
35         samba4kpasswd=$BINDIR/samba4kpasswd
36 fi
37
38 enableaccount="$samba_tool user enable"
39 machineaccountccache="$samba4srcdir/scripting/bin/machineaccountccache"
40
41 ldbmodify="ldbmodify"
42 if [ -x "$samba4bindir/ldbmodify" ]; then
43         ldbmodify="$samba4bindir/ldbmodify"
44 fi
45
46 ldbsearch="ldbsearch"
47 if [ -x "$samba4bindir/ldbsearch" ]; then
48         ldbsearch="$samba4bindir/ldbsearch"
49 fi
50
51 . `dirname $0`/subunit.sh
52 . `dirname $0`/common_test_fns.inc
53
54 enctype="-e $ENCTYPE"
55 unc="//$SERVER/tmp"
56
57 ADMIN_LDBMODIFY_CONFIG="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
58 export ADMIN_LDBMODIFY_CONFIG
59
60 KRB5CCNAME_PATH="$PREFIX/tmpccache"
61 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
62 ADMIN_KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
63 export KRB5CCNAME
64 rm -rf $KRB5CCNAME_PATH
65
66 testit "reset password policies beside of minimum password age of 0 days" $VALGRIND $samba_tool domain passwordsettings $ADMIN_LDBMODIFY_CONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=0 --max-pwd-age=default || failed=`expr $failed + 1`
67
68 echo $PASSWORD > $PREFIX/tmppassfile
69 testit "kinit with password" $samba4kinit $enctype --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
70 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
71
72 testit "kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
73 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
74
75 testit "kinit with password (windows style)" $samba4kinit $enctype  --renewable --windows --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
76 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
77
78 testit "kinit renew ticket" $samba4kinit $enctype --request-pac -R
79
80 test_smbclient "Test login with kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
81
82 testit "check time with kerberos ccache" $VALGRIND $samba_tool time $SERVER $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
83
84 USERPASS=testPass@12%
85 echo $USERPASS > $PREFIX/tmpuserpassfile
86 testit "add user with kerberos ccache" $VALGRIND $samba_tool user create nettestuser $USERPASS $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
87
88 echo "Getting defaultNamingContext"
89 BASEDN=`$ldbsearch $options --basedn='' -H ldap://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
90
91 cat > $PREFIX/tmpldbmodify <<EOF
92 dn: cn=nettestuser,cn=users,$BASEDN
93 changetype: modify
94 add: servicePrincipalName
95 servicePrincipalName: host/nettestuser
96 replace: userPrincipalName
97 userPrincipalName: nettest@$REALM
98 EOF
99
100 testit "modify servicePrincipalName and userPrincpalName" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
101
102 testit "set user password with kerberos ccache" $VALGRIND $samba_tool user setpassword nettestuser --newpassword=$USERPASS $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
103
104 testit "enable user with kerberos cache" $VALGRIND $enableaccount nettestuser -H ldap://$SERVER -k yes $@ || failed=`expr $failed + 1`
105
106 KRB5CCNAME_PATH="$PREFIX/tmpuserccache"
107 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
108 export KRB5CCNAME
109
110 rm -f $KRB5CCNAME_PATH
111 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
112
113 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
114
115 NEWUSERPASS=testPaSS@34%
116 testit "change user password with 'samba-tool user password' (rpc)" $VALGRIND $samba_tool user password -W$DOMAIN -Unettestuser%$USERPASS $CONFIGURATION -k no --newpassword=$NEWUSERPASS $@ || failed=`expr $failed + 1`
117
118 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
119 rm -f $KRB5CCNAME_PATH
120 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
121
122 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
123
124
125 rm -f $KRB5CCNAME_PATH
126 testit "kinit with password (NT-Principal style) using UPN" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM   || failed=`expr $failed + 1`
127 test_smbclient "Test login with user kerberos ccache from enterprise UPN" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
128
129 rm -f $KRB5CCNAME_PATH
130 testit "kinit with password (enterprise style) using UPN" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM   || failed=`expr $failed + 1`
131 test_smbclient "Test login with user kerberos ccache from enterprise UPN" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
132
133 rm -f $KRB5CCNAME_PATH
134 testit "kinit with password (windows style) using UPN" $samba4kinit $enctype  --renewable --windows --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM   || failed=`expr $failed + 1`
135 test_smbclient "Test login with user kerberos ccache from windows UPN" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
136
137 cat > $PREFIX/tmpldbmodify <<EOF
138 dn: cn=nettestuser,cn=users,$BASEDN
139 changetype: modify
140 replace: userPrincipalName
141 userPrincipalName: nettest@$REALM.org
142 EOF
143
144 testit "modify userPrincipalName to be a different domain" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
145
146 rm -f $KRB5CCNAME_PATH
147 testit "kinit with password (enterprise style) using UPN" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM.org   || failed=`expr $failed + 1`
148 test_smbclient "Test login with user kerberos ccache from enterprise UPN, different domain" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
149
150
151 USERPASS=$NEWUSERPASS
152 NEWUSERPASS=testPaSS@56%
153 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
154
155 cat > $PREFIX/tmpkpasswdscript <<EOF
156 expect Password
157 password ${USERPASS}\n
158 expect New password
159 send ${NEWUSERPASS}\n
160 expect Verify password
161 send ${NEWUSERPASS}\n
162 expect Success
163 EOF
164
165 testit "change user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
166
167 rm -f $KRB5CCNAME_PATH
168 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
169
170 NEWUSERPASS=testPaSS@78%
171 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
172
173 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
174
175 cat > $PREFIX/tmpkpasswdscript <<EOF
176 expect New password
177 send ${NEWUSERPASS}\n
178 expect Verify password
179 send ${NEWUSERPASS}\n
180 expect Success
181 EOF
182
183 testit "set user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$ADMIN_KRB5CCNAME nettestuser@$REALM || failed=`expr $failed + 1`
184
185 rm -f $KRB5CCNAME_PATH
186 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
187
188 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
189
190 NEWUSERPASS=testPaSS@910%
191 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
192
193 cat > $PREFIX/tmpkpasswdscript <<EOF
194 expect New password
195 send ${NEWUSERPASS}\n
196 expect Verify password
197 send ${NEWUSERPASS}\n
198 expect Success
199 EOF
200
201 testit "set user password with kpasswd and servicePrincipalName" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache host/nettestuser@$REALM || failed=`expr $failed + 1`
202
203 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
204
205 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
206
207 cat > $PREFIX/tmpldbmodify <<EOF
208 dn: cn=nettestuser,cn=users,$BASEDN
209 changetype: modify
210 replace: pwdLastSet
211 pwdLastSet: 0
212 EOF
213
214 USERPASS=$NEWUSERPASS
215 NEWUSERPASS=testPaSS@911%
216
217 testit "modify pwdLastSet" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
218
219 cat > $PREFIX/tmppasswordchange <<EOF
220 expect nettestuser@${REALM}'s Password:
221 send ${USERPASS}\n
222 expect Your password will expire at
223 expect Changing password
224 expect New password:
225 send ${NEWUSERPASS}\n
226 expect Repeat new password:
227 send ${NEWUSERPASS}\n
228 expect Success: Password changed
229 EOF
230
231 testit "kinit with user password for expired password" $texpect $PREFIX/tmppasswordchange $samba4kinit $enctype --request-pac nettestuser@$REALM && failed=`expr $failed + 1`
232
233 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
234
235 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
236 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
237
238 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
239
240 KRB5CCNAME_PATH="$PREFIX/tmpccache"
241 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
242 export KRB5CCNAME
243
244 rm -rf $KRB5CCNAME_PATH
245
246 lowerrealm=$(echo $REALM | tr '[A-Z]' '[a-z]')
247 test_smbclient "Test login with user kerberos lowercase realm" 'ls' "$unc" -k yes -Unettestuser@$lowerrealm%$NEWUSERPASS || failed=`expr $failed + 1`
248 test_smbclient "Test login with user kerberos lowercase realm 2" 'ls' "$unc" -k yes -Unettestuser@$REALM%$NEWUSERPASS --realm=$lowerrealm || failed=`expr $failed + 1`
249
250 testit "del user with kerberos ccache" $VALGRIND $samba_tool user delete nettestuser $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
251
252 rm -f $KRB5CCNAME_PATH
253 testit "kinit with machineaccountccache script" $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed=`expr $failed + 1`
254 test_smbclient "Test machine account login with kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
255
256 testit "reset password policies" $VALGRIND $samba_tool domain passwordsettings $ADMIN_LDBMODIFY_CONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
257
258 rm -f $PREFIX/tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
259 exit $failed