CVE-2020-25718 tests/krb5: Fix indentation
[Samba.git] / testprogs / blackbox / test_kinit_heimdal.sh
blob7a3ff6841353d7b600650dd8bdd19af58904c022
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_binary=kinit
27 if test -x $BINDIR/samba4kinit; then
28 samba4kinit_binary=$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
52 . `dirname $0`/common_test_fns.inc
54 enctype="-e $ENCTYPE"
55 unc="//$SERVER/tmp"
57 ADMIN_LDBMODIFY_CONFIG="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
58 export ADMIN_LDBMODIFY_CONFIG
60 KRB5CCNAME_PATH="$PREFIX/tmpccache"
61 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
62 samba4kinit="$samba4kinit_binary -c $KRB5CCNAME"
63 ADMIN_KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
64 export KRB5CCNAME
65 rm -rf $KRB5CCNAME_PATH
67 testit "reset password policies beside of minimum password age of 0 days" $VALGRIND $PYTHON $samba_tool domain passwordsettings set $ADMIN_LDBMODIFY_CONFIG --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=0 --max-pwd-age=default || failed=`expr $failed + 1`
69 echo $PASSWORD > $PREFIX/tmppassfile
70 testit "kinit with password (initial)" $samba4kinit $enctype --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
71 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
73 testit "kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
74 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
76 testit "kinit with password (windows style)" $samba4kinit $enctype --renewable --windows --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM || failed=`expr $failed + 1`
77 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
79 testit "kinit renew ticket" $samba4kinit $enctype --request-pac -R
81 test_smbclient "Test login with kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
83 testit "check time with kerberos ccache" $VALGRIND $PYTHON $samba_tool time $SERVER $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
85 USERPASS=testPass@12%
86 echo $USERPASS > $PREFIX/tmpuserpassfile
87 testit "add user with kerberos ccache" $VALGRIND $PYTHON $samba_tool user create nettestuser $USERPASS $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
89 echo "Getting defaultNamingContext"
90 BASEDN=`$ldbsearch $options --basedn='' -H ldap://$SERVER --scope=base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
92 cat > $PREFIX/tmpldbmodify <<EOF
93 dn: cn=nettestuser,cn=users,$BASEDN
94 changetype: modify
95 add: servicePrincipalName
96 servicePrincipalName: host/nettestuser
97 replace: userPrincipalName
98 userPrincipalName: nettest@$REALM
99 EOF
101 testit "modify servicePrincipalName and userPrincpalName" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
103 testit "set user password with kerberos ccache" $VALGRIND $PYTHON $samba_tool user setpassword nettestuser --newpassword=$USERPASS $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
105 testit "enable user with kerberos cache" $VALGRIND $PYTHON $enableaccount nettestuser -H ldap://$SERVER -k yes $@ || failed=`expr $failed + 1`
107 KRB5CCNAME_PATH="$PREFIX/tmpuserccache"
108 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
109 samba4kinit="$samba4kinit_binary -c $KRB5CCNAME"
110 export KRB5CCNAME
112 rm -f $KRB5CCNAME_PATH
113 testit "kinit with user password (after enable of user and password change)" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
115 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
117 NEWUSERPASS=testPaSS@34%
118 testit "change user password with 'samba-tool user password' (rpc)" $VALGRIND $PYTHON $samba_tool user password -W$DOMAIN -Unettestuser%$USERPASS $CONFIGURATION -k no --newpassword=$NEWUSERPASS $@ || failed=`expr $failed + 1`
120 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
121 rm -f $KRB5CCNAME_PATH
122 testit "kinit with user password (after rpc password change)" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
124 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
127 rm -f $KRB5CCNAME_PATH
128 testit "kinit with password (NT-Principal style) using UPN" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM || failed=`expr $failed + 1`
129 test_smbclient "Test login with user kerberos ccache from enterprise UPN" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
131 rm -f $KRB5CCNAME_PATH
132 testit "kinit with password (enterprise style) using UPN" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM || failed=`expr $failed + 1`
133 test_smbclient "Test login with user kerberos ccache from enterprise UPN" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
135 rm -f $KRB5CCNAME_PATH
136 testit "kinit with password (windows style) using UPN" $samba4kinit $enctype --renewable --windows --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM || failed=`expr $failed + 1`
137 test_smbclient "Test login with user kerberos ccache from windows UPN" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
139 cat > $PREFIX/tmpldbmodify <<EOF
140 dn: cn=nettestuser,cn=users,$BASEDN
141 changetype: modify
142 replace: userPrincipalName
143 userPrincipalName: nettest@$REALM.org
146 testit "modify userPrincipalName to be a different domain" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
148 rm -f $KRB5CCNAME_PATH
149 testit "kinit with password (enterprise style) using UPN" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmpuserpassfile --request-pac nettest@$REALM.org || failed=`expr $failed + 1`
150 test_smbclient "Test login with user kerberos ccache from enterprise UPN, different domain" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
153 USERPASS=$NEWUSERPASS
154 NEWUSERPASS=testPaSS@56%
155 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
157 cat > $PREFIX/tmpkpasswdscript <<EOF
158 expect Password
159 password ${USERPASS}\n
160 expect New password
161 send ${NEWUSERPASS}\n
162 expect Verify password
163 send ${NEWUSERPASS}\n
164 expect Success
167 testit "change user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
169 rm -f $KRB5CCNAME_PATH
170 testit "kinit with user password (after kpasswd change)" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
172 NEWUSERPASS=testPaSS@78%
173 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
175 test_smbclient "Test login with user kerberos ccache (after kpasswd change)" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
177 cat > $PREFIX/tmpkpasswdscript <<EOF
178 expect New password
179 send ${NEWUSERPASS}\n
180 expect Verify password
181 send ${NEWUSERPASS}\n
182 expect Success
185 testit "set user password with kpasswd" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$ADMIN_KRB5CCNAME nettestuser@$REALM || failed=`expr $failed + 1`
187 rm -f $KRB5CCNAME_PATH
188 testit "kinit with user password (after kpasswd set)" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
190 test_smbclient "Test login with user kerberos ccache (after kpasswd set)" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
192 NEWUSERPASS=testPaSS@910%
193 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
195 cat > $PREFIX/tmpkpasswdscript <<EOF
196 expect New password
197 send ${NEWUSERPASS}\n
198 expect Verify password
199 send ${NEWUSERPASS}\n
200 expect Success
203 testit "set user password with kpasswd and servicePrincipalName" $texpect $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache host/nettestuser@$REALM || failed=`expr $failed + 1`
205 testit "kinit with user password (after set with kpasswd and spn)" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
207 test_smbclient "Test login with user kerberos ccache (after set with kpasswd and spn)" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
209 cat > $PREFIX/tmpldbmodify <<EOF
210 dn: cn=nettestuser,cn=users,$BASEDN
211 changetype: modify
212 replace: pwdLastSet
213 pwdLastSet: 0
216 USERPASS=$NEWUSERPASS
217 NEWUSERPASS=testPaSS@911%
219 testit "modify pwdLastSet" $VALGRIND $ldbmodify $ADMIN_LDBMODIFY_CONFIG $PREFIX/tmpldbmodify $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
221 cat > $PREFIX/tmppasswordchange <<EOF
222 expect nettestuser@${REALM}'s Password:
223 send ${USERPASS}\n
224 expect Your password will expire at
225 expect Changing password
226 expect New password:
227 send ${NEWUSERPASS}\n
228 expect Repeat new password:
229 send ${NEWUSERPASS}\n
230 expect Success: Password changed
233 testit "kinit with user password for expired password" $texpect $PREFIX/tmppasswordchange $samba4kinit $enctype --request-pac nettestuser@$REALM && failed=`expr $failed + 1`
235 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
237 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
238 testit "kinit with user password (after password change forced by expiration)" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
240 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
242 KRB5CCNAME_PATH="$PREFIX/tmpccache"
243 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
244 samba4kinit="$samba4kinit_binary -c $KRB5CCNAME"
245 export KRB5CCNAME
247 rm -rf $KRB5CCNAME_PATH
249 lowerrealm=$(echo $REALM | tr '[A-Z]' '[a-z]')
250 test_smbclient "Test login with user kerberos lowercase realm" 'ls' "$unc" --use-kerberos=required -Unettestuser@$lowerrealm%$NEWUSERPASS || failed=`expr $failed + 1`
251 test_smbclient "Test login with user kerberos lowercase realm 2" 'ls' "$unc" --use-kerberos=required -Unettestuser@$REALM%$NEWUSERPASS --realm=$lowerrealm || failed=`expr $failed + 1`
253 testit "del user with kerberos ccache" $VALGRIND $PYTHON $samba_tool user delete nettestuser $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
255 rm -f $KRB5CCNAME_PATH
256 testit "kinit with machineaccountccache script" $PYTHON $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed=`expr $failed + 1`
257 test_smbclient "Test machine account login with kerberos ccache" 'ls' "$unc" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
259 testit "reset password policies" $VALGRIND $PYTHON $samba_tool domain passwordsettings set $ADMIN_LDBMODIFY_CONFIG --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
261 rm -f $PREFIX/tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
262 exit $failed