testprogs: use texpect instead of rkpty.
[samba.git] / testprogs / blackbox / test_kinit.sh
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>
5
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;
11 fi
12
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
23
24 samba4bindir="$BINDIR"
25 samba4srcdir="$SRCDIR/source4"
26 samba4kinit=kinit
27 if test -x $BINDIR/samba4kinit; then
28         samba4kinit=$BINDIR/samba4kinit
29 fi
30
31 samba_tool="$samba4bindir/samba-tool"
32 texpect="$samba4bindir/texpect"
33 samba4kpasswd=kpasswd
34 if test -x $BINDIR/samba4kpasswd; then
35         samba4kpasswd=$BINDIR/samba4kpasswd
36 fi
37
38 enableaccount="$samba_tool user enable"
39 machineaccountccache="$samba4srcdir/scripting/bin/machineaccountccache"
40
41 ldbmodify="ldbmodify"
42 if [ -x "$samba4bindir/ldbmodify" ]; then
43         ldbmodify="$samba4bindir/ldbmodify"
44 fi
45
46 ldbsearch="ldbsearch"
47 if [ -x "$samba4bindir/ldbsearch" ]; then
48         ldbsearch="$samba4bindir/ldbsearch"
49 fi
50
51 . `dirname $0`/subunit.sh
52
53 test_smbclient() {
54         name="$1"
55         cmd="$2"
56         shift
57         shift
58         echo "test: $name"
59         $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" $@
60         status=$?
61         if [ x$status = x0 ]; then
62                 echo "success: $name"
63         else
64                 echo "failure: $name"
65         fi
66         return $status
67 }
68
69 enctype="-e $ENCTYPE"
70
71 PWSETCONFIG="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
72 export PWSETCONFIG
73
74 KRB5CCNAME="$PREFIX/tmpccache"
75 export KRB5CCNAME
76
77 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`
78
79 echo $PASSWORD > $PREFIX/tmppassfile
80 #testit "kinit with keytab" $samba4kinit $enctype --keytab=$PREFIX/dc/private/secrets.keytab $SERVER\$@$REALM   || failed=`expr $failed + 1`
81 testit "kinit with password" $samba4kinit $enctype --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
82 testit "kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
83 testit "kinit with password (windows style)" $samba4kinit $enctype  --renewable --windows --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
84 testit "kinit renew ticket" $samba4kinit $enctype --request-pac -R
85
86 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
87
88 testit "check time with kerberos ccache" $VALGRIND $samba_tool time $SERVER $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
89
90 USERPASS=testPass@12%
91 echo $USERPASS > $PREFIX/tmpuserpassfile
92 testit "add user with kerberos ccache" $VALGRIND $samba_tool user create nettestuser $USERPASS $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
93
94 echo "Getting defaultNamingContext"
95 BASEDN=`$ldbsearch $options --basedn='' -H ldap://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
96
97 cat > $PREFIX/tmpldbmodify <<EOF
98 dn: cn=nettestuser,cn=users,$BASEDN
99 changetype: modify
100 add: servicePrincipalName
101 servicePrincipalName: host/nettestuser
102 EOF
103
104 testit "modify servicePrincipalName" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
105
106 testit "set user password with kerberos ccache" $VALGRIND $samba_tool user setpassword nettestuser --newpassword=$USERPASS $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
107
108 testit "enable user with kerberos cache" $VALGRIND $enableaccount nettestuser -H ldap://$SERVER -k yes $@ || failed=`expr $failed + 1`
109
110 KRB5CCNAME="$PREFIX/tmpuserccache"
111 export KRB5CCNAME
112
113 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
114
115 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
116
117 NEWUSERPASS=testPaSS@34%
118 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`
119
120 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
121 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
122
123 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
124
125
126 USERPASS=$NEWUSERPASS
127 NEWUSERPASS=testPaSS@56%
128 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
129
130 cat > $PREFIX/tmpkpasswdscript <<EOF
131 expect Password
132 password ${USERPASS}\n
133 expect New password
134 send ${NEWUSERPASS}\n
135 expect Verify password
136 send ${NEWUSERPASS}\n
137 expect Success
138 EOF
139
140 testit "change user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
141
142 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
143
144 NEWUSERPASS=testPaSS@78%
145 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
146
147 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
148
149 cat > $PREFIX/tmpkpasswdscript <<EOF
150 expect New password
151 send ${NEWUSERPASS}\n
152 expect Verify password
153 send ${NEWUSERPASS}\n
154 expect Success
155 EOF
156
157 testit "set user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache nettestuser@$REALM || failed=`expr $failed + 1`
158
159 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
160
161 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
162
163 NEWUSERPASS=testPaSS@910%
164 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
165
166 cat > $PREFIX/tmpkpasswdscript <<EOF
167 expect New password
168 send ${NEWUSERPASS}\n
169 expect Verify password
170 send ${NEWUSERPASS}\n
171 expect Success
172 EOF
173
174 testit "set user password with kpasswd and servicePrincipalName" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache host/nettestuser@$REALM || failed=`expr $failed + 1`
175
176 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
177
178 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
179
180 cat > $PREFIX/tmpldbmodify <<EOF
181 dn: cn=nettestuser,cn=users,$BASEDN
182 changetype: modify
183 replace: pwdLastSet
184 pwdLastSet: 0
185 EOF
186
187 USERPASS=$NEWUSERPASS
188 NEWUSERPASS=testPaSS@911%
189
190 testit "modify pwdLastSet" $VALGRIND $ldbmodify $PWSETCONFIG $PREFIX/tmpldbmodify $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
191
192 cat > $PREFIX/tmppasswordchange <<EOF
193 expect nettestuser@${REALM}'s Password: 
194 send ${USERPASS}\n
195 expect Your password will expire at
196 expect Changing password
197 expect New password:
198 send ${NEWUSERPASS}\n
199 expect Repeat new password:
200 send ${NEWUSERPASS}\n
201 expect Success: Password changed
202 EOF
203
204 testit "kinit with user password for expired password" $texpect $PREFIX/tmppasswordchange $samba4kinit $enctype --request-pac nettestuser@$REALM && failed=`expr $failed + 1`
205
206 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
207
208 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
209 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
210
211 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
212
213 KRB5CCNAME="$PREFIX/tmpccache"
214 export KRB5CCNAME
215
216 lowerrealm=$(echo $REALM | tr '[A-Z]' '[a-z]')
217 test_smbclient "Test login with user kerberos lowercase realm" 'ls' -k yes -Unettestuser@$lowerrealm%$NEWUSERPASS || failed=`expr $failed + 1`
218 test_smbclient "Test login with user kerberos lowercase realm 2" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS --realm=$lowerrealm || failed=`expr $failed + 1`
219
220 testit "del user with kerberos ccache" $VALGRIND $samba_tool user delete nettestuser $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
221
222 rm -f $KRB5CCNAME
223 testit "kinit with machineaccountccache script" $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed=`expr $failed + 1`
224 test_smbclient "Test machine account login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
225
226 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`
227
228 rm -f $PREFIX/tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
229 exit $failed