2019-10-30 17:59:16 +03:00
#!/bin/sh
if [ $# -lt 5 ] ; then
2022-04-22 16:46:05 +03:00
cat <<EOF
2019-10-30 17:59:16 +03:00
Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX
EOF
2022-04-22 16:46:05 +03:00
exit 1
2019-10-30 17:59:16 +03:00
fi
SERVER = $1
USERNAME = $2
PASSWORD = $3
REALM = $4
DOMAIN = $5
2020-05-09 17:26:45 +03:00
TRUST_SERVER = $6
TRUST_USERNAME = $7
TRUST_PASSWORD = $8
TRUST_REALM = $9
TRUST_DOMAIN = ${ 10 }
PREFIX = ${ 11 }
shift 11
2019-10-30 17:59:16 +03:00
failed = 0
samba_tool = " $VALGRIND $PYTHON $BINDIR /samba-tool "
2020-04-03 17:29:36 +03:00
samba4kinit_binary = kinit
2019-10-30 17:59:16 +03:00
if test -x $BINDIR /samba4kinit; then
2020-04-03 17:29:36 +03:00
samba4kinit_binary = $BINDIR /samba4kinit
2019-10-30 17:59:16 +03:00
fi
samba4kgetcred = kgetcred
if test -x $BINDIR /samba4kgetcred; then
samba4kgetcred = $BINDIR /samba4kgetcred
fi
2022-04-22 16:46:05 +03:00
. $( dirname $0 ) /subunit.sh
. $( dirname $0 ) /common_test_fns.inc
2019-10-30 17:59:16 +03:00
ocache = " $PREFIX /tmpoutcache "
KRB5CCNAME_PATH = " $PREFIX /tmpccache "
KRB5CCNAME = " FILE: $KRB5CCNAME_PATH "
2020-04-03 17:29:36 +03:00
samba4kinit = " $samba4kinit_binary -c $KRB5CCNAME "
2019-10-30 17:59:16 +03:00
export KRB5CCNAME
rm -rf $KRB5CCNAME_PATH
princ = test_impersonate_princ
2020-05-09 17:26:45 +03:00
impersonator = test_impersonator.$REALM
2019-10-30 17:59:16 +03:00
target = " CIFS/ $SERVER . $REALM "
2022-04-22 16:46:05 +03:00
testit "add impersonator principal" $samba_tool user add $impersonator $PASSWORD || failed = $( expr $failed + 1)
testit "become a service" $samba_tool spn add " HOST/ $impersonator " $impersonator || failed = $( expr $failed + 1)
2019-10-30 17:59:16 +03:00
2022-04-22 16:46:05 +03:00
testit "set TrustedToAuthForDelegation" $samba_tool delegation for -any-protocol $impersonator on || failed = $( expr $failed + 1)
testit "add msDS-AllowedToDelegateTo" $samba_tool delegation add-service $impersonator $target || failed = $( expr $failed + 1)
2019-10-30 17:59:16 +03:00
2022-04-22 16:46:05 +03:00
testit "add a new principal" $samba_tool user add $princ --random-password || failed = $( expr $failed + 1)
testit "set not-delegated flag" $samba_tool user sensitive $princ on || failed = $( expr $failed + 1)
2019-10-30 17:59:16 +03:00
2022-04-22 16:46:05 +03:00
echo $PASSWORD >$PREFIX /tmppassfile
testit "kinit impersonator" $samba4kinit -f --password-file= $PREFIX /tmppassfile $impersonator || failed = $( expr $failed + 1)
2019-10-30 17:59:16 +03:00
2022-04-22 16:46:05 +03:00
testit "test S4U2Self with normal user" $samba4kgetcred --out-cache= $ocache --forwardable --impersonate= ${ USERNAME } $impersonator || failed = $( expr $failed + 1)
testit "test S4U2Proxy with normal user" $samba4kgetcred --out-cache= $ocache --delegation-credential-cache= ${ ocache } $target || failed = $( expr $failed + 1)
2019-10-30 17:59:16 +03:00
2022-04-22 16:46:05 +03:00
testit "test S4U2Self with sensitive user" $samba4kgetcred --out-cache= $ocache --forwardable --impersonate= $princ $impersonator || failed = $( expr $failed + 1)
testit_expect_failure "test S4U2Proxy with sensitive user" $samba4kgetcred --out-cache= $ocache --delegation-credential-cache= ${ ocache } $target || failed = $( expr $failed + 1)
2019-10-30 17:59:16 +03:00
rm -f $ocache
2022-04-22 16:46:05 +03:00
testit "unset not-delegated flag" $samba_tool user sensitive $princ off || failed = $( expr $failed + 1)
2019-10-30 17:59:16 +03:00
2022-04-22 16:46:05 +03:00
testit "test S4U2Self after unsetting ND flag" $samba4kgetcred --out-cache= $ocache --forwardable --impersonate= $princ $impersonator || failed = $( expr $failed + 1)
testit "test S4U2Proxy after unsetting ND flag" $samba4kgetcred --out-cache= $ocache --delegation-credential-cache= ${ ocache } $target || failed = $( expr $failed + 1)
2019-10-30 17:59:16 +03:00
2022-04-22 16:46:05 +03:00
testit "kinit user cache" $samba4kinit -c $ocache -f --password-file= $PREFIX /tmppassfile $USERNAME || failed = $( expr $failed + 1)
testit "get a ticket to impersonator" $samba4kgetcred -c $ocache --forwardable $impersonator || failed = $( expr $failed + 1)
testit "test S4U2Proxy evidence ticket obtained by TGS" $samba4kgetcred --out-cache= $ocache --delegation-credential-cache= ${ ocache } $target || failed = $( expr $failed + 1)
2020-05-09 17:26:45 +03:00
2022-04-22 16:46:05 +03:00
echo $TRUST_PASSWORD >$PREFIX /tmppassfile
testit "kinit trust user cache" $samba4kinit -c $ocache -f --password-file= $PREFIX /tmppassfile $TRUST_USERNAME @$TRUST_REALM || failed = $( expr $failed + 1)
testit "get a ticket to impersonator for trust user" $samba4kgetcred -c $ocache --forwardable $impersonator || failed = $( expr $failed + 1)
testit "test S4U2Proxy evidence ticket obtained by TGS of trust user" $samba4kgetcred --out-cache= $ocache --delegation-credential-cache= ${ ocache } $target || failed = $( expr $failed + 1)
2020-01-19 18:24:24 +03:00
2022-04-22 16:46:05 +03:00
echo $PASSWORD >$PREFIX /tmppassfile
testit "set not-delegated on impersonator" $samba_tool user sensitive $impersonator on || failed = $( expr $failed + 1)
testit "kinit user cache again" $samba4kinit -c $ocache -f --password-file= $PREFIX /tmppassfile $USERNAME || failed = $( expr $failed + 1)
testit "get a ticket to sensitive impersonator" $samba4kgetcred -c $ocache --forwardable $impersonator || failed = $( expr $failed + 1)
testit_expect_failure "test S4U2Proxy using received ticket" $samba4kgetcred --out-cache= $ocache --delegation-credential-cache= ${ ocache } $target || failed = $( expr $failed + 1)
2020-01-19 18:24:24 +03:00
rm -f $ocache $PREFIX /tmpccache $PREFIX /tmppassfile
2019-10-30 17:59:16 +03:00
exit $failed