2007-04-16 08:55:52 +04:00
#!/bin/sh
2007-07-19 10:40:42 +04:00
# Blackbox tests for kinit and kerberos integration with smbclient etc
# Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
2008-10-20 07:22:37 +04:00
# Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
2007-04-16 08:55:52 +04:00
if [ $# -lt 5 ] ; then
cat <<EOF
2012-05-30 14:15:10 +04:00
Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX ENCTYPE SMBCLIENT
2007-04-16 08:55:52 +04:00
EOF
exit 1;
fi
SERVER = $1
USERNAME = $2
PASSWORD = $3
REALM = $4
2007-07-19 10:40:42 +04:00
DOMAIN = $5
PREFIX = $6
2010-06-24 03:42:40 +04:00
ENCTYPE = $7
2012-05-30 14:15:10 +04:00
smbclient = $8
shift 8
2007-04-16 08:55:52 +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 "
2012-01-26 02:42:27 +04:00
samba4kinit = " $samba4bindir /samba4kinit "
samba_tool = " $samba4bindir /samba-tool "
ldbmodify = " $samba4bindir /ldbmodify "
ldbsearch = " $samba4bindir /ldbsearch "
rkpty = " $samba4bindir /rkpty "
samba4kpasswd = " $samba4bindir /samba4kpasswd "
2011-06-01 11:22:15 +04:00
enableaccount = " $samba_tool user enable "
2011-02-03 09:30:53 +03:00
machineaccountccache = " $samba4srcdir /scripting/bin/machineaccountccache "
2007-09-02 04:04:27 +04:00
2008-04-16 16:52:29 +04:00
. ` dirname $0 ` /subunit.sh
2007-07-19 10:40:42 +04:00
test_smbclient( ) {
name = " $1 "
cmd = " $2 "
shift
shift
echo " test: $name "
2011-10-18 03:03:21 +04:00
$VALGRIND $smbclient $CONFIGURATION //$SERVER /tmp -c " $cmd " $@
2007-07-19 10:40:42 +04:00
status = $?
if [ x$status = x0 ] ; then
echo " success: $name "
else
echo " failure: $name "
fi
return $status
}
2010-06-24 03:42:40 +04:00
enctype = " -e $ENCTYPE "
2010-07-03 17:52:00 +04:00
PWSETCONFIG = " -H ldap:// $SERVER -U $USERNAME % $PASSWORD "
export PWSETCONFIG
2008-02-08 02:34:29 +03:00
KRB5CCNAME = " $PREFIX /tmpccache "
2007-04-16 08:55:52 +04:00
export KRB5CCNAME
2011-06-28 00:49:43 +04:00
testit "reset password policies beside of minimum password age of 0 days" $VALGRIND $samba_tool domain passwordsettings $PWSETCONFIG set --complexity= default --history-length= default --min-pwd-length= default --min-pwd-age= 0 --max-pwd-age= default || failed = ` expr $failed + 1`
2010-07-03 17:52:00 +04:00
2010-12-24 13:41:10 +03:00
echo $PASSWORD > $PREFIX /tmppassfile
2010-06-24 03:42:40 +04:00
#testit "kinit with keytab" $samba4kinit $enctype --keytab=$PREFIX/dc/private/secrets.keytab $SERVER\$@$REALM || failed=`expr $failed + 1`
2010-12-24 13:41:10 +03:00
testit "kinit with password" $samba4kinit $enctype --password-file= $PREFIX /tmppassfile --request-pac $USERNAME @$REALM || failed = ` expr $failed + 1`
testit "kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file= $PREFIX /tmppassfile --request-pac $USERNAME @$REALM || failed = ` expr $failed + 1`
testit "kinit with password (windows style)" $samba4kinit $enctype --renewable --windows --password-file= $PREFIX /tmppassfile --request-pac $USERNAME @$REALM || failed = ` expr $failed + 1`
2010-06-24 03:42:40 +04:00
testit "kinit renew ticket" $samba4kinit $enctype --request-pac -R
2007-07-19 10:40:42 +04:00
test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
2011-07-27 12:49:35 +04:00
testit "check time with kerberos ccache" $VALGRIND $samba_tool time $SERVER $CONFIGURATION -k yes $@ || failed = ` expr $failed + 1`
2007-07-19 10:40:42 +04:00
USERPASS = testPass@12%
2010-12-24 13:41:10 +03:00
echo $USERPASS > $PREFIX /tmpuserpassfile
2011-10-24 02:23:28 +04:00
testit "add user with kerberos ccache" $VALGRIND $samba_tool user create nettestuser $USERPASS $CONFIGURATION -k yes $@ || failed = ` expr $failed + 1`
2007-07-19 10:40:42 +04:00
2010-03-25 08:30:54 +03:00
echo "Getting defaultNamingContext"
BASEDN = ` $ldbsearch $options --basedn= '' -H ldap://$SERVER -s base DUMMY = x defaultNamingContext | grep defaultNamingContext | awk '{print $2}' `
2010-12-24 13:41:10 +03:00
cat > $PREFIX /tmpldbmodify <<EOF
2010-03-25 08:30:54 +03:00
dn: cn = nettestuser,cn= users,$BASEDN
changetype: modify
add: servicePrincipalName
servicePrincipalName: host/nettestuser
EOF
2010-12-24 13:41:10 +03:00
testit "modify servicePrincipalName" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX /tmpldbmodify -k yes $@ || failed = ` expr $failed + 1`
2010-03-25 08:30:54 +03:00
2011-07-27 12:52:05 +04:00
testit "set user password with kerberos ccache" $VALGRIND $samba_tool user setpassword nettestuser --newpassword= $USERPASS $CONFIGURATION -k yes $@ || failed = ` expr $failed + 1`
2007-04-16 08:55:52 +04:00
2009-09-21 13:33:13 +04:00
testit "enable user with kerberos cache" $VALGRIND $enableaccount nettestuser -H ldap://$SERVER -k yes $@ || failed = ` expr $failed + 1`
2007-04-16 08:55:52 +04:00
2008-03-28 13:57:15 +03:00
KRB5CCNAME = " $PREFIX /tmpuserccache "
export KRB5CCNAME
2010-12-24 13:41:10 +03:00
testit "kinit with user password" $samba4kinit $enctype --password-file= $PREFIX /tmpuserpassfile --request-pac nettestuser@$REALM || failed = ` expr $failed + 1`
2008-03-28 13:57:15 +03:00
test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
2008-04-15 12:40:06 +04:00
NEWUSERPASS = testPaSS@34%
2011-07-28 03:23:03 +04:00
testit "change user password with 'samba-tool user password' (rpc)" $VALGRIND $samba_tool user password -W$DOMAIN -Unettestuser%$USERPASS $CONFIGURATION -k no --newpassword= $NEWUSERPASS $@ || failed = ` expr $failed + 1`
2008-04-15 12:40:06 +04:00
2010-12-24 13:41:10 +03:00
echo $NEWUSERPASS > $PREFIX /tmpuserpassfile
testit "kinit with user password" $samba4kinit $enctype --password-file= $PREFIX /tmpuserpassfile --request-pac nettestuser@$REALM || failed = ` expr $failed + 1`
2008-04-15 12:40:06 +04:00
test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
2008-10-20 07:22:37 +04:00
USERPASS = $NEWUSERPASS
NEWUSERPASS = testPaSS@56%
2010-12-24 13:41:10 +03:00
echo $NEWUSERPASS > $PREFIX /tmpuserpassfile
2008-10-20 07:22:37 +04:00
2010-12-24 13:41:10 +03:00
cat > $PREFIX /tmpkpasswdscript <<EOF
2008-10-20 07:22:37 +04:00
expect Password
password ${ USERPASS } \n
expect New password
send ${ NEWUSERPASS } \n
2010-03-27 03:48:05 +03:00
expect Verify password
2008-10-20 07:22:37 +04:00
send ${ NEWUSERPASS } \n
expect Success
EOF
2010-12-24 13:41:10 +03:00
testit "change user password with kpasswd" $rkpty $PREFIX /tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed = ` expr $failed + 1`
2008-10-20 07:22:37 +04:00
2010-12-24 13:41:10 +03:00
testit "kinit with user password" $samba4kinit $enctype --password-file= $PREFIX /tmpuserpassfile --request-pac nettestuser@$REALM || failed = ` expr $failed + 1`
2008-10-20 07:22:37 +04:00
NEWUSERPASS = testPaSS@78%
2010-12-24 13:41:10 +03:00
echo $NEWUSERPASS > $PREFIX /tmpuserpassfile
2008-10-20 07:22:37 +04:00
test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
2010-12-24 13:41:10 +03:00
cat > $PREFIX /tmpkpasswdscript <<EOF
2008-10-20 07:22:37 +04:00
expect New password
send ${ NEWUSERPASS } \n
2010-03-27 03:48:05 +03:00
expect Verify password
2008-10-20 07:22:37 +04:00
send ${ NEWUSERPASS } \n
expect Success
EOF
2010-12-24 13:41:10 +03:00
testit "set user password with kpasswd" $rkpty $PREFIX /tmpkpasswdscript $samba4kpasswd --cache= $PREFIX /tmpccache nettestuser@$REALM || failed = ` expr $failed + 1`
2008-10-20 07:22:37 +04:00
2010-12-24 13:41:10 +03:00
testit "kinit with user password" $samba4kinit $enctype --password-file= $PREFIX /tmpuserpassfile --request-pac nettestuser@$REALM || failed = ` expr $failed + 1`
2008-10-20 07:22:37 +04:00
test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
2010-03-25 08:30:54 +03:00
NEWUSERPASS = testPaSS@910%
2010-12-24 13:41:10 +03:00
echo $NEWUSERPASS > $PREFIX /tmpuserpassfile
2010-03-25 08:30:54 +03:00
2010-12-24 13:41:10 +03:00
cat > $PREFIX /tmpkpasswdscript <<EOF
2010-03-25 08:30:54 +03:00
expect New password
send ${ NEWUSERPASS } \n
2010-03-27 04:23:21 +03:00
expect Verify password
2010-03-25 08:30:54 +03:00
send ${ NEWUSERPASS } \n
expect Success
EOF
2010-12-24 13:41:10 +03:00
testit "set user password with kpasswd and servicePrincipalName" $rkpty $PREFIX /tmpkpasswdscript $samba4kpasswd --cache= $PREFIX /tmpccache host/nettestuser@$REALM || failed = ` expr $failed + 1`
2010-03-25 08:30:54 +03:00
2010-12-24 13:41:10 +03:00
testit "kinit with user password" $samba4kinit $enctype --password-file= $PREFIX /tmpuserpassfile --request-pac nettestuser@$REALM || failed = ` expr $failed + 1`
2010-03-25 08:30:54 +03:00
test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
2012-06-27 06:47:59 +04:00
cat > $PREFIX /tmpldbmodify <<EOF
dn: cn = nettestuser,cn= users,$BASEDN
changetype: modify
replace: pwdLastSet
pwdLastSet: 0
EOF
USERPASS = $NEWUSERPASS
NEWUSERPASS = testPaSS@911%
testit "modify pwdLastSet" $VALGRIND $ldbmodify $PWSETCONFIG $PREFIX /tmpldbmodify $PREFIX /tmpldbmodify -k yes $@ || failed = ` expr $failed + 1`
cat > $PREFIX /tmppasswordchange <<EOF
expect nettestuser@${ REALM } ' s Password:
send ${ USERPASS } \n
expect Your password will expire at
expect Changing password
expect New password:
send ${ NEWUSERPASS } \n
expect Repeat new password:
send ${ NEWUSERPASS } \n
expect Success: Password changed
EOF
testit "kinit with user password for expired password" $rkpty $PREFIX /tmppasswordchange $samba4kinit $enctype --request-pac nettestuser@$REALM && failed = ` expr $failed + 1`
test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
echo $NEWUSERPASS > $PREFIX /tmpuserpassfile
testit "kinit with user password" $samba4kinit $enctype --password-file= $PREFIX /tmpuserpassfile --request-pac nettestuser@$REALM || failed = ` expr $failed + 1`
test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
2008-03-28 13:57:15 +03:00
KRB5CCNAME = " $PREFIX /tmpccache "
export KRB5CCNAME
2010-11-16 08:01:19 +03:00
lowerrealm = $( echo $REALM | tr '[A-Z]' '[a-z]' )
test_smbclient "Test login with user kerberos lowercase realm" 'ls' -k yes -Unettestuser@$lowerrealm %$NEWUSERPASS || failed = ` expr $failed + 1`
test_smbclient "Test login with user kerberos lowercase realm 2" 'ls' -k yes -Unettestuser@$REALM %$NEWUSERPASS --realm= $lowerrealm || failed = ` expr $failed + 1`
2010-10-24 06:27:26 +04:00
testit "del user with kerberos ccache" $VALGRIND $samba_tool user delete nettestuser $CONFIGURATION -k yes $@ || failed = ` expr $failed + 1`
2007-04-16 08:55:52 +04:00
2010-02-20 03:44:41 +03:00
rm -f $KRB5CCNAME
2010-10-15 13:32:09 +04:00
testit "kinit with machineaccountccache script" $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed = ` expr $failed + 1`
2010-02-20 03:44:41 +03:00
test_smbclient "Test machine account login with kerberos ccache" 'ls' -k yes || failed = ` expr $failed + 1`
2011-06-28 00:49:43 +04:00
testit "reset password policies" $VALGRIND $samba_tool domain passwordsettings $PWSETCONFIG set --complexity= default --history-length= default --min-pwd-length= default --min-pwd-age= default --max-pwd-age= default || failed = ` expr $failed + 1`
2010-07-03 17:52:00 +04:00
2010-02-20 03:44:41 +03:00
rm -f $PREFIX /tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
2007-04-16 08:55:52 +04:00
exit $failed