2 # Blackbox tests for kinit and kerberos integration with smbclient etc
3 # Copyright (c) 2015-2016 Andreas Schneider <asn@samba.org>
7 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX SMBCLIENT
22 samba_bindir
="$BINDIR"
23 samba_srcdir
="$SRCDIR/source4"
25 samba_kdestroy
=kdestroy
28 samba_tool
="$samba_bindir/samba-tool"
29 samba_texpect
="$samba_bindir/texpect"
31 samba_enableaccount
="$samba_tool user enable"
32 machineaccountccache
="$samba_srcdir/scripting/bin/machineaccountccache"
35 if [ -x "$samba4bindir/ldbmodify" ]; then
36 ldbmodify
="$samba4bindir/ldbmodify"
40 if [ -x "$samba4bindir/ldbsearch" ]; then
41 ldbsearch
="$samba4bindir/ldbsearch"
44 .
`dirname $0`/subunit.sh
52 $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp
-c "$cmd" $@
54 if [ x
$status = x0
]; then
62 ADMIN_LDBMODIFY_CONFIG
="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
63 export ADMIN_LDBMODIFY_CONFIG
65 KRB5CCNAME_PATH
="$PREFIX/tmpccache"
66 KRB5CCNAME
="FILE:$KRB5CCNAME_PATH"
67 ADMIN_KRB5CCNAME
="FILE:$KRB5CCNAME_PATH"
69 rm -rf $KRB5CCNAME_PATH
71 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`
73 cat > $PREFIX/tmpkinitscript
<<EOF
78 ###########################################################
79 ### Test kinit defaults
80 ###########################################################
82 testit
"kinit with password" $samba_texpect $PREFIX/tmpkinitscript
$samba_kinit $USERNAME@
$REALM || failed
=`expr $failed + 1`
83 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
85 testit
"kinit renew ticket" $samba_kinit -R || failed
=`expr $failed + 1`
86 test_smbclient
"Test login with kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
90 ###########################################################
91 ### Test kinit with enterprice principal
92 ###########################################################
94 testit
"kinit with password (enterprise style)" $samba_texpect $PREFIX/tmpkinitscript
$samba_kinit -E $USERNAME@
$REALM || failed
=`expr $failed + 1`
95 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
97 # This does not work with MIT Kerberos 1.14 or older
98 testit
"kinit renew ticket (enterprise style)" $samba_kinit -R || failed
=`expr $failed + 1`
99 test_smbclient
"Test login with kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
103 ###########################################################
104 ### Tests with kinit default again
105 ###########################################################
107 testit
"kinit with password" $samba_texpect $PREFIX/tmpkinitscript
$samba_kinit $USERNAME@
$REALM || failed
=`expr $failed + 1`
108 testit
"check time with kerberos ccache" $VALGRIND $samba_tool time $SERVER $CONFIGURATION -k yes $@ || failed
=`expr $failed + 1`
110 USERPASS
="testPass@12%"
112 testit
"add user with kerberos ccache" $VALGRIND $samba_tool user create nettestuser
$USERPASS $CONFIGURATION -k yes $@ || failed
=`expr $failed + 1`
114 echo "Getting defaultNamingContext"
115 BASEDN
=`$ldbsearch $options --basedn='' -H ldap://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
117 cat > $PREFIX/tmpldbmodify
<<EOF
118 dn: cn=nettestuser,cn=users,$BASEDN
120 add: servicePrincipalName
121 servicePrincipalName: host/nettestuser
122 replace: userPrincipalName
123 userPrincipalName: nettest@$REALM
126 testit
"modify servicePrincipalName and userPrincpalName" $VALGRIND $ldbmodify -H ldap
://$SERVER $PREFIX/tmpldbmodify
-k yes $@ || failed
=`expr $failed + 1`
128 testit
"set user password with kerberos ccache" $VALGRIND $samba_tool user setpassword nettestuser
--newpassword=$USERPASS $CONFIGURATION -k yes $@ || failed
=`expr $failed + 1`
130 testit
"enable user with kerberos cache" $VALGRIND $samba_enableaccount nettestuser
-H ldap
://$SERVER -k yes $@ || failed
=`expr $failed + 1`
132 ###########################################################
133 ### Test kinit with user credentials
134 ###########################################################
136 KRB5CCNAME_PATH
="$PREFIX/tmpuserccache"
137 KRB5CCNAME
="FILE:$KRB5CCNAME_PATH"
140 rm -f $KRB5CCNAME_PATH
142 cat > $PREFIX/tmpkinituserpassscript
<<EOF
147 testit
"kinit with user password" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit nettestuser@
$REALM || failed
=`expr $failed + 1`
148 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
152 NEWUSERPASS
="testPaSS@34%"
153 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`
155 cat > $PREFIX/tmpkinituserpassscript
<<EOF
157 send ${NEWUSERPASS}\n
160 testit
"kinit with new user password" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit nettestuser@
$REALM || failed
=`expr $failed + 1`
161 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
165 ###########################################################
166 ### Test kinit with user credentials in special formats
167 ###########################################################
169 testit
"kinit with new (NT-Principal style) using UPN" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit nettest@
$REALM || failed
=`expr $failed + 1`
170 test_smbclient
"Test login with user kerberos ccache from NT UPN" 'ls' -k yes || failed
=`expr $failed + 1`
174 testit
"kinit with new (enterprise style) using UPN" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit -E nettest@
$REALM || failed
=`expr $failed + 1`
175 test_smbclient
"Test login with user kerberos ccache from enterprise UPN" 'ls' -k yes || failed
=`expr $failed + 1`
179 ###########################################################
180 ### Test kinit with user credentials and changed realm
181 ###########################################################
183 cat > $PREFIX/tmpldbmodify
<<EOF
184 dn: cn=nettestuser,cn=users,$BASEDN
186 replace: userPrincipalName
187 userPrincipalName: nettest@$REALM.org
190 testit
"modify userPrincipalName to be a different domain" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify
$PREFIX/tmpldbmodify
-k yes $@ || failed
=`expr $failed + 1`
192 testit
"kinit with new (enterprise style) using UPN" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit -E nettest@
$REALM.org || failed
=`expr $failed + 1`
193 test_smbclient
"Test login with user kerberos ccache from enterprise UPN" 'ls' -k yes || failed
=`expr $failed + 1`
197 ###########################################################
198 ### Test password change with kpasswd
199 ###########################################################
201 testit
"kinit with user password" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit nettestuser@
$REALM || failed
=`expr $failed + 1`
202 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
204 USERPASS
=$NEWUSERPASS
205 NEWUSERPASS
=testPaSS@
56%
207 cat > $PREFIX/tmpkpasswdscript
<<EOF
209 password ${USERPASS}\n
210 expect Enter new password
211 send ${NEWUSERPASS}\n
212 expect Enter it again
213 send ${NEWUSERPASS}\n
214 expect Password changed
217 testit
"change user password with kpasswd" $samba_texpect $PREFIX/tmpkpasswdscript
$samba_kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
221 USERPASS
=$NEWUSERPASS
222 cat > $PREFIX/tmpkinituserpassscript
<<EOF
227 testit
"kinit with user password" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit nettestuser@
$REALM || failed
=`expr $failed + 1`
228 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
232 ###########################################################
233 ### TODO Test set password with kpasswd
234 ###########################################################
236 # This is not implemented in kpasswd
238 ###########################################################
239 ### Test password expiry
240 ###########################################################
242 cat > $PREFIX/tmpldbmodify
<<EOF
243 dn: cn=nettestuser,cn=users,$BASEDN
249 USERPASS
=$NEWUSERPASS
250 NEWUSERPASS
=testPaSS@
911%
252 testit
"modify pwdLastSet" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify
$PREFIX/tmpldbmodify
-k yes $@ || failed
=`expr $failed + 1`
254 cat > $PREFIX/tmpkinituserpassscript
<<EOF
257 expect Password expired. You must change it now.
258 expect Enter new password
259 send ${NEWUSERPASS}\n
260 expect Enter it again
261 send ${NEWUSERPASS}\n
264 testit
"kinit (MIT) with user password for expired password" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit nettestuser@
$REALM || failed
=`expr $failed + 1`
265 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
267 USERPASS
=$NEWUSERPASS
268 cat > $PREFIX/tmpkinituserpassscript
<<EOF
273 testit
"kinit with user password" $samba_texpect $PREFIX/tmpkinituserpassscript
$samba_kinit nettestuser@
$REALM || failed
=`expr $failed + 1`
274 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
276 ###########################################################
277 ### Test login with lowercase realm
278 ###########################################################
280 KRB5CCNAME_PATH
="$PREFIX/tmpccache"
281 KRB5CCNAME
="FILE:$KRB5CCNAME_PATH"
284 rm -rf $KRB5CCNAME_PATH
286 lowerrealm
=$
(echo $REALM |
tr '[A-Z]' '[a-z]')
287 test_smbclient
"Test login with user kerberos lowercase realm" 'ls' -k yes -Unettestuser@
$lowerrealm%$NEWUSERPASS || failed
=`expr $failed + 1`
288 test_smbclient
"Test login with user kerberos lowercase realm 2" 'ls' -k yes -Unettestuser@
$REALM%$NEWUSERPASS --realm=$lowerrealm || failed
=`expr $failed + 1`
290 testit
"del user with kerberos ccache" $VALGRIND $samba_tool user delete nettestuser
$CONFIGURATION -k yes $@ || failed
=`expr $failed + 1`
292 ###########################################################
293 ### Test login with machine account
294 ###########################################################
296 rm -f $KRB5CCNAME_PATH
297 testit
"kinit with machineaccountccache script" $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed
=`expr $failed + 1`
298 test_smbclient
"Test machine account login with kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
300 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`
306 rm -f $KRB5CCNAME_PATH
307 rm -f $PREFIX/tmpkinituserpassscript
308 rm -f $PREFIX/tmpkinitscript