2009-06-18 06:38:04 +04:00
#!/bin/sh
2016-09-06 10:31:41 +03:00
# Blackbox tests for chainging passwords with kinit and kpasswd
#
2009-06-18 06:38:04 +04:00
# Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
# Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
2016-09-06 10:31:41 +03:00
# Copyright (C) 2016 Andreas Schneider <asn@samba.org>
2009-06-18 06:38:04 +04:00
2023-03-13 14:23:08 +03:00
if [ $# -lt 7 ] ; then
2022-04-22 16:46:05 +03:00
cat <<EOF
2023-03-13 14:23:08 +03:00
Usage: test_kpasswd_heimdal.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX SMBCLIENT CONFIGURATION
2009-06-18 06:38:04 +04:00
EOF
2022-04-22 16:46:05 +03:00
exit 1
2009-06-18 06:38:04 +04:00
fi
SERVER = $1
USERNAME = $2
PASSWORD = $3
REALM = $4
DOMAIN = $5
PREFIX = $6
2023-03-13 14:23:08 +03:00
CONFIGURATION = ${ 7 }
shift 7
2009-06-18 06:38:04 +04:00
failed = 0
2016-09-06 10:31:41 +03:00
samba_bindir = " $BINDIR "
2014-05-12 18:56:29 +04:00
2016-09-06 10:31:41 +03:00
smbclient = " $samba_bindir /smbclient "
samba_kinit = $samba_bindir /samba4kinit
samba_kpasswd = $samba_bindir /samba4kpasswd
2022-05-19 17:35:28 +03:00
mit_kpasswd = " $( command -v kpasswd) "
2016-09-06 10:31:41 +03:00
samba_tool = " $samba_bindir /samba-tool "
2023-03-13 14:23:08 +03:00
net_tool = " $samba_bindir /net ${ CONFIGURATION } "
2016-09-06 10:31:41 +03:00
texpect = " $samba_bindir /texpect "
2014-05-12 18:56:29 +04:00
2011-10-24 02:23:28 +04:00
newuser = " $samba_tool user create "
2016-09-06 10:31:41 +03:00
SMB_UNC = " // $SERVER /tmp "
2009-06-18 06:38:04 +04:00
2022-04-22 16:46:05 +03:00
. $( dirname $0 ) /subunit.sh
. $( dirname $0 ) /common_test_fns.inc
2009-06-18 06:38:04 +04:00
2022-04-22 16:46:05 +03:00
do_kinit( )
{
2016-09-06 10:31:41 +03:00
principal = " $1 "
2014-08-25 18:35:23 +04:00
password = " $2 "
shift
shift
2022-06-13 16:57:35 +03:00
kerberos_kinit " $samba_kinit " " $principal " " $password " " $@ "
2014-08-25 18:35:23 +04:00
}
2016-09-06 10:31:41 +03:00
testit "reset password policies beside of minimum password age of 0 days" \
2023-03-13 14:23:08 +03:00
$VALGRIND $PYTHON $samba_tool domain passwordsettings set " ${ CONFIGURATION } " --complexity= default --history-length= default --min-pwd-length= default --min-pwd-age= 0 --max-pwd-age= default || failed = $( expr $failed + 1)
2010-07-03 13:23:39 +04:00
2016-09-06 10:31:41 +03:00
TEST_USERNAME = " $( mktemp -u alice-XXXXXX) "
TEST_PRINCIPAL = " $TEST_USERNAME @ $REALM "
TEST_PASSWORD = "testPaSS@00%"
TEST_PASSWORD_NEW = "testPaSS@01%"
TEST_PASSWORD_SHORT = "secret"
TEST_PASSWORD_WEAK = "Supersecret"
2009-06-18 06:38:04 +04:00
2016-09-06 10:31:41 +03:00
testit "create user locally" \
2023-03-13 14:23:08 +03:00
$VALGRIND $PYTHON $newuser " ${ CONFIGURATION } " $TEST_USERNAME $TEST_PASSWORD || failed = $( expr $failed + 1)
2009-06-18 06:38:04 +04:00
KRB5CCNAME = " $PREFIX /tmpuserccache "
export KRB5CCNAME
2016-09-06 10:31:41 +03:00
testit "kinit with user password" \
2022-04-22 16:46:05 +03:00
do_kinit $TEST_PRINCIPAL $TEST_PASSWORD || failed = $( expr $failed + 1)
2009-06-18 06:38:04 +04:00
2016-09-06 10:31:41 +03:00
test_smbclient "Test login with user kerberos ccache" \
2022-04-22 16:46:05 +03:00
"ls" " $SMB_UNC " --use-krb5-ccache= ${ KRB5CCNAME } || failed = $( expr $failed + 1)
2009-06-18 06:38:04 +04:00
2016-09-06 10:31:41 +03:00
testit "change user password with 'samba-tool user password' (unforced)" \
2023-03-13 14:23:08 +03:00
$VALGRIND $PYTHON $samba_tool user password " ${ CONFIGURATION } " -W$DOMAIN -U$TEST_USERNAME %$TEST_PASSWORD --use-kerberos= off --newpassword= $TEST_PASSWORD_NEW || failed = $( expr $failed + 1)
2009-06-18 06:38:04 +04:00
2016-09-06 10:31:41 +03:00
TEST_PASSWORD_OLD = $TEST_PASSWORD
TEST_PASSWORD = $TEST_PASSWORD_NEW
TEST_PASSWORD_NEW = "testPaSS@02%"
2009-06-18 06:38:04 +04:00
2016-09-06 10:31:41 +03:00
testit "kinit with user password" \
2022-04-22 16:46:05 +03:00
do_kinit $TEST_PRINCIPAL $TEST_PASSWORD || failed = $( expr $failed + 1)
2009-06-18 06:38:04 +04:00
2016-09-06 10:31:41 +03:00
test_smbclient "Test login with user kerberos ccache" \
2022-04-22 16:46:05 +03:00
"ls" " $SMB_UNC " --use-krb5-ccache= ${ KRB5CCNAME } || failed = $( expr $failed + 1)
2012-05-24 07:36:20 +04:00
2016-09-06 10:31:41 +03:00
###########################################################
### check that a short password is rejected
###########################################################
2010-04-15 10:25:50 +04:00
2022-04-22 16:46:05 +03:00
cat >$PREFIX /tmpkpasswdscript <<EOF
2010-04-15 10:25:50 +04:00
expect Password
2016-09-06 10:31:41 +03:00
password ${ TEST_PASSWORD } \n
2010-04-15 10:25:50 +04:00
expect New password
2016-09-06 10:31:41 +03:00
send ${ TEST_PASSWORD_SHORT } \n
expect Verify password
send ${ TEST_PASSWORD_SHORT } \n
expect Password too short
2010-04-15 10:25:50 +04:00
EOF
2016-09-06 10:31:41 +03:00
testit "kpasswd check short user password" \
2022-04-22 16:46:05 +03:00
$texpect $PREFIX /tmpkpasswdscript $samba_kpasswd $TEST_PRINCIPAL || failed = $( expr $failed + 1)
2016-09-06 10:31:41 +03:00
###########################################################
### check that a weak password is rejected
###########################################################
2010-04-15 10:25:50 +04:00
echo "check that a short password is rejected"
2022-04-22 16:46:05 +03:00
cat >$PREFIX /tmpkpasswdscript <<EOF
2010-04-15 10:25:50 +04:00
expect Password
2016-09-06 10:31:41 +03:00
password ${ TEST_PASSWORD } \n
2010-04-15 10:25:50 +04:00
expect New password
2016-09-06 10:31:41 +03:00
send $TEST_PASSWORD_WEAK \n
expect Verify password
send $TEST_PASSWORD_WEAK \n
expect Password does not meet complexity requirements
2010-04-15 10:25:50 +04:00
EOF
2016-09-06 10:31:41 +03:00
testit "kpasswd check weak user password" \
2022-04-22 16:46:05 +03:00
$texpect $PREFIX /tmpkpasswdscript $samba_kpasswd $TEST_PRINCIPAL || failed = $( expr $failed + 1)
2010-04-15 10:25:50 +04:00
2016-09-06 10:31:41 +03:00
###########################################################
### check that a strong password is accepted
###########################################################
2010-04-15 10:25:50 +04:00
2022-04-22 16:46:05 +03:00
cat >$PREFIX /tmpkpasswdscript <<EOF
2009-06-18 06:38:04 +04:00
expect Password
2016-09-06 10:31:41 +03:00
password ${ TEST_PASSWORD } \n
2009-06-18 06:38:04 +04:00
expect New password
2016-09-06 10:31:41 +03:00
send ${ TEST_PASSWORD_NEW } \n
expect Verify password
send ${ TEST_PASSWORD_NEW } \n
2009-06-18 06:38:04 +04:00
expect Success
EOF
2016-09-06 10:31:41 +03:00
testit "kpasswd change user password" \
2022-04-22 16:46:05 +03:00
$texpect $PREFIX /tmpkpasswdscript $samba_kpasswd $TEST_PRINCIPAL || failed = $( expr $failed + 1)
2009-06-18 06:38:04 +04:00
2016-09-06 10:31:41 +03:00
TEST_PASSWORD = $TEST_PASSWORD_NEW
TEST_PASSWORD_NEW = "testPaSS@03%"
2009-06-18 06:38:04 +04:00
2022-05-19 17:35:28 +03:00
###########################################################
2022-10-04 10:31:47 +03:00
### CVE-2022-2031
2022-05-19 17:35:28 +03:00
###########################################################
if [ -n " ${ mit_kpasswd } " ] ; then
cat > " ${ PREFIX } /tmpkpasswdscript " <<EOF
expect Password for ${ TEST_PRINCIPAL }
password ${ TEST_PASSWORD } \n
expect Enter new password
send ${ TEST_PASSWORD_NEW } \n
expect Enter it again
send ${ TEST_PASSWORD_NEW } \n
expect Password changed.
EOF
SAVE_KRB5_CONFIG = " ${ KRB5_CONFIG } "
KRB5_CONFIG = " ${ PREFIX } /tmpkrb5.conf "
export KRB5_CONFIG
sed -e 's/\[libdefaults\]/[libdefaults]\n canonicalize = yes/' \
" ${ SAVE_KRB5_CONFIG } " > " ${ KRB5_CONFIG } "
testit "MIT kpasswd change user password" \
" ${ texpect } " " ${ PREFIX } /tmpkpasswdscript " " ${ mit_kpasswd } " \
" ${ TEST_PRINCIPAL } " ||
failed = $(( failed + 1 ))
KRB5_CONFIG = " ${ SAVE_KRB5_CONFIG } "
export KRB5_CONFIG
fi
TEST_PASSWORD = " ${ TEST_PASSWORD_NEW } "
TEST_PASSWORD_NEW = "testPaSS@03force%"
2016-09-06 10:31:41 +03:00
###########################################################
### Force password change at login
###########################################################
2012-01-24 12:23:20 +04:00
2016-09-06 10:31:41 +03:00
testit "set password on user locally" \
2023-03-13 14:23:08 +03:00
$VALGRIND $PYTHON $samba_tool user setpassword $TEST_USERNAME " ${ CONFIGURATION } " --newpassword= $TEST_PASSWORD_NEW --must-change-at-next-login || failed = $( expr $failed + 1)
2012-01-24 12:23:20 +04:00
2016-09-06 10:31:41 +03:00
TEST_PASSWORD = $TEST_PASSWORD_NEW
TEST_PASSWORD_NEW = "testPaSS@04%"
2012-01-24 12:23:20 +04:00
2016-09-06 10:31:41 +03:00
rm -f $PREFIX /tmpuserccache
2012-01-24 12:23:20 +04:00
2022-04-22 16:46:05 +03:00
cat >$PREFIX /tmpkinitscript <<EOF
2009-06-18 06:38:04 +04:00
expect Password
2016-09-06 10:31:41 +03:00
password ${ TEST_PASSWORD } \n
expect Changing password
2009-06-18 06:38:04 +04:00
expect New password
2016-09-06 10:31:41 +03:00
send ${ TEST_PASSWORD_NEW } \n
expect Repeat new password
send ${ TEST_PASSWORD_NEW } \n
2009-06-18 06:38:04 +04:00
expect Success
EOF
2016-09-06 10:31:41 +03:00
testit "kinit and change user password" \
2022-04-22 16:46:05 +03:00
$texpect $PREFIX /tmpkinitscript $samba_kinit $TEST_PRINCIPAL || failed = $( expr $failed + 1)
2009-09-08 15:01:18 +04:00
2016-09-06 10:31:41 +03:00
TEST_PASSWORD = $TEST_PASSWORD_NEW
TEST_PASSWORD_NEW = "testPaSS@07%"
2009-09-08 15:01:18 +04:00
2016-09-06 10:31:41 +03:00
test_smbclient "Test login with user (kerberos)" \
2022-04-22 16:46:05 +03:00
"ls" " $SMB_UNC " -k yes -U$TEST_PRINCIPAL %$TEST_PASSWORD || failed = $( expr $failed + 1)
2009-09-08 15:01:18 +04:00
2016-09-06 10:31:41 +03:00
###########################################################
### Test kpasswd service via 'net ads password'
###########################################################
2009-09-08 15:01:18 +04:00
2016-09-06 10:31:41 +03:00
# NOTE: This works with heimdal because the krb5_set_password function tries
# set_password call first and falls back to change_password if it doesn't
# succeed.
testit " change user password with 'net ads password', admin: $DOMAIN / $TEST_USERNAME , target: $TEST_PRINCIPAL " \
2022-04-22 16:46:05 +03:00
$VALGRIND $net_tool ads password -W$DOMAIN -U$TEST_PRINCIPAL %$TEST_PASSWORD $TEST_PRINCIPAL " $TEST_PASSWORD_NEW " || failed = $( expr $failed + 1)
2009-12-31 08:52:49 +03:00
2016-09-06 10:31:41 +03:00
TEST_PASSWORD = $TEST_PASSWORD_NEW
TEST_PASSWORD_NEW = "testPaSS@08%"
2014-08-26 14:39:06 +04:00
2016-09-06 10:31:41 +03:00
test_smbclient "Test login with smbclient (ntlm)" \
2022-04-22 16:46:05 +03:00
"ls" " $SMB_UNC " -k no -U$TEST_PRINCIPAL %$TEST_PASSWORD || failed = $( expr $failed + 1)
2014-08-26 14:39:06 +04:00
2016-09-06 10:31:41 +03:00
###########################################################
### Test kpasswd service via 'net ads password' as admin
###########################################################
2014-08-26 14:39:06 +04:00
2016-09-06 10:31:41 +03:00
testit " set user password with 'net ads password', admin: $DOMAIN / $USERNAME , target: $TEST_PRINCIPAL " \
2022-04-22 16:46:05 +03:00
$VALGRIND $net_tool ads password -W$DOMAIN -U$USERNAME @$REALM %$PASSWORD $TEST_PRINCIPAL " $TEST_PASSWORD_NEW " || failed = $( expr $failed + 1)
2014-08-26 14:39:06 +04:00
2016-09-06 10:31:41 +03:00
TEST_PASSWORD = $TEST_PASSWORD_NEW
TEST_PASSWORD_NEW = "testPaSS@07%"
2009-09-08 15:01:18 +04:00
2016-09-06 10:31:41 +03:00
test_smbclient "Test login with smbclient (ntlm)" \
2022-04-22 16:46:05 +03:00
"ls" " $SMB_UNC " -k no -U$TEST_PRINCIPAL %$TEST_PASSWORD || failed = $( expr $failed + 1)
2009-09-08 15:01:18 +04:00
2016-09-06 10:31:41 +03:00
###########################################################
### Cleanup
###########################################################
2009-09-08 15:01:18 +04:00
2016-09-06 10:31:41 +03:00
testit "reset password policies" \
2023-03-13 14:23:08 +03:00
$VALGRIND $PYTHON $samba_tool domain passwordsettings set " ${ CONFIGURATION } " --complexity= default --history-length= default --min-pwd-length= default --min-pwd-age= default --max-pwd-age= default || failed = $( expr $failed + 1)
2009-09-08 15:01:18 +04:00
2016-09-06 10:31:41 +03:00
testit "delete user" \
2023-03-13 14:23:08 +03:00
$VALGRIND $PYTHON $samba_tool user delete $TEST_USERNAME -U" $USERNAME % $PASSWORD " " ${ CONFIGURATION } " -k no || failed = $( expr $failed + 1)
2009-06-18 06:38:04 +04:00
2016-09-06 10:31:41 +03:00
rm -f $PREFIX /tmpuserccache $PREFIX /tmpkpasswdscript $PREFIX /tmpkinitscript
2009-06-18 06:38:04 +04:00
exit $failed