2010-07-04 16:39:17 +04:00
#!/bin/sh
# Blackbox tests for kinit and kerberos integration with smbclient etc
# Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
# Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
if [ $# -lt 4 ] ; then
2022-04-22 16:46:04 +03:00
cat <<EOF
2023-09-05 07:22:01 +03:00
Usage: test_chgdcpass.sh SERVER USERNAME REALM DOMAIN PREFIX ENCTYPE PROVDIR SMBCLIENT
2010-07-04 16:39:17 +04:00
EOF
2022-04-22 16:46:04 +03:00
exit 1
2010-07-04 16:39:17 +04:00
fi
SERVER = $1
USERNAME = $2
REALM = $3
DOMAIN = $4
PREFIX = $5
ENCTYPE = $6
PROVDIR = $7
2012-05-30 14:07:18 +04:00
smbclient = $8
shift 8
2010-07-04 16:39:17 +04:00
failed = 0
2011-04-15 06:41:22 +04:00
samba4bindir = " $BINDIR "
2011-02-03 09:30:53 +03:00
samba4srcdir = " $SRCDIR /source4 "
2014-05-12 18:56:29 +04:00
2020-04-03 17:29:36 +03:00
samba4kinit_binary = kinit
2015-04-22 16:19:10 +03:00
heimdal = 0
2014-05-12 18:56:29 +04:00
if test -x $BINDIR /samba4kinit; then
2015-04-22 16:19:10 +03:00
heimdal = 1
2020-04-03 17:29:36 +03:00
samba4kinit_binary = bin/samba4kinit
2014-05-12 18:56:29 +04:00
fi
2011-02-03 09:30:53 +03:00
machineaccountccache = " $samba4srcdir /scripting/bin/machineaccountccache "
2010-07-04 16:39:17 +04:00
2016-04-24 21:09:05 +03:00
unc = " // $SERVER /tmp "
2010-07-04 16:39:17 +04:00
2022-04-22 16:46:04 +03:00
. $( dirname $0 ) /subunit.sh
. $( dirname $0 ) /common_test_fns.inc
2010-07-15 04:54:08 +04:00
2022-04-22 16:46:04 +03:00
test_drs( )
{
2012-11-01 07:11:02 +04:00
function = " $1 "
name = " $2 "
shift
2012-10-31 11:45:25 +04:00
shift
echo " test: $name "
2022-06-13 16:33:55 +03:00
echo $VALGRIND $PYTHON $samba4bindir /samba-tool drs $function $SERVER -k yes " $@ "
$VALGRIND $PYTHON $samba4bindir /samba-tool drs $function $SERVER -k yes " $@ "
2012-10-31 11:45:25 +04:00
status = $?
if [ x$status = x0 ] ; then
echo " success: $name "
else
echo " failure: $name "
fi
return $status
}
2010-07-04 16:39:17 +04:00
enctype = " -e $ENCTYPE "
KRB5CCNAME = " $PREFIX /tmpccache "
2020-04-03 17:29:36 +03:00
samba4kinit = " $samba4kinit_binary -c $KRB5CCNAME "
2010-07-04 16:39:17 +04:00
export KRB5CCNAME
rm -f $KRB5CCNAME
2015-04-22 16:19:10 +03:00
if [ $heimdal -eq 1 ] ; then
2022-04-22 16:46:04 +03:00
testit "kinit with keytab" $samba4kinit $enctype -t $PROVDIR /private/secrets.keytab --use-keytab $USERNAME || failed = $( expr $failed + 1)
2015-04-22 16:19:10 +03:00
else
2022-04-22 16:46:04 +03:00
testit "kinit with keytab" $samba4kinit -k -t $PROVDIR /private/secrets.keytab $USERNAME || failed = $( expr $failed + 1)
2015-04-22 16:19:10 +03:00
fi
2010-07-15 04:54:08 +04:00
2010-07-15 08:05:23 +04:00
#This is important because it puts the ticket for the old KVNO and password into a local ccache
2022-04-22 16:46:04 +03:00
test_smbclient "Test login with kerberos ccache before password change" 'ls' " $unc " --use-krb5-ccache= $KRB5CCNAME || failed = $( expr $failed + 1)
2012-10-31 11:45:25 +04:00
2012-11-01 07:11:02 +04:00
#check that drs bind works before we change the password (prime the ccache)
2022-04-22 16:46:04 +03:00
test_drs bind "Test drs bind with with kerberos ccache" || failed = $( expr $failed + 1)
2012-11-01 07:11:02 +04:00
2012-10-31 11:45:25 +04:00
#check that drs options works before we change the password (prime the ccache)
2022-04-22 16:46:04 +03:00
test_drs options "Test drs options with with kerberos ccache" || failed = $( expr $failed + 1)
2012-10-31 11:45:25 +04:00
2022-04-22 16:46:04 +03:00
testit "change dc password" $PYTHON $samba4srcdir /scripting/devel/chgtdcpass --configfile= $PROVDIR /etc/smb.conf || failed = $( expr $failed + 1)
2010-07-15 04:54:08 +04:00
2010-07-15 08:05:23 +04:00
#This is important because it shows that the old ticket remains valid (as it must) for incoming connections after the DC password is changed
2022-04-22 16:46:04 +03:00
test_smbclient "Test login with kerberos ccache after password change" 'ls' " $unc " --use-krb5-ccache= $KRB5CCNAME || failed = $( expr $failed + 1)
2010-07-15 04:54:08 +04:00
2012-11-01 07:11:02 +04:00
#check that drs bind works after we change the password
2022-04-22 16:46:04 +03:00
test_drs bind "Test drs bind with new password" || failed = $( expr $failed + 1)
2012-11-01 07:11:02 +04:00
2012-10-31 11:45:25 +04:00
#check that drs options works after we change the password
2022-04-22 16:46:04 +03:00
test_drs options "Test drs options with new password" || failed = $( expr $failed + 1)
2012-10-31 11:45:25 +04:00
2022-04-22 16:46:04 +03:00
testit "change dc password (2nd time)" $PYTHON $samba4srcdir /scripting/devel/chgtdcpass --configfile= $PROVDIR /etc/smb.conf || failed = $( expr $failed + 1)
2012-10-31 11:00:43 +04:00
2015-02-23 06:22:29 +03:00
# This is important because it shows that the old ticket is discarded if the server rejects it (as it must) after the password was changed twice in succession.
# This also ensures we handle the case where the domain is re-provisioned etc
2022-04-22 16:46:04 +03:00
test_smbclient "Test login with kerberos ccache after 2nd password change" 'ls' " $unc " --use-krb5-ccache= $KRB5CCNAME || failed = $( expr $failed + 1)
2012-10-31 11:00:43 +04:00
2012-11-01 07:11:02 +04:00
#check that drs bind works after we change the password a 2nd time
2022-04-22 16:46:04 +03:00
test_drs bind "Test drs bind after 2nd password change" || failed = $( expr $failed + 1)
2012-11-01 07:11:02 +04:00
2012-10-31 11:45:25 +04:00
#check that drs options works after we change the password a 2nd time
2022-04-22 16:46:04 +03:00
test_drs options "Test drs options after 2nd password change" || failed = $( expr $failed + 1)
2012-10-31 11:45:25 +04:00
2010-07-15 04:54:08 +04:00
#This confirms that the DC password is valid for a kinit too
2015-04-22 16:19:10 +03:00
if [ $heimdal -eq 1 ] ; then
2022-04-22 16:46:04 +03:00
testit "kinit with keytab" $samba4kinit $enctype -t $PROVDIR /private/secrets.keytab --use-keytab $USERNAME || failed = $( expr $failed + 1)
2015-04-22 16:19:10 +03:00
else
2022-04-22 16:46:04 +03:00
testit "kinit with keytab" $samba4kinit -k -t $PROVDIR /private/secrets.keytab $USERNAME || failed = $( expr $failed + 1)
2015-04-22 16:19:10 +03:00
fi
2022-04-22 16:46:04 +03:00
test_smbclient "Test login with kerberos ccache with fresh kinit" 'ls' " $unc " --use-krb5-ccache= $KRB5CCNAME || failed = $( expr $failed + 1)
2015-04-22 16:19:10 +03:00
2010-07-04 16:39:17 +04:00
rm -f $KRB5CCNAME
2018-03-22 03:15:34 +03:00
rm -f $PREFIX /tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache
2010-07-04 16:39:17 +04:00
exit $failed