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>
8 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX ENCTYPE SMBCLIENT
24 samba4bindir
="$BINDIR"
25 samba4srcdir
="$SRCDIR/source4"
27 if test -x $BINDIR/samba4kinit
; then
28 samba4kinit
=$BINDIR/samba4kinit
31 samba_tool
="$samba4bindir/samba-tool"
32 texpect
="$samba4bindir/texpect"
34 if test -x $BINDIR/samba4kpasswd
; then
35 samba4kpasswd
=$BINDIR/samba4kpasswd
38 enableaccount
="$samba_tool user enable"
39 machineaccountccache
="$samba4srcdir/scripting/bin/machineaccountccache"
42 if [ -x "$samba4bindir/ldbmodify" ]; then
43 ldbmodify
="$samba4bindir/ldbmodify"
47 if [ -x "$samba4bindir/ldbsearch" ]; then
48 ldbsearch
="$samba4bindir/ldbsearch"
51 .
`dirname $0`/subunit.sh
59 $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp
-c "$cmd" $@
61 if [ x
$status = x0
]; then
71 ADMIN_LDBMODIFY_CONFIG
="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
72 export ADMIN_LDBMODIFY_CONFIG
74 KRB5CCNAME_PATH
="$PREFIX/tmpccache"
75 KRB5CCNAME
="FILE:$KRB5CCNAME_PATH"
76 ADMIN_KRB5CCNAME
="FILE:$KRB5CCNAME_PATH"
78 rm -rf $KRB5CCNAME_PATH
80 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`
82 echo $PASSWORD > $PREFIX/tmppassfile
83 #testit "kinit with keytab" $samba4kinit $enctype --keytab=$PREFIX/dc/private/secrets.keytab $SERVER\$@$REALM || failed=`expr $failed + 1`
84 testit
"kinit with password" $samba4kinit $enctype --password-file=$PREFIX/tmppassfile
--request-pac $USERNAME@
$REALM || failed
=`expr $failed + 1`
85 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
87 testit
"kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmppassfile
--request-pac $USERNAME@
$REALM || failed
=`expr $failed + 1`
88 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
90 testit
"kinit with password (windows style)" $samba4kinit $enctype --renewable --windows --password-file=$PREFIX/tmppassfile
--request-pac $USERNAME@
$REALM || failed
=`expr $failed + 1`
91 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
93 testit
"kinit renew ticket" $samba4kinit $enctype --request-pac -R
95 test_smbclient
"Test login with kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
97 testit
"check time with kerberos ccache" $VALGRIND $samba_tool time $SERVER $CONFIGURATION -k yes $@ || failed
=`expr $failed + 1`
100 echo $USERPASS > $PREFIX/tmpuserpassfile
101 testit
"add user with kerberos ccache" $VALGRIND $samba_tool user create nettestuser
$USERPASS $CONFIGURATION -k yes $@ || failed
=`expr $failed + 1`
103 echo "Getting defaultNamingContext"
104 BASEDN
=`$ldbsearch $options --basedn='' -H ldap://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
106 cat > $PREFIX/tmpldbmodify
<<EOF
107 dn: cn=nettestuser,cn=users,$BASEDN
109 add: servicePrincipalName
110 servicePrincipalName: host/nettestuser
111 replace: userPrincipalName
112 userPrincipalName: nettest@$REALM
115 testit
"modify servicePrincipalName and userPrincpalName" $VALGRIND $ldbmodify -H ldap
://$SERVER $PREFIX/tmpldbmodify
-k yes $@ || failed
=`expr $failed + 1`
117 testit
"set user password with kerberos ccache" $VALGRIND $samba_tool user setpassword nettestuser
--newpassword=$USERPASS $CONFIGURATION -k yes $@ || failed
=`expr $failed + 1`
119 testit
"enable user with kerberos cache" $VALGRIND $enableaccount nettestuser
-H ldap
://$SERVER -k yes $@ || failed
=`expr $failed + 1`
121 KRB5CCNAME_PATH
="$PREFIX/tmpuserccache"
122 KRB5CCNAME
="FILE:$KRB5CCNAME_PATH"
125 rm -f $KRB5CCNAME_PATH
126 testit
"kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile
--request-pac nettestuser@
$REALM || failed
=`expr $failed + 1`
128 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
130 NEWUSERPASS
=testPaSS@
34%
131 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`
133 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
134 rm -f $KRB5CCNAME_PATH
135 testit
"kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile
--request-pac nettestuser@
$REALM || failed
=`expr $failed + 1`
137 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
140 rm -f $KRB5CCNAME_PATH
141 testit
"kinit with password (NT-Principal style) using UPN" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile
--request-pac nettest@
$REALM || failed
=`expr $failed + 1`
142 test_smbclient
"Test login with user kerberos ccache from enterprise UPN" 'ls' -k yes || failed
=`expr $failed + 1`
144 rm -f $KRB5CCNAME_PATH
145 testit
"kinit with password (enterprise style) using UPN" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmpuserpassfile
--request-pac nettest@
$REALM || failed
=`expr $failed + 1`
146 test_smbclient
"Test login with user kerberos ccache from enterprise UPN" 'ls' -k yes || failed
=`expr $failed + 1`
148 rm -f $KRB5CCNAME_PATH
149 testit
"kinit with password (windows style) using UPN" $samba4kinit $enctype --renewable --windows --password-file=$PREFIX/tmpuserpassfile
--request-pac nettest@
$REALM || failed
=`expr $failed + 1`
150 test_smbclient
"Test login with user kerberos ccache from windows UPN" 'ls' -k yes || failed
=`expr $failed + 1`
152 cat > $PREFIX/tmpldbmodify
<<EOF
153 dn: cn=nettestuser,cn=users,$BASEDN
155 replace: userPrincipalName
156 userPrincipalName: nettest@$REALM.org
159 testit
"modify userPrincipalName to be a different domain" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify
$PREFIX/tmpldbmodify
-k yes $@ || failed
=`expr $failed + 1`
161 rm -f $KRB5CCNAME_PATH
162 testit
"kinit with password (enterprise style) using UPN" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmpuserpassfile
--request-pac nettest@
$REALM.org || failed
=`expr $failed + 1`
163 test_smbclient
"Test login with user kerberos ccache from enterprise UPN, different domain" 'ls' -k yes || failed
=`expr $failed + 1`
166 USERPASS
=$NEWUSERPASS
167 NEWUSERPASS
=testPaSS@
56%
168 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
170 cat > $PREFIX/tmpkpasswdscript
<<EOF
172 password ${USERPASS}\n
174 send ${NEWUSERPASS}\n
175 expect Verify password
176 send ${NEWUSERPASS}\n
180 testit
"change user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
182 rm -f $KRB5CCNAME_PATH
183 testit
"kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile
--request-pac nettestuser@
$REALM || failed
=`expr $failed + 1`
185 NEWUSERPASS
=testPaSS@
78%
186 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
188 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
190 cat > $PREFIX/tmpkpasswdscript
<<EOF
192 send ${NEWUSERPASS}\n
193 expect Verify password
194 send ${NEWUSERPASS}\n
198 testit
"set user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript
$samba4kpasswd --cache=$ADMIN_KRB5CCNAME nettestuser@
$REALM || failed
=`expr $failed + 1`
200 rm -f $KRB5CCNAME_PATH
201 testit
"kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile
--request-pac nettestuser@
$REALM || failed
=`expr $failed + 1`
203 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
205 NEWUSERPASS
=testPaSS@
910%
206 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
208 cat > $PREFIX/tmpkpasswdscript
<<EOF
210 send ${NEWUSERPASS}\n
211 expect Verify password
212 send ${NEWUSERPASS}\n
216 testit
"set user password with kpasswd and servicePrincipalName" $texpect $PREFIX/tmpkpasswdscript
$samba4kpasswd --cache=$PREFIX/tmpccache host
/nettestuser@
$REALM || failed
=`expr $failed + 1`
218 testit
"kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile
--request-pac nettestuser@
$REALM || failed
=`expr $failed + 1`
220 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
222 cat > $PREFIX/tmpldbmodify
<<EOF
223 dn: cn=nettestuser,cn=users,$BASEDN
229 USERPASS
=$NEWUSERPASS
230 NEWUSERPASS
=testPaSS@
911%
232 testit
"modify pwdLastSet" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify
$PREFIX/tmpldbmodify
-k yes $@ || failed
=`expr $failed + 1`
234 cat > $PREFIX/tmppasswordchange
<<EOF
235 expect nettestuser@${REALM}'s Password:
237 expect Your password will expire at
238 expect Changing password
240 send ${NEWUSERPASS}\n
241 expect Repeat new password:
242 send ${NEWUSERPASS}\n
243 expect Success: Password changed
246 testit
"kinit with user password for expired password" $texpect $PREFIX/tmppasswordchange
$samba4kinit $enctype --request-pac nettestuser@
$REALM && failed
=`expr $failed + 1`
248 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
250 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
251 testit
"kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile
--request-pac nettestuser@
$REALM || failed
=`expr $failed + 1`
253 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
255 KRB5CCNAME_PATH
="$PREFIX/tmpccache"
256 KRB5CCNAME
="FILE:$KRB5CCNAME_PATH"
259 rm -rf $KRB5CCNAME_PATH
261 lowerrealm
=$
(echo $REALM |
tr '[A-Z]' '[a-z]')
262 test_smbclient
"Test login with user kerberos lowercase realm" 'ls' -k yes -Unettestuser@
$lowerrealm%$NEWUSERPASS || failed
=`expr $failed + 1`
263 test_smbclient
"Test login with user kerberos lowercase realm 2" 'ls' -k yes -Unettestuser@
$REALM%$NEWUSERPASS --realm=$lowerrealm || failed
=`expr $failed + 1`
265 testit
"del user with kerberos ccache" $VALGRIND $samba_tool user delete nettestuser
$CONFIGURATION -k yes $@ || failed
=`expr $failed + 1`
267 rm -f $KRB5CCNAME_PATH
268 testit
"kinit with machineaccountccache script" $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed
=`expr $failed + 1`
269 test_smbclient
"Test machine account login with kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
271 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`
273 rm -f $PREFIX/tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript