messaging3: Make the _send function return 0/errno
[Samba.git] / testprogs / blackbox / test_kinit.sh
blobadfed78255574e0ab0eda90a78a4110aabda70d2
1 #!/bin/sh
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>
6 if [ $# -lt 5 ]; then
7 cat <<EOF
8 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX ENCTYPE SMBCLIENT
9 EOF
10 exit 1;
13 SERVER=$1
14 USERNAME=$2
15 PASSWORD=$3
16 REALM=$4
17 DOMAIN=$5
18 PREFIX=$6
19 ENCTYPE=$7
20 smbclient=$8
21 shift 8
22 failed=0
24 samba4bindir="$BINDIR"
25 samba4srcdir="$SRCDIR/source4"
26 samba4kinit="$samba4bindir/samba4kinit"
27 samba_tool="$samba4bindir/samba-tool"
28 rkpty="$samba4bindir/rkpty"
29 samba4kpasswd="$samba4bindir/samba4kpasswd"
30 enableaccount="$samba_tool user enable"
31 machineaccountccache="$samba4srcdir/scripting/bin/machineaccountccache"
33 ldbmodify="ldbmodify"
34 if [ -x "$samba4bindir/ldbmodify" ]; then
35 ldbmodify="$samba4bindir/ldbmodify"
38 ldbsearch="ldbsearch"
39 if [ -x "$samba4bindir/ldbsearch" ]; then
40 ldbsearch="$samba4bindir/ldbsearch"
43 . `dirname $0`/subunit.sh
45 test_smbclient() {
46 name="$1"
47 cmd="$2"
48 shift
49 shift
50 echo "test: $name"
51 $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" $@
52 status=$?
53 if [ x$status = x0 ]; then
54 echo "success: $name"
55 else
56 echo "failure: $name"
58 return $status
61 enctype="-e $ENCTYPE"
63 PWSETCONFIG="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
64 export PWSETCONFIG
66 KRB5CCNAME="$PREFIX/tmpccache"
67 export KRB5CCNAME
69 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`
71 echo $PASSWORD > $PREFIX/tmppassfile
72 #testit "kinit with keytab" $samba4kinit $enctype --keytab=$PREFIX/dc/private/secrets.keytab $SERVER\$@$REALM || failed=`expr $failed + 1`
73 testit "kinit with password" $samba4kinit $enctype --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
74 testit "kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
75 testit "kinit with password (windows style)" $samba4kinit $enctype --renewable --windows --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
76 testit "kinit renew ticket" $samba4kinit $enctype --request-pac -R
78 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
80 testit "check time with kerberos ccache" $VALGRIND $samba_tool time $SERVER $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
82 USERPASS=testPass@12%
83 echo $USERPASS > $PREFIX/tmpuserpassfile
84 testit "add user with kerberos ccache" $VALGRIND $samba_tool user create nettestuser $USERPASS $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
86 echo "Getting defaultNamingContext"
87 BASEDN=`$ldbsearch $options --basedn='' -H ldap://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
89 cat > $PREFIX/tmpldbmodify <<EOF
90 dn: cn=nettestuser,cn=users,$BASEDN
91 changetype: modify
92 add: servicePrincipalName
93 servicePrincipalName: host/nettestuser
94 EOF
96 testit "modify servicePrincipalName" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
98 testit "set user password with kerberos ccache" $VALGRIND $samba_tool user setpassword nettestuser --newpassword=$USERPASS $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
100 testit "enable user with kerberos cache" $VALGRIND $enableaccount nettestuser -H ldap://$SERVER -k yes $@ || failed=`expr $failed + 1`
102 KRB5CCNAME="$PREFIX/tmpuserccache"
103 export KRB5CCNAME
105 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/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`
109 NEWUSERPASS=testPaSS@34%
110 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`
112 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
113 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
115 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
118 USERPASS=$NEWUSERPASS
119 NEWUSERPASS=testPaSS@56%
120 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
122 cat > $PREFIX/tmpkpasswdscript <<EOF
123 expect Password
124 password ${USERPASS}\n
125 expect New password
126 send ${NEWUSERPASS}\n
127 expect Verify password
128 send ${NEWUSERPASS}\n
129 expect Success
132 testit "change user password with kpasswd" $rkpty $PREFIX/tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
134 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
136 NEWUSERPASS=testPaSS@78%
137 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
139 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
141 cat > $PREFIX/tmpkpasswdscript <<EOF
142 expect New password
143 send ${NEWUSERPASS}\n
144 expect Verify password
145 send ${NEWUSERPASS}\n
146 expect Success
149 testit "set user password with kpasswd" $rkpty $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache nettestuser@$REALM || failed=`expr $failed + 1`
151 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
153 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
155 NEWUSERPASS=testPaSS@910%
156 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
158 cat > $PREFIX/tmpkpasswdscript <<EOF
159 expect New password
160 send ${NEWUSERPASS}\n
161 expect Verify password
162 send ${NEWUSERPASS}\n
163 expect Success
166 testit "set user password with kpasswd and servicePrincipalName" $rkpty $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache host/nettestuser@$REALM || failed=`expr $failed + 1`
168 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
170 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
172 cat > $PREFIX/tmpldbmodify <<EOF
173 dn: cn=nettestuser,cn=users,$BASEDN
174 changetype: modify
175 replace: pwdLastSet
176 pwdLastSet: 0
179 USERPASS=$NEWUSERPASS
180 NEWUSERPASS=testPaSS@911%
182 testit "modify pwdLastSet" $VALGRIND $ldbmodify $PWSETCONFIG $PREFIX/tmpldbmodify $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
184 cat > $PREFIX/tmppasswordchange <<EOF
185 expect nettestuser@${REALM}'s Password:
186 send ${USERPASS}\n
187 expect Your password will expire at
188 expect Changing password
189 expect New password:
190 send ${NEWUSERPASS}\n
191 expect Repeat new password:
192 send ${NEWUSERPASS}\n
193 expect Success: Password changed
196 testit "kinit with user password for expired password" $rkpty $PREFIX/tmppasswordchange $samba4kinit $enctype --request-pac nettestuser@$REALM && failed=`expr $failed + 1`
198 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
200 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
201 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
203 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
205 KRB5CCNAME="$PREFIX/tmpccache"
206 export KRB5CCNAME
208 lowerrealm=$(echo $REALM | tr '[A-Z]' '[a-z]')
209 test_smbclient "Test login with user kerberos lowercase realm" 'ls' -k yes -Unettestuser@$lowerrealm%$NEWUSERPASS || failed=`expr $failed + 1`
210 test_smbclient "Test login with user kerberos lowercase realm 2" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS --realm=$lowerrealm || failed=`expr $failed + 1`
212 testit "del user with kerberos ccache" $VALGRIND $samba_tool user delete nettestuser $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
214 rm -f $KRB5CCNAME
215 testit "kinit with machineaccountccache script" $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed=`expr $failed + 1`
216 test_smbclient "Test machine account login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
218 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`
220 rm -f $PREFIX/tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
221 exit $failed