2 # Blackbox tests for kinit and kerberos integration with smbclient etc
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
8 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX
23 samba4bindir="$BUILDDIR/bin"
24 smbclient="$samba4bindir/smbclient$EXEEXT"
25 samba4kinit="$samba4bindir/samba4kinit$EXEEXT"
26 net="$samba4bindir/net$EXEEXT"
27 ldbmodify="$samba4bindir/ldbmodify$EXEEXT"
28 ldbsearch="$samba4bindir/ldbsearch$EXEEXT"
29 rkpty="$samba4bindir/rkpty$EXEEXT"
30 samba4kpasswd="$samba4bindir/samba4kpasswd$EXEEXT"
31 enableaccount="$samba4bindir/net enableaccount"
32 machineaccountccache="$BUILDDIR/scripting/bin/machineaccountccache"
34 . `dirname $0`/subunit.sh
42 $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" -W "$DOMAIN" $@
44 if [ x$status = x0 ]; then
54 PWSETCONFIG="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
57 KRB5CCNAME="$PREFIX/tmpccache"
60 testit "reset password policies beside of minimum password age of 0 days" $VALGRIND $net pwsettings $PWSETCONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=0 --max-pwd-age=default || failed=`expr $failed + 1`
62 echo $PASSWORD > ./tmppassfile
63 #testit "kinit with keytab" $samba4kinit $enctype --keytab=$PREFIX/dc/private/secrets.keytab $SERVER\$@$REALM || failed=`expr $failed + 1`
64 testit "kinit with password" $samba4kinit $enctype --password-file=./tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
65 testit "kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file=./tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
66 testit "kinit with password (windows style)" $samba4kinit $enctype --renewable --windows --password-file=./tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
67 testit "kinit renew ticket" $samba4kinit $enctype --request-pac -R
69 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
71 testit "domain join with kerberos ccache" $VALGRIND $net join $DOMAIN $CONFIGURATION -W "$DOMAIN" -k yes $@ || failed=`expr $failed + 1`
72 testit "check time with kerberos ccache" $VALGRIND $net $CONFIGURATION -W "$DOMAIN" -k yes $@ time $SERVER || failed=`expr $failed + 1`
75 echo $USERPASS > ./tmpuserpassfile
76 testit "add user with kerberos ccache" $VALGRIND $net user add nettestuser $USERPASS $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
78 echo "Getting defaultNamingContext"
79 BASEDN=`$ldbsearch $options --basedn='' -H ldap://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
81 cat > ./tmpldbmodify <<EOF
82 dn: cn=nettestuser,cn=users,$BASEDN
84 add: servicePrincipalName
85 servicePrincipalName: host/nettestuser
88 testit "modify servicePrincipalName" $VALGRIND $ldbmodify -H ldap://$SERVER ./tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
90 testit "set user password with kerberos ccache" $VALGRIND $net password set $DOMAIN\\nettestuser $USERPASS $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
92 testit "enable user with kerberos cache" $VALGRIND $enableaccount nettestuser -H ldap://$SERVER -k yes $@ || failed=`expr $failed + 1`
94 KRB5CCNAME="$PREFIX/tmpuserccache"
97 testit "kinit with user password" $samba4kinit $enctype --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
99 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
101 NEWUSERPASS=testPaSS@34%
102 testit "change user password with 'net password change' (rpc)" $VALGRIND $net password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS $CONFIGURATION -k no $NEWUSERPASS $@ || failed=`expr $failed + 1`
104 echo $NEWUSERPASS > ./tmpuserpassfile
105 testit "kinit with user password" $samba4kinit $enctype --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
107 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
110 USERPASS=$NEWUSERPASS
111 NEWUSERPASS=testPaSS@56%
112 echo $NEWUSERPASS > ./tmpuserpassfile
114 cat > ./tmpkpasswdscript <<EOF
116 password ${USERPASS}\n
118 send ${NEWUSERPASS}\n
119 expect Verify password
120 send ${NEWUSERPASS}\n
124 testit "change user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
126 testit "kinit with user password" $samba4kinit $enctype --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
128 NEWUSERPASS=testPaSS@78%
129 echo $NEWUSERPASS > ./tmpuserpassfile
131 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
133 cat > ./tmpkpasswdscript <<EOF
135 send ${NEWUSERPASS}\n
136 expect Verify password
137 send ${NEWUSERPASS}\n
141 testit "set user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache nettestuser@$REALM || failed=`expr $failed + 1`
143 testit "kinit with user password" $samba4kinit $enctype --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
145 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
147 NEWUSERPASS=testPaSS@910%
148 echo $NEWUSERPASS > ./tmpuserpassfile
150 cat > ./tmpkpasswdscript <<EOF
152 send ${NEWUSERPASS}\n
153 expect Verify password
154 send ${NEWUSERPASS}\n
158 testit "set user password with kpasswd and servicePrincipalName" $rkpty ./tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache host/nettestuser@$REALM || failed=`expr $failed + 1`
160 testit "kinit with user password" $samba4kinit $enctype --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
162 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
164 KRB5CCNAME="$PREFIX/tmpccache"
167 testit "del user with kerberos ccache" $VALGRIND $net user delete nettestuser $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
170 testit "kinit with machineaccountccache script" $machineaccountccache $CONFIGURATTION $KRB5CCNAME || failed=`expr $failed + 1`
171 test_smbclient "Test machine account login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
173 testit "reset password policies" $VALGRIND $net pwsettings $PWSETCONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
175 rm -f $PREFIX/tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript