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
2016-09-06 10:31:41 +03:00
if [ $# -lt 6 ] ; then
2009-06-18 06:38:04 +04:00
cat <<EOF
2012-05-30 14:18:35 +04:00
Usage: test_passwords.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX SMBCLIENT
2009-06-18 06:38:04 +04:00
EOF
exit 1;
fi
SERVER = $1
USERNAME = $2
PASSWORD = $3
REALM = $4
DOMAIN = $5
PREFIX = $6
2016-09-06 10:31:41 +03:00
shift 6
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
samba_tool = " $samba_bindir /samba-tool "
net_tool = " $samba_bindir /net "
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
. ` dirname $0 ` /subunit.sh
2016-04-24 21:09:05 +03:00
. ` dirname $0 ` /common_test_fns.inc
2009-06-18 06:38:04 +04:00
2014-08-25 18:35:23 +04: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
2016-09-06 10:31:41 +03:00
echo $password > $PREFIX /tmppassfile
$samba_kinit --password-file= $PREFIX /tmppassfile $principal $@
2014-08-25 18:35:23 +04:00
}
2013-07-29 15:50:06 +04:00
UID_WRAPPER_ROOT = 1
export UID_WRAPPER_ROOT
2015-03-16 12:27:56 +03:00
CONFIG = " --configfile= $PREFIX /etc/smb.conf "
2009-12-31 08:52:49 +03:00
export CONFIG
2016-09-06 10:31:41 +03:00
testit "reset password policies beside of minimum password age of 0 days" \
2018-05-03 03:12:04 +03:00
$VALGRIND $samba_tool domain passwordsettings set $CONFIG --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" \
$VALGRIND $newuser $CONFIG $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" \
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" \
"ls" " $SMB_UNC " -k yes || 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)" \
$VALGRIND $samba_tool user password -W$DOMAIN -U$TEST_USERNAME %$TEST_PASSWORD -k no --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" \
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" \
"ls" " $SMB_UNC " -k yes || 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
2016-09-06 10:31:41 +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" \
$texpect $PREFIX /tmpkpasswdscript $samba_kpasswd $TEST_PRINCIPAL || failed = ` expr $failed + 1`
###########################################################
### check that a weak password is rejected
###########################################################
2010-04-15 10:25:50 +04:00
echo "check that a short password is rejected"
2018-03-22 03:18:39 +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" \
$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
2018-03-22 03:18:39 +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" \
$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
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" \
$VALGRIND $samba_tool user setpassword $TEST_USERNAME $CONFIG --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
2016-09-06 10:31:41 +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" \
$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)" \
"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 " \
$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)" \
"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 " \
$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)" \
"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" \
2018-05-03 03:12:04 +03:00
$VALGRIND $samba_tool domain passwordsettings set $CONFIG --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" \
$VALGRIND $samba_tool user delete $TEST_USERNAME -U" $USERNAME % $PASSWORD " $CONFIG -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