lib/util: add debug_set_forced_log_priority()
[Samba.git] / testprogs / blackbox / test_kinit.sh
blob80188e8f852b4bd74518e358c67cf74d01b8899b
1 #!/bin/sh
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>
7 if [ $# -lt 8 ]; then
8 cat <<EOF
9 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX SMBCLIENT CONFIGURATION
10 EOF
11 exit 1
14 SERVER=$1
15 USERNAME=$2
16 PASSWORD=$3
17 REALM=$4
18 DOMAIN=$5
19 PREFIX=$6
20 smbclient=$7
21 CONFIGURATION="${8}"
22 shift 8
23 failed=0
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
45 # HEIMDAL
46 OPTION_RENEWABLE="--renewable"
47 OPTION_RENEW_TICKET="--renew"
48 OPTION_ENTERPRISE_NAME="--enterprise"
49 OPTION_CANONICALIZATION=""
50 OPTION_WINDOWS="--windows"
51 OPTION_SERVICE="-S"
52 else
53 # MIT
54 OPTION_RENEWABLE="-r 1h"
55 OPTION_RENEW_TICKET="-R"
56 OPTION_ENTERPRISE_NAME="-E"
57 OPTION_CANONICALIZATION="-C"
58 OPTION_WINDOWS=""
59 OPTION_SERVICE="-S"
62 TEST_USER="$(mktemp -u kinittest-XXXXXX)"
63 UNC="//${SERVER}/tmp"
65 ADMIN_LDBMODIFY_CONFIG="-H ldap://${SERVER} -U${USERNAME}%${PASSWORD}"
66 export ADMIN_LDBMODIFY_CONFIG
68 KRB5CCNAME_PATH="${PREFIX}/tmpccache"
69 KRB5CCNAME="FILE:${KRB5CCNAME_PATH}"
70 export KRB5CCNAME
71 rm -rf "${KRB5CCNAME_PATH}"
73 testit "reset password policies beside of minimum password age of 0 days" \
74 "${VALGRIND}" "${PYTHON}" "${samba_tool}" domain passwordsettings set \
75 "${ADMIN_LDBMODIFY_CONFIG}" \
76 --complexity=default \
77 --history-length=default \
78 --min-pwd-length=default \
79 --min-pwd-age=0 \
80 --max-pwd-age=default || \
81 failed=$((failed + 1))
83 ###########################################################
84 ### Test kinit defaults
85 ###########################################################
87 testit "kinit with password (initial)" \
88 kerberos_kinit "${samba_kinit}" "${USERNAME}@${REALM}" "${PASSWORD}" \
89 "${OPTION_RENEWABLE}" || \
90 failed=$((failed + 1))
91 test_smbclient "Test login with user kerberos ccache" \
92 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
93 failed=$((failed + 1))
95 testit "kinit renew ticket (initial)" \
96 "${samba_kinit}" ${OPTION_RENEW_TICKET} || \
97 failed=$((failed + 1))
99 test_smbclient "Test login with kerberos ccache (initial)" \
100 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
101 failed=$((failed + 1))
103 rm -f "${KRB5CCNAME_PATH}"
105 ###########################################################
106 ### Test kinit with enterprice principal
107 ###########################################################
109 testit "kinit with password (enterprise style)" \
110 kerberos_kinit "${samba_kinit}" \
111 "${USERNAME}@${REALM}" "${PASSWORD}" "${OPTION_ENTERPRISE_NAME}" \
112 "${OPTION_RENEWABLE}" || \
113 failed=$((failed + 1))
115 test_smbclient "Test login with user kerberos ccache (enterprise style)" \
116 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
117 failed=$((failed + 1))
119 testit "kinit renew ticket (enterprise style)" \
120 "${samba_kinit}" ${OPTION_RENEW_TICKET} || \
121 failed=$((failed + 1))
123 test_smbclient "Test login with kerberos ccache (enterprise style)" \
124 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
125 failed=$((failed + 1))
127 rm -f "${KRB5CCNAME_PATH}"
129 ###########################################################
130 ### Tests with kinit windows
131 ###########################################################
133 # HEIMDAL ONLY
134 if [ "${kbase}" = "samba4kinit" ]; then
135 testit "kinit with password (windows style)" \
136 kerberos_kinit "${samba_kinit}" \
137 "${USERNAME}@${REALM}" "${PASSWORD}" \
138 "${OPTION_RENEWABLE}" "${OPTION_WINDOWS}" || \
139 failed=$((failed + 1))
141 test_smbclient "Test login with kerberos ccache (windows style)" \
142 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
143 failed=$((failed + 1))
145 testit "kinit renew ticket (windows style)" \
146 "${samba_kinit}" ${OPTION_RENEW_TICKET} || \
147 failed=$((failed + 1))
149 test_smbclient "Test login with kerberos ccache (windows style)" \
150 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
151 failed=$((failed + 1))
153 rm -f "${KRB5CCNAME_PATH}"
154 fi # HEIMDAL ONLY
156 ###########################################################
157 ### Tests with kinit default again
158 ###########################################################
160 testit "kinit with password (default)" \
161 kerberos_kinit "${samba_kinit}" "${USERNAME}@${REALM}" "${PASSWORD}" || \
162 failed=$((failed + 1))
164 testit "check time with kerberos ccache (default)" \
165 "${VALGRIND}" "${PYTHON}" "${samba_tool}" time "${SERVER}" \
166 "${CONFIGURATION}" --use-krb5-ccache="${KRB5CCNAME}" "$@" || \
167 failed=$((failed + 1))
169 USERPASS="testPass@12%"
171 testit "add user with kerberos ccache" \
172 "${VALGRIND}" "${PYTHON}" "${samba_tool}" user create \
173 "${TEST_USER}" "${USERPASS}" \
174 "${CONFIGURATION}" --use-krb5-ccache="${KRB5CCNAME}" "$@" || \
175 failed=$((failed + 1))
177 echo "Getting defaultNamingContext"
178 BASEDN=$(${ldbsearch} --basedn='' -H "ldap://${SERVER}" --scope=base \
179 DUMMY=x defaultNamingContext | awk '/defaultNamingContext/ {print $2}')
182 TEST_UPN="$(mktemp -u test-XXXXXX)@${REALM}"
183 cat >"${PREFIX}/tmpldbmodify" <<EOF
184 dn: cn=${TEST_USER},cn=users,${BASEDN}
185 changetype: modify
186 add: servicePrincipalName
187 servicePrincipalName: host/${TEST_USER}
188 replace: userPrincipalName
189 userPrincipalName: ${TEST_UPN}
192 testit "modify servicePrincipalName and userPrincpalName" \
193 "${VALGRIND}" "${ldbmodify}" -H "ldap://${SERVER}" "${PREFIX}/tmpldbmodify" \
194 --use-krb5-ccache="${KRB5CCNAME}" "$@" || \
195 failed=$((failed + 1))
197 testit "set user password with kerberos ccache" \
198 "${VALGRIND}" "${PYTHON}" "${samba_tool}" user setpassword "${TEST_USER}" \
199 --newpassword="${USERPASS}" "${CONFIGURATION}" \
200 --use-krb5-ccache="${KRB5CCNAME}" "$@" || \
201 failed=$((failed + 1))
203 testit "enable user with kerberos cache" \
204 "${VALGRIND}" "${PYTHON}" "${samba_enableaccount}" "${TEST_USER}" \
205 -H "ldap://$SERVER" --use-krb5-ccache="${KRB5CCNAME}" "$@" || \
206 failed=$((failed + 1))
208 testit "kinit with new user password" \
209 kerberos_kinit "${samba_kinit}" "${TEST_USER}" "${USERPASS}" || \
210 failed=$((failed + 1))
212 test_smbclient "Test login with new user kerberos ccache" \
213 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
214 failed=$((failed + 1))
216 rm -f "${KRB5CCNAME_PATH}"
218 ###########################################################
219 ### Test kinit fter changing password with samba-tool
220 ###########################################################
222 NEW_USERPASS="testPaSS@34%"
223 testit "change user password with 'samba-tool user password' (rpc)" \
224 "${VALGRIND}" "${PYTHON}" "${samba_tool}" user password \
225 -W"${DOMAIN}" -U"${TEST_USER}%${USERPASS}" "${CONFIGURATION}" \
226 --newpassword="${NEW_USERPASS}" \
227 --use-kerberos=off "$@" || \
228 failed=$((failed + 1))
230 testit "kinit with user password (after rpc password change)" \
231 kerberos_kinit "${samba_kinit}" \
232 "${TEST_USER}@${REALM}" "${NEW_USERPASS}" || \
233 failed=$((failed + 1))
235 test_smbclient "Test login with user kerberos (after rpc password change)" \
236 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
237 failed=$((failed + 1))
239 USERPASS="${NEW_USERPASS}"
241 rm -f "${KRB5CCNAME_PATH}"
243 ###########################################################
244 ### Test kinit with UPN
245 ###########################################################
247 testit "kinit with new (NT-Principal style) using UPN" \
248 kerberos_kinit "${samba_kinit}" "${TEST_UPN}" "${USERPASS}" || \
249 failed=$((failed + 1))
251 test_smbclient "Test login with user kerberos ccache from NT UPN" \
252 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
253 failed=$((failed + 1))
255 rm -f "${KRB5CCNAME_PATH}"
257 testit "kinit with new (enterprise style) using UPN" \
258 kerberos_kinit "${samba_kinit}" "${TEST_UPN}" "${USERPASS}" \
259 ${OPTION_ENTERPRISE_NAME} || \
260 failed=$((failed + 1))
262 test_smbclient "Test login with user kerberos ccache from enterprise UPN" \
263 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
264 failed=$((failed + 1))
266 rm -f "${KRB5CCNAME_PATH}"
268 # HEIMDAL ONLY
269 if [ "${kbase}" = "samba4kinit" ]; then
270 testit "kinit with new (windows style) using UPN" \
271 kerberos_kinit "${samba_kinit}" "${TEST_UPN}" "${USERPASS}" \
272 ${OPTION_WINDOWS} || \
273 failed=$((failed + 1))
275 test_smbclient "Test login with user kerberos ccache with (windows style) UPN" \
276 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
277 failed=$((failed + 1))
279 rm -f "${KRB5CCNAME_PATH}"
280 fi # HEIMDAL ONLY
282 ###########################################################
283 ### Tests with SPN
284 ###########################################################
286 DNSDOMAIN=$(echo "${REALM}" | tr '[:upper:]' '[:lower:]')
287 testit "kinit with password (SPN)" \
288 kerberos_kinit "${samba_kinit}" \
289 "http/testupnspn.${DNSDOMAIN}" "${PASSWORD}" || \
290 failed=$((failed + 1))
292 test_smbclient "Test login with kerberos ccache (SPN)" \
293 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
294 failed=$((failed + 1))
296 rm -f "${KRB5CCNAME_PATH}"
298 ###########################################################
299 ### Test kinit with canonicalization
300 ###########################################################
302 upperusername=$(echo "${USERNAME}" | tr '[:lower:]' '[:upper:]')
303 testit "kinit with canonicalize and service" \
304 kerberos_kinit "${samba_kinit}" "${upperusername}@${REALM}" "${PASSWORD}" \
305 ${OPTION_CANONICALIZATION} \
306 ${OPTION_SERVICE} "kadmin/changepw@${REALM}" || \
307 failed=$((failed + 1))
309 rm -f "${KRB5CCNAME_PATH}"
311 ###########################################################
312 ### Test kinit with user credentials and changed realm
313 ###########################################################
315 testit "kinit with password (default)" \
316 kerberos_kinit "${samba_kinit}" "${USERNAME}@${REALM}" "${PASSWORD}" || \
317 failed=$((failed + 1))
319 cat >"${PREFIX}/tmpldbmodify" <<EOF
320 dn: cn=${TEST_USER},cn=users,$BASEDN
321 changetype: modify
322 replace: userPrincipalName
323 userPrincipalName: ${TEST_UPN}.org
326 testit "modify userPrincipalName to be a different domain" \
327 "${VALGRIND}" "${ldbmodify}" "${ADMIN_LDBMODIFY_CONFIG}" \
328 "${PREFIX}/tmpldbmodify" "${PREFIX}/tmpldbmodify" \
329 --use-krb5-ccache="${KRB5CCNAME}" "$@" || \
330 failed=$((failed + 1))
332 testit "kinit with new (enterprise style) using UPN" \
333 kerberos_kinit "${samba_kinit}" "${TEST_UPN}.org" "${USERPASS}" \
334 ${OPTION_ENTERPRISE_NAME} || failed=$((failed + 1))
336 test_smbclient "Test login with user kerberos ccache from enterprise UPN" \
337 "ls" "${UNC}" \
338 --use-krb5-ccache="${KRB5CCNAME}" || \
339 failed=$((failed + 1))
341 rm -f "${KRB5CCNAME_PATH}"
343 ###########################################################
344 ### Test password change with kpasswd
345 ###########################################################
347 testit "kinit with user password" \
348 kerberos_kinit "${samba_kinit}" "${TEST_USER}@$REALM" "${USERPASS}" || \
349 failed=$((failed + 1))
351 test_smbclient "Test login with user kerberos ccache" \
352 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
353 failed=$((failed + 1))
355 NEWUSERPASS=testPaSS@56%
357 if [ "${kbase}" = "samba4kinit" ]; then
358 # HEIMDAL
359 cat >"${PREFIX}/tmpkpasswdscript" <<EOF
360 expect Password
361 password ${USERPASS}\n
362 expect New password
363 send ${NEWUSERPASS}\n
364 expect Verify password
365 send ${NEWUSERPASS}\n
366 expect Success
369 else
370 # MIT
371 cat >"${PREFIX}/tmpkpasswdscript" <<EOF
372 expect Password for
373 password ${USERPASS}\n
374 expect Enter new password
375 send ${NEWUSERPASS}\n
376 expect Enter it again
377 send ${NEWUSERPASS}\n
378 expect Password changed
382 testit "change user password with kpasswd" \
383 "${samba_texpect}" "${PREFIX}/tmpkpasswdscript" \
384 "${samba_kpasswd}" "${TEST_USER}@$REALM" || \
385 failed=$((failed + 1))
387 rm -f "${KRB5CCNAME_PATH}"
389 USERPASS="${NEWUSERPASS}"
391 testit "kinit with user password (after kpasswd)" \
392 kerberos_kinit "${samba_kinit}" \
393 "${TEST_USER}@${REALM}" "${USERPASS}" || \
394 failed=$((failed + 1))
396 test_smbclient "Test login with user kerberos ccache (after kpasswd)" \
397 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
398 failed=$((failed + 1))
400 rm -f "${KRB5CCNAME_PATH}"
402 ###########################################################
403 ### TODO Test set password with kpasswd
404 ###########################################################
406 # This is not implemented in kpasswd
408 ###########################################################
409 ### Test password expiry
410 ###########################################################
412 cat >"${PREFIX}/tmpldbmodify" <<EOF
413 dn: cn=${TEST_USER},cn=users,${BASEDN}
414 changetype: modify
415 replace: pwdLastSet
416 pwdLastSet: 0
419 NEWUSERPASS=testPaSS@78%
421 testit "modify pwdLastSet" \
422 "${VALGRIND}" "${ldbmodify}" "${ADMIN_LDBMODIFY_CONFIG}" \
423 "${PREFIX}/tmpldbmodify" "${PREFIX}/tmpldbmodify" \
424 --use-krb5-ccache="${KRB5CCNAME}" "$@" || \
425 failed=$((failed + 1))
427 if [ "${kbase}" = "samba4kinit" ]; then
428 # HEIMDAL branch
429 cat >"${PREFIX}/tmpkinituserpassscript" <<EOF
430 expect ${TEST_USER}@$REALM's Password
431 send ${USERPASS}\n
432 expect Password has expired
433 expect New password
434 send ${NEWUSERPASS}\n
435 expect Repeat new password
436 send ${NEWUSERPASS}\n
438 else
439 # MIT branch
440 cat >"${PREFIX}/tmpkinituserpassscript" <<EOF
441 expect Password for
442 send ${USERPASS}\n
443 expect Password expired. You must change it now.
444 expect Enter new password
445 send ${NEWUSERPASS}\n
446 expect Enter it again
447 send ${NEWUSERPASS}\n
450 fi # END MIT ONLY
452 testit "kinit with user password for expired password" \
453 "${samba_texpect}" "$PREFIX/tmpkinituserpassscript" \
454 "${samba_kinit}" "${TEST_USER}@$REALM" || \
455 failed=$((failed + 1))
457 test_smbclient "Test login with user kerberos ccache" \
458 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
459 failed=$((failed + 1))
461 USERPASS="${NEWUSERPASS}"
463 testit "kinit with user password" \
464 kerberos_kinit "${samba_kinit}" \
465 "${TEST_USER}@${REALM}" "${USERPASS}" || \
466 failed=$((failed + 1))
468 test_smbclient "Test login with user kerberos ccache" \
469 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
470 failed=$((failed + 1))
472 ###########################################################
473 ### Test login with lowercase realm
474 ###########################################################
476 KRB5CCNAME_PATH="$PREFIX/tmpccache"
477 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
478 export KRB5CCNAME
480 rm -rf "${KRB5CCNAME_PATH}"
482 testit "kinit with user password" \
483 kerberos_kinit "${samba_kinit}" "${TEST_USER}@${REALM}" "${USERPASS}" || \
484 failed=$((failed + 1))
486 lowerrealm=$(echo "${REALM}" | tr '[:upper:]' '[:lower:]')
487 test_smbclient "Test login with user kerberos lowercase realm" \
488 "ls" "${UNC}" --use-kerberos=required \
489 -U"${TEST_USER}@${lowerrealm}%${NEWUSERPASS}" || \
490 failed=$((failed + 1))
492 test_smbclient "Test login with user kerberos lowercase realm 2" \
493 "ls" "${UNC}" --use-kerberos=required \
494 -U"${TEST_USER}@${REALM}%${NEWUSERPASS}" --realm="${lowerrealm}" || \
495 failed=$((failed + 1))
497 testit "del user with kerberos ccache" \
498 "${VALGRIND}" "${PYTHON}" "${samba_tool}" user delete \
499 "${TEST_USER}" "${CONFIGURATION}" \
500 --use-krb5-ccache="${KRB5CCNAME}" "$@" || \
501 failed=$((failed + 1))
503 ###########################################################
504 ### Test login with machine account
505 ###########################################################
507 rm -f "${KRB5CCNAME_PATH}"
509 testit "kinit with machineaccountccache script" \
510 "${PYTHON}" "${machineaccountccache}" "${CONFIGURATION}" \
511 "${KRB5CCNAME}" || \
512 failed=$((failed + 1))
514 test_smbclient "Test machine account login with kerberos ccache" \
515 "ls" "${UNC}" --use-krb5-ccache="${KRB5CCNAME}" || \
516 failed=$((failed + 1))
518 testit "reset password policies" \
519 "${VALGRIND}" "${PYTHON}" "${samba_tool}" domain passwordsettings set \
520 "${ADMIN_LDBMODIFY_CONFIG}" \
521 --complexity=default \
522 --history-length=default \
523 --min-pwd-length=default \
524 --min-pwd-age=default \
525 --max-pwd-age=default || \
526 failed=$((failed + 1))
528 ###########################################################
529 ### Test basic s4u2self request
530 ###########################################################
532 # MIT ONLY
533 if [ "${kbase}" = "kinit" ]; then
535 # Use previous acquired machine creds to request a ticket for self.
536 # We expect it to fail for now.
537 MACHINE_ACCOUNT="$(hostname -s | tr '[:lower:]' '[:upper:]')\$@${REALM}"
539 ${samba_kvno} -U"${MACHINE_ACCOUNT}" "${MACHINE_ACCOUNT}"
541 # But we expect the KDC to be up and running still
542 testit "kinit with machineaccountccache after s4u2self" \
543 "${machineaccountccache}" "${CONFIGURATION}" "${KRB5CCNAME}" || \
544 failed=$((failed + 1))
546 fi # END MIT ONLY
548 ### Cleanup
550 rm -f "${KRB5CCNAME_PATH}"
551 rm -f "${PREFIX}/tmpkinituserpassscript"
552 rm -f "${PREFIX}/tmpkinitscript"
553 rm -f "${PREFIX}/tmpkpasswdscript"
555 exit $failed