2 # Blackbox tests for kinit and kerberos integration with smbclient etc
3 # Copyright (c) Andreas Schneider <asn@samba.org>
4 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
5 # Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
9 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX SMBCLIENT CONFIGURATION
25 .
"$(dirname "${0}")/subunit.sh"
26 .
"$(dirname "${0}")/common_test_fns.inc"
28 samba_bindir
="$BINDIR"
29 samba_srcdir
="$SRCDIR/source4"
30 samba_kinit
=$
(system_or_builddir_binary kinit
"${BINDIR}" samba4kinit
)
31 samba_kpasswd
=$
(system_or_builddir_binary kpasswd
"${BINDIR}" samba4kpasswd
)
32 samba_kvno
=$
(system_or_builddir_binary kvno
"${BINDIR}" samba4kvno
)
34 samba_tool
="${samba_bindir}/samba-tool"
35 samba_texpect
="${samba_bindir}/texpect"
37 samba_enableaccount
="${samba_tool} user enable"
38 machineaccountccache
="${samba_srcdir}/scripting/bin/machineaccountccache"
40 ldbmodify
=$
(system_or_builddir_binary ldbmodify
"${BINDIR}")
41 ldbsearch
=$
(system_or_builddir_binary ldbsearch
"${BINDIR}")
43 kbase
="$(basename "${samba_kinit}")"
44 if [ "${kbase}" = "samba4kinit" ]; then
46 OPTION_RENEWABLE
="--renewable"
47 OPTION_RENEW_TICKET
="--renew"
48 OPTION_ENTERPRISE_NAME
="--enterprise"
49 OPTION_CANONICALIZATION
=""
50 OPTION_WINDOWS
="--windows"
54 OPTION_RENEWABLE
="-r 1h"
55 OPTION_RENEW_TICKET
="-R"
56 OPTION_ENTERPRISE_NAME
="-E"
57 OPTION_CANONICALIZATION
="-C"
62 TEST_USER
="$(mktemp -u kinittest-XXXXXX)"
65 ADMIN_LDBMODIFY_CONFIG
="-H ldap://${SERVER} -U${USERNAME}%${PASSWORD}"
66 export ADMIN_LDBMODIFY_CONFIG
68 KRB5CCNAME_PATH
="${PREFIX}/tmpccache"
69 EXPLICIT_KRB5CCNAME
="FILE:${KRB5CCNAME_PATH}"
71 INVALID_KRB5CCNAME_PATH
="${KRB5CCNAME_PATH}.invalid"
72 INVALID_KRB5CCNAME
="FILE:${INVALID_KRB5CCNAME_PATH}"
73 rm -rf "${INVALID_KRB5CCNAME_PATH}"
75 KRB5CCNAME
=${EXPLICIT_KRB5CCNAME}
77 rm -rf "${KRB5CCNAME_PATH}"
79 testit
"reset password policies beside of minimum password age of 0 days" \
80 "${VALGRIND}" "${PYTHON}" "${samba_tool}" domain passwordsettings
set \
81 "${ADMIN_LDBMODIFY_CONFIG}" \
82 --complexity=default \
83 --history-length=default \
84 --min-pwd-length=default \
86 --max-pwd-age=default || \
87 failed
=$
((failed
+ 1))
89 ###########################################################
90 ### Test kinit defaults
91 ###########################################################
93 KRB5CCNAME
=${EXPLICIT_KRB5CCNAME}
95 rm -rf "${KRB5CCNAME_PATH}"
97 testit
"kinit with password (initial)" \
98 kerberos_kinit
"${samba_kinit}" "${USERNAME}@${REALM}" "${PASSWORD}" \
99 "${OPTION_RENEWABLE}" || \
100 failed
=$
((failed
+ 1))
102 KRB5CCNAME
=${INVALID_KRB5CCNAME}
105 test_smbclient
"Test login with user kerberos ccache" \
106 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
107 failed
=$
((failed
+ 1))
109 KRB5CCNAME
=${EXPLICIT_KRB5CCNAME}
112 testit
"kinit renew ticket (initial)" \
113 "${samba_kinit}" ${OPTION_RENEW_TICKET} || \
114 failed
=$
((failed
+ 1))
116 KRB5CCNAME
=${INVALID_KRB5CCNAME}
119 test_smbclient
"Test login with kerberos ccache (initial)" \
120 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
121 failed
=$
((failed
+ 1))
123 rm -f "${KRB5CCNAME_PATH}"
125 ###########################################################
126 ### Test kinit with enterprise principal
127 ###########################################################
129 KRB5CCNAME
=${EXPLICIT_KRB5CCNAME}
131 rm -rf "${KRB5CCNAME_PATH}"
133 testit
"kinit with password (enterprise style)" \
134 kerberos_kinit
"${samba_kinit}" \
135 "${USERNAME}@${REALM}" "${PASSWORD}" "${OPTION_ENTERPRISE_NAME}" \
136 "${OPTION_RENEWABLE}" || \
137 failed
=$
((failed
+ 1))
139 test_smbclient
"Test login with user kerberos ccache (enterprise style)" \
140 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
141 failed
=$
((failed
+ 1))
143 testit
"kinit renew ticket (enterprise style)" \
144 "${samba_kinit}" ${OPTION_RENEW_TICKET} || \
145 failed
=$
((failed
+ 1))
147 test_smbclient
"Test login with kerberos ccache (enterprise style)" \
148 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
149 failed
=$
((failed
+ 1))
151 rm -f "${KRB5CCNAME_PATH}"
153 ###########################################################
154 ### Tests with kinit windows
155 ###########################################################
158 if [ "${kbase}" = "samba4kinit" ]; then
159 testit
"kinit with password (windows style)" \
160 kerberos_kinit
"${samba_kinit}" \
161 "${USERNAME}@${REALM}" "${PASSWORD}" \
162 "${OPTION_RENEWABLE}" "${OPTION_WINDOWS}" || \
163 failed
=$
((failed
+ 1))
165 test_smbclient
"Test login with kerberos ccache (windows style)" \
166 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
167 failed
=$
((failed
+ 1))
169 testit
"kinit renew ticket (windows style)" \
170 "${samba_kinit}" ${OPTION_RENEW_TICKET} || \
171 failed
=$
((failed
+ 1))
173 test_smbclient
"Test login with kerberos ccache (windows style)" \
174 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
175 failed
=$
((failed
+ 1))
177 rm -f "${KRB5CCNAME_PATH}"
180 ###########################################################
181 ### Tests with kinit default again
182 ###########################################################
184 KRB5CCNAME
=${EXPLICIT_KRB5CCNAME}
186 rm -rf "${KRB5CCNAME_PATH}"
188 testit
"kinit with password (default)" \
189 kerberos_kinit
"${samba_kinit}" "${USERNAME}@${REALM}" "${PASSWORD}" || \
190 failed
=$
((failed
+ 1))
192 KRB5CCNAME
=${INVALID_KRB5CCNAME}
195 testit
"check time with kerberos ccache (default)" \
196 "${VALGRIND}" "${PYTHON}" "${samba_tool}" time "${SERVER}" \
197 "${CONFIGURATION}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" "$@" || \
198 failed
=$
((failed
+ 1))
200 USERPASS
="testPass@12%"
202 testit
"add user with kerberos ccache" \
203 "${VALGRIND}" "${PYTHON}" "${samba_tool}" user create \
204 "${TEST_USER}" "${USERPASS}" \
205 "${CONFIGURATION}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" "$@" || \
206 failed
=$
((failed
+ 1))
208 echo "Getting defaultNamingContext"
209 BASEDN
=$
(${ldbsearch} --basedn='' -H "ldap://${SERVER}" --scope=base \
210 DUMMY
=x defaultNamingContext |
awk '/defaultNamingContext/ {print $2}')
213 TEST_UPN
="$(mktemp -u test-XXXXXX)@${REALM}"
214 cat >"${PREFIX}/tmpldbmodify" <<EOF
215 dn: cn=${TEST_USER},cn=users,${BASEDN}
217 add: servicePrincipalName
218 servicePrincipalName: host/${TEST_USER}
219 replace: userPrincipalName
220 userPrincipalName: ${TEST_UPN}
223 testit
"modify servicePrincipalName and userPrincpalName" \
224 "${VALGRIND}" "${ldbmodify}" -H "ldap://${SERVER}" "${PREFIX}/tmpldbmodify" \
225 --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" "$@" || \
226 failed
=$
((failed
+ 1))
228 testit
"set user password with kerberos ccache" \
229 "${VALGRIND}" "${PYTHON}" "${samba_tool}" user setpassword "${TEST_USER}" \
230 --newpassword="${USERPASS}" "${CONFIGURATION}" \
231 --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" "$@" || \
232 failed
=$
((failed
+ 1))
234 testit
"enable user with kerberos cache" \
235 "${VALGRIND}" "${PYTHON}" "${samba_enableaccount}" "${TEST_USER}" \
236 -H "ldap://$SERVER" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" "$@" || \
237 failed
=$
((failed
+ 1))
239 KRB5CCNAME
=${EXPLICIT_KRB5CCNAME}
241 rm -rf "${KRB5CCNAME_PATH}"
243 testit
"kinit with new user password" \
244 kerberos_kinit
"${samba_kinit}" "${TEST_USER}" "${USERPASS}" || \
245 failed
=$
((failed
+ 1))
247 test_smbclient
"Test login with new user kerberos ccache" \
248 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
249 failed
=$
((failed
+ 1))
251 rm -f "${KRB5CCNAME_PATH}"
253 ###########################################################
254 ### Test kinit after changing password with samba-tool
255 ###########################################################
257 NEW_USERPASS
="testPaSS@34%"
258 testit
"change user password with 'samba-tool user password' (rpc)" \
259 "${VALGRIND}" "${PYTHON}" "${samba_tool}" user password \
260 -W"${DOMAIN}" -U"${TEST_USER}%${USERPASS}" "${CONFIGURATION}" \
261 --newpassword="${NEW_USERPASS}" \
262 --use-kerberos=off
"$@" || \
263 failed
=$
((failed
+ 1))
265 testit
"kinit with user password (after rpc password change)" \
266 kerberos_kinit
"${samba_kinit}" \
267 "${TEST_USER}@${REALM}" "${NEW_USERPASS}" || \
268 failed
=$
((failed
+ 1))
270 test_smbclient
"Test login with user kerberos (after rpc password change)" \
271 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
272 failed
=$
((failed
+ 1))
274 USERPASS
="${NEW_USERPASS}"
276 rm -f "${KRB5CCNAME_PATH}"
278 ###########################################################
279 ### Test kinit with UPN
280 ###########################################################
282 testit
"kinit with new (NT-Principal style) using UPN" \
283 kerberos_kinit
"${samba_kinit}" "${TEST_UPN}" "${USERPASS}" || \
284 failed
=$
((failed
+ 1))
286 test_smbclient
"Test login with user kerberos ccache from NT UPN" \
287 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
288 failed
=$
((failed
+ 1))
290 rm -f "${KRB5CCNAME_PATH}"
292 testit
"kinit with new (enterprise style) using UPN" \
293 kerberos_kinit
"${samba_kinit}" "${TEST_UPN}" "${USERPASS}" \
294 ${OPTION_ENTERPRISE_NAME} || \
295 failed
=$
((failed
+ 1))
297 test_smbclient
"Test login with user kerberos ccache from enterprise UPN" \
298 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
299 failed
=$
((failed
+ 1))
301 rm -f "${KRB5CCNAME_PATH}"
304 if [ "${kbase}" = "samba4kinit" ]; then
305 testit
"kinit with new (windows style) using UPN" \
306 kerberos_kinit
"${samba_kinit}" "${TEST_UPN}" "${USERPASS}" \
307 ${OPTION_WINDOWS} || \
308 failed
=$
((failed
+ 1))
310 test_smbclient
"Test login with user kerberos ccache with (windows style) UPN" \
311 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
312 failed
=$
((failed
+ 1))
314 rm -f "${KRB5CCNAME_PATH}"
317 ###########################################################
319 ###########################################################
321 DNSDOMAIN
=$
(echo "${REALM}" |
tr '[:upper:]' '[:lower:]')
322 testit
"kinit with password (SPN)" \
323 kerberos_kinit
"${samba_kinit}" \
324 "http/testupnspn.${DNSDOMAIN}" "${PASSWORD}" || \
325 failed
=$
((failed
+ 1))
327 test_smbclient
"Test login with kerberos ccache (SPN)" \
328 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
329 failed
=$
((failed
+ 1))
331 rm -f "${KRB5CCNAME_PATH}"
333 ###########################################################
334 ### Test kinit with canonicalization
335 ###########################################################
337 upperusername
=$
(echo "${USERNAME}" |
tr '[:lower:]' '[:upper:]')
338 testit
"kinit with canonicalize and service" \
339 kerberos_kinit
"${samba_kinit}" "${upperusername}@${REALM}" "${PASSWORD}" \
340 ${OPTION_CANONICALIZATION} \
341 ${OPTION_SERVICE} "kadmin/changepw@${REALM}" || \
342 failed
=$
((failed
+ 1))
344 rm -f "${KRB5CCNAME_PATH}"
346 ###########################################################
347 ### Test kinit with user credentials and changed realm
348 ###########################################################
350 testit
"kinit with password (default)" \
351 kerberos_kinit
"${samba_kinit}" "${USERNAME}@${REALM}" "${PASSWORD}" || \
352 failed
=$
((failed
+ 1))
354 cat >"${PREFIX}/tmpldbmodify" <<EOF
355 dn: cn=${TEST_USER},cn=users,$BASEDN
357 replace: userPrincipalName
358 userPrincipalName: ${TEST_UPN}.org
361 testit
"modify userPrincipalName to be a different domain" \
362 "${VALGRIND}" "${ldbmodify}" "${ADMIN_LDBMODIFY_CONFIG}" \
363 "${PREFIX}/tmpldbmodify" "${PREFIX}/tmpldbmodify" \
364 --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" "$@" || \
365 failed
=$
((failed
+ 1))
367 testit
"kinit with new (enterprise style) using UPN" \
368 kerberos_kinit
"${samba_kinit}" "${TEST_UPN}.org" "${USERPASS}" \
369 ${OPTION_ENTERPRISE_NAME} || failed
=$
((failed
+ 1))
371 test_smbclient
"Test login with user kerberos ccache from enterprise UPN" \
373 --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
374 failed
=$
((failed
+ 1))
376 rm -f "${KRB5CCNAME_PATH}"
378 ###########################################################
379 ### Test password change with kpasswd
380 ###########################################################
382 testit
"kinit with user password" \
383 kerberos_kinit
"${samba_kinit}" "${TEST_USER}@$REALM" "${USERPASS}" || \
384 failed
=$
((failed
+ 1))
386 test_smbclient
"Test login with user kerberos ccache" \
387 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
388 failed
=$
((failed
+ 1))
390 NEWUSERPASS
=testPaSS@
56%
392 if [ "${kbase}" = "samba4kinit" ]; then
394 cat >"${PREFIX}/tmpkpasswdscript" <<EOF
396 password ${USERPASS}\n
398 send ${NEWUSERPASS}\n
399 expect Verify password
400 send ${NEWUSERPASS}\n
406 cat >"${PREFIX}/tmpkpasswdscript" <<EOF
408 password ${USERPASS}\n
409 expect Enter new password
410 send ${NEWUSERPASS}\n
411 expect Enter it again
412 send ${NEWUSERPASS}\n
413 expect Password changed
417 testit
"change user password with kpasswd" \
418 "${samba_texpect}" "${PREFIX}/tmpkpasswdscript" \
419 "${samba_kpasswd}" "${TEST_USER}@$REALM" || \
420 failed
=$
((failed
+ 1))
422 rm -f "${KRB5CCNAME_PATH}"
424 USERPASS
="${NEWUSERPASS}"
426 testit
"kinit with user password (after kpasswd)" \
427 kerberos_kinit
"${samba_kinit}" \
428 "${TEST_USER}@${REALM}" "${USERPASS}" || \
429 failed
=$
((failed
+ 1))
431 test_smbclient
"Test login with user kerberos ccache (after kpasswd)" \
432 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
433 failed
=$
((failed
+ 1))
435 rm -f "${KRB5CCNAME_PATH}"
437 ###########################################################
438 ### TODO Test set password with kpasswd
439 ###########################################################
441 # This is not implemented in kpasswd
443 ###########################################################
444 ### Test password expiry
445 ###########################################################
447 cat >"${PREFIX}/tmpldbmodify" <<EOF
448 dn: cn=${TEST_USER},cn=users,${BASEDN}
454 NEWUSERPASS
=testPaSS@
78%
456 testit
"modify pwdLastSet" \
457 "${VALGRIND}" "${ldbmodify}" "${ADMIN_LDBMODIFY_CONFIG}" \
458 "${PREFIX}/tmpldbmodify" "${PREFIX}/tmpldbmodify" \
459 --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" "$@" || \
460 failed
=$
((failed
+ 1))
462 if [ "${kbase}" = "samba4kinit" ]; then
464 cat >"${PREFIX}/tmpkinituserpassscript" <<EOF
465 expect ${TEST_USER}@$REALM's Password
467 expect Password has expired
469 send ${NEWUSERPASS}\n
470 expect Repeat new password
471 send ${NEWUSERPASS}\n
475 cat >"${PREFIX}/tmpkinituserpassscript" <<EOF
478 expect Password expired. You must change it now.
479 expect Enter new password
480 send ${NEWUSERPASS}\n
481 expect Enter it again
482 send ${NEWUSERPASS}\n
487 testit
"kinit with user password for expired password" \
488 "${samba_texpect}" "$PREFIX/tmpkinituserpassscript" \
489 "${samba_kinit}" "${TEST_USER}@$REALM" || \
490 failed
=$
((failed
+ 1))
492 test_smbclient
"Test login with user kerberos ccache" \
493 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
494 failed
=$
((failed
+ 1))
496 USERPASS
="${NEWUSERPASS}"
498 testit
"kinit with user password" \
499 kerberos_kinit
"${samba_kinit}" \
500 "${TEST_USER}@${REALM}" "${USERPASS}" || \
501 failed
=$
((failed
+ 1))
503 test_smbclient
"Test login with user kerberos ccache" \
504 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
505 failed
=$
((failed
+ 1))
507 ###########################################################
508 ### Test login with lowercase realm
509 ###########################################################
511 KRB5CCNAME
="${EXPLICIT_KRB5CCNAME}"
514 rm -rf "${KRB5CCNAME_PATH}"
516 testit
"kinit with user password" \
517 kerberos_kinit
"${samba_kinit}" "${TEST_USER}@${REALM}" "${USERPASS}" || \
518 failed
=$
((failed
+ 1))
520 lowerrealm
=$
(echo "${REALM}" |
tr '[:upper:]' '[:lower:]')
521 test_smbclient
"Test login with user kerberos lowercase realm" \
522 "ls" "${UNC}" --use-kerberos=required \
523 -U"${TEST_USER}@${lowerrealm}%${NEWUSERPASS}" || \
524 failed
=$
((failed
+ 1))
526 test_smbclient
"Test login with user kerberos lowercase realm 2" \
527 "ls" "${UNC}" --use-kerberos=required \
528 -U"${TEST_USER}@${REALM}%${NEWUSERPASS}" --realm="${lowerrealm}" || \
529 failed
=$
((failed
+ 1))
531 testit
"del user with kerberos ccache" \
532 "${VALGRIND}" "${PYTHON}" "${samba_tool}" user delete \
533 "${TEST_USER}" "${CONFIGURATION}" \
534 --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" "$@" || \
535 failed
=$
((failed
+ 1))
537 ###########################################################
538 ### Test login with machine account
539 ###########################################################
541 rm -f "${KRB5CCNAME_PATH}"
543 testit
"kinit with machineaccountccache script" \
544 "${PYTHON}" "${machineaccountccache}" "${CONFIGURATION}" \
545 "${EXPLICIT_KRB5CCNAME}" || \
546 failed
=$
((failed
+ 1))
548 test_smbclient
"Test machine account login with kerberos ccache" \
549 "ls" "${UNC}" --use-krb5-ccache="${EXPLICIT_KRB5CCNAME}" || \
550 failed
=$
((failed
+ 1))
552 testit
"reset password policies" \
553 "${VALGRIND}" "${PYTHON}" "${samba_tool}" domain passwordsettings
set \
554 "${ADMIN_LDBMODIFY_CONFIG}" \
555 --complexity=default \
556 --history-length=default \
557 --min-pwd-length=default \
558 --min-pwd-age=default \
559 --max-pwd-age=default || \
560 failed
=$
((failed
+ 1))
562 ###########################################################
563 ### Test basic s4u2self request
564 ###########################################################
567 if [ "${kbase}" = "kinit" ]; then
569 # Use previous acquired machine creds to request a ticket for self.
570 # We expect it to fail for now.
571 MACHINE_ACCOUNT
="$(hostname -s | tr '[:lower:]' '[:upper:]')\$@${REALM}"
573 ${samba_kvno} -U"${MACHINE_ACCOUNT}" "${MACHINE_ACCOUNT}"
575 # But we expect the KDC to be up and running still
576 testit "kinit with machineaccountccache after s4u2self
" \
577 "${machineaccountccache}" "${CONFIGURATION}" "${EXPLICIT_KRB5CCNAME}" || \
578 failed=$((failed + 1))
582 testit_expect_failure \
583 "Check INVALID_KRB5CCNAME_PATH
[${INVALID_KRB5CCNAME_PATH}] was not created
" \
584 test -e "${INVALID_KRB5CCNAME_PATH}" || \
585 failed=$((failed + 1))
589 rm -f "${KRB5CCNAME_PATH}"
590 rm -f "${PREFIX}/tmpkinituserpassscript
"
591 rm -f "${PREFIX}/tmpkinitscript
"
592 rm -f "${PREFIX}/tmpkpasswdscript
"