lib: Remove unused parmlist code
[Samba.git] / testprogs / blackbox / test_kinit.sh
blob9df13a70a2c46523849137a2ed49467522f1dcef
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=kinit
27 if test -x $BINDIR/samba4kinit; then
28 samba4kinit=$BINDIR/samba4kinit
31 samba_tool="$samba4bindir/samba-tool"
32 texpect="$samba4bindir/texpect"
33 samba4kpasswd=kpasswd
34 if test -x $BINDIR/samba4kpasswd; then
35 samba4kpasswd=$BINDIR/samba4kpasswd
38 enableaccount="$samba_tool user enable"
39 machineaccountccache="$samba4srcdir/scripting/bin/machineaccountccache"
41 ldbmodify="ldbmodify"
42 if [ -x "$samba4bindir/ldbmodify" ]; then
43 ldbmodify="$samba4bindir/ldbmodify"
46 ldbsearch="ldbsearch"
47 if [ -x "$samba4bindir/ldbsearch" ]; then
48 ldbsearch="$samba4bindir/ldbsearch"
51 . `dirname $0`/subunit.sh
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"
66 return $status
69 enctype="-e $ENCTYPE"
71 ADMIN_LDBMODIFY_CONFIG="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
72 export ADMIN_LDBMODIFY_CONFIG
74 KRB5CCNAME_PATH="$PREFIX/tmpccache"
75 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
76 ADMIN_KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
77 export KRB5CCNAME
78 rm -rf $KRB5CCNAME_PATH
80 testit "reset password policies beside of minimum password age of 0 days" $VALGRIND $samba_tool domain passwordsettings $ADMIN_LDBMODIFY_CONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=0 --max-pwd-age=default || failed=`expr $failed + 1`
82 echo $PASSWORD > $PREFIX/tmppassfile
83 testit "kinit with password" $samba4kinit $enctype --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
84 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
86 testit "kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
87 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
89 testit "kinit with password (windows style)" $samba4kinit $enctype --renewable --windows --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
90 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
92 testit "kinit renew ticket" $samba4kinit $enctype --request-pac -R
94 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
96 testit "check time with kerberos ccache" $VALGRIND $samba_tool time $SERVER $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
98 USERPASS=testPass@12%
99 echo $USERPASS > $PREFIX/tmpuserpassfile
100 testit "add user with kerberos ccache" $VALGRIND $samba_tool user create nettestuser $USERPASS $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
102 echo "Getting defaultNamingContext"
103 BASEDN=`$ldbsearch $options --basedn='' -H ldap://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
105 cat > $PREFIX/tmpldbmodify <<EOF
106 dn: cn=nettestuser,cn=users,$BASEDN
107 changetype: modify
108 add: servicePrincipalName
109 servicePrincipalName: host/nettestuser
110 replace: userPrincipalName
111 userPrincipalName: nettest@$REALM
114 testit "modify servicePrincipalName and userPrincpalName" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
116 testit "set user password with kerberos ccache" $VALGRIND $samba_tool user setpassword nettestuser --newpassword=$USERPASS $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
118 testit "enable user with kerberos cache" $VALGRIND $enableaccount nettestuser -H ldap://$SERVER -k yes $@ || failed=`expr $failed + 1`
120 KRB5CCNAME_PATH="$PREFIX/tmpuserccache"
121 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
122 export KRB5CCNAME
124 rm -f $KRB5CCNAME_PATH
125 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
127 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
129 NEWUSERPASS=testPaSS@34%
130 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`
132 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
133 rm -f $KRB5CCNAME_PATH
134 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
136 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
139 rm -f $KRB5CCNAME_PATH
140 testit "kinit with password (NT-Principal style) using UPN" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM || failed=`expr $failed + 1`
141 test_smbclient "Test login with user kerberos ccache from enterprise UPN" 'ls' -k yes || failed=`expr $failed + 1`
143 rm -f $KRB5CCNAME_PATH
144 testit "kinit with password (enterprise style) using UPN" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM || failed=`expr $failed + 1`
145 test_smbclient "Test login with user kerberos ccache from enterprise UPN" 'ls' -k yes || failed=`expr $failed + 1`
147 rm -f $KRB5CCNAME_PATH
148 testit "kinit with password (windows style) using UPN" $samba4kinit $enctype --renewable --windows --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM || failed=`expr $failed + 1`
149 test_smbclient "Test login with user kerberos ccache from windows UPN" 'ls' -k yes || failed=`expr $failed + 1`
151 cat > $PREFIX/tmpldbmodify <<EOF
152 dn: cn=nettestuser,cn=users,$BASEDN
153 changetype: modify
154 replace: userPrincipalName
155 userPrincipalName: nettest@$REALM.org
158 testit "modify userPrincipalName to be a different domain" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
160 rm -f $KRB5CCNAME_PATH
161 testit "kinit with password (enterprise style) using UPN" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM.org || failed=`expr $failed + 1`
162 test_smbclient "Test login with user kerberos ccache from enterprise UPN, different domain" 'ls' -k yes || failed=`expr $failed + 1`
165 USERPASS=$NEWUSERPASS
166 NEWUSERPASS=testPaSS@56%
167 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
169 cat > $PREFIX/tmpkpasswdscript <<EOF
170 expect Password
171 password ${USERPASS}\n
172 expect New password
173 send ${NEWUSERPASS}\n
174 expect Verify password
175 send ${NEWUSERPASS}\n
176 expect Success
179 testit "change user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
181 rm -f $KRB5CCNAME_PATH
182 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
184 NEWUSERPASS=testPaSS@78%
185 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
187 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
189 cat > $PREFIX/tmpkpasswdscript <<EOF
190 expect New password
191 send ${NEWUSERPASS}\n
192 expect Verify password
193 send ${NEWUSERPASS}\n
194 expect Success
197 testit "set user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$ADMIN_KRB5CCNAME nettestuser@$REALM || failed=`expr $failed + 1`
199 rm -f $KRB5CCNAME_PATH
200 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
202 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
204 NEWUSERPASS=testPaSS@910%
205 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
207 cat > $PREFIX/tmpkpasswdscript <<EOF
208 expect New password
209 send ${NEWUSERPASS}\n
210 expect Verify password
211 send ${NEWUSERPASS}\n
212 expect Success
215 testit "set user password with kpasswd and servicePrincipalName" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache host/nettestuser@$REALM || failed=`expr $failed + 1`
217 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
219 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
221 cat > $PREFIX/tmpldbmodify <<EOF
222 dn: cn=nettestuser,cn=users,$BASEDN
223 changetype: modify
224 replace: pwdLastSet
225 pwdLastSet: 0
228 USERPASS=$NEWUSERPASS
229 NEWUSERPASS=testPaSS@911%
231 testit "modify pwdLastSet" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
233 cat > $PREFIX/tmppasswordchange <<EOF
234 expect nettestuser@${REALM}'s Password:
235 send ${USERPASS}\n
236 expect Your password will expire at
237 expect Changing password
238 expect New password:
239 send ${NEWUSERPASS}\n
240 expect Repeat new password:
241 send ${NEWUSERPASS}\n
242 expect Success: Password changed
245 testit "kinit with user password for expired password" $texpect $PREFIX/tmppasswordchange $samba4kinit $enctype --request-pac nettestuser@$REALM && failed=`expr $failed + 1`
247 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
249 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
250 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
252 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
254 KRB5CCNAME_PATH="$PREFIX/tmpccache"
255 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
256 export KRB5CCNAME
258 rm -rf $KRB5CCNAME_PATH
260 lowerrealm=$(echo $REALM | tr '[A-Z]' '[a-z]')
261 test_smbclient "Test login with user kerberos lowercase realm" 'ls' -k yes -Unettestuser@$lowerrealm%$NEWUSERPASS || failed=`expr $failed + 1`
262 test_smbclient "Test login with user kerberos lowercase realm 2" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS --realm=$lowerrealm || failed=`expr $failed + 1`
264 testit "del user with kerberos ccache" $VALGRIND $samba_tool user delete nettestuser $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
266 rm -f $KRB5CCNAME_PATH
267 testit "kinit with machineaccountccache script" $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed=`expr $failed + 1`
268 test_smbclient "Test machine account login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
270 testit "reset password policies" $VALGRIND $samba_tool domain passwordsettings $ADMIN_LDBMODIFY_CONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
272 rm -f $PREFIX/tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
273 exit $failed