CVE-2020-25718 kdc: Confirm the RODC was allowed to issue a particular ticket
[Samba.git] / testprogs / blackbox / test_kpasswd_mit.sh
blobdf0f53e00419355737eaef0e0d8593277485997a
1 #!/bin/sh
2 # Blackbox tests for chainging passwords with kinit and kpasswd
4 # Copyright (c) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
5 # Copyright (c) 2006-2008 Andrew Bartlett <abartlet@samba.org>
6 # Copyright (c) 2016 Andreas Schneider <asn@samba.org>
8 if [ $# -lt 6 ]; then
9 cat <<EOF
10 Usage: test_kpasswd_mit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX
11 EOF
12 exit 1;
15 SERVER=$1
16 USERNAME=$2
17 PASSWORD=$3
18 REALM=$4
19 DOMAIN=$5
20 PREFIX=$6
21 shift 6
22 failed=0
24 samba_bindir="$BINDIR"
26 samba_kinit=kinit
27 samba_kpasswd=kpasswd
29 smbclient="$samba_bindir/smbclient"
30 samba_tool="$samba_bindir/samba-tool"
31 net_tool="$samba_bindir/net"
32 texpect="$samba_bindir/texpect"
34 newuser="$samba_tool user create"
35 SMB_UNC="//$SERVER/tmp"
37 . `dirname $0`/subunit.sh
38 . `dirname $0`/common_test_fns.inc
40 do_kinit() {
41 principal="$1"
42 password="$2"
43 shift
44 shift
45 echo $password | $samba_kinit $principal
48 UID_WRAPPER_ROOT=1
49 export UID_WRAPPER_ROOT
51 CONFIG="--configfile=$PREFIX/etc/smb.conf"
52 export CONFIG
54 testit "reset password policies beside of minimum password age of 0 days" \
55 $VALGRIND $PYTHON $samba_tool domain passwordsettings set $CONFIG --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=0 --max-pwd-age=default || failed=`expr $failed + 1`
57 TEST_USERNAME="samson"
58 TEST_PASSWORD="testPaSS@00%"
59 TEST_PASSWORD_NEW="testPaSS@01%"
60 TEST_PASSWORD_SHORT="secret"
61 TEST_PASSWORD_WEAK="Supersecret"
62 TEST_PRINCIPAL="$TEST_USERNAME@$REALM"
64 testit "create user locally" \
65 $VALGRIND $PYTHON $newuser $CONFIG $TEST_USERNAME $TEST_PASSWORD || failed=`expr $failed + 1`
67 KRB5CCNAME="$PREFIX/tmpuserccache"
68 export KRB5CCNAME
70 testit "kinit with user password" \
71 do_kinit $TEST_PRINCIPAL $TEST_PASSWORD || failed=`expr $failed + 1`
73 test_smbclient "Test login with user kerberos ccache" \
74 "ls" "$SMB_UNC" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
76 testit "change user password with 'samba-tool user password' (unforced)" \
77 $VALGRIND $PYTHON $samba_tool user password -W$DOMAIN -U$TEST_USERNAME%$TEST_PASSWORD --use-kerberos=off --newpassword=$TEST_PASSWORD_NEW || failed=`expr $failed + 1`
79 TEST_PASSWORD_OLD=$TEST_PASSWORD
80 TEST_PASSWORD=$TEST_PASSWORD_NEW
81 TEST_PASSWORD_NEW="testPaSS@02%"
83 testit "kinit with user password" \
84 do_kinit $TEST_PRINCIPAL $TEST_PASSWORD || failed=`expr $failed + 1`
86 test_smbclient "Test login with user kerberos ccache" \
87 "ls" "$SMB_UNC" --use-krb5-ccache=$KRB5CCNAME || failed=`expr $failed + 1`
89 ###########################################################
90 ### check that a password mismatch is detected
91 ###########################################################
93 cat > $PREFIX/tmpkpasswdscript <<EOF
94 expect Password for $TEST_PRINCIPAL
95 password ${TEST_PASSWORD}\n
96 expect Enter new password
97 send ${TEST_PASSWORD_WEAK}\n
98 expect Enter it again
99 send ${TEST_PASSWORD_NEW}\n
100 expect kpasswd: Password mismatch while reading password
103 testit_expect_failure "kpasswd check password mismatch" \
104 $texpect $PREFIX/tmpkpasswdscript $samba_kpasswd $TEST_PRINCIPAL && failed=`expr $failed + 1`
106 ###########################################################
107 ### check that a short password is rejected
108 ###########################################################
110 cat > $PREFIX/tmpkpasswdscript <<EOF
111 expect Password for $TEST_PRINCIPAL
112 password ${TEST_PASSWORD}\n
113 expect Enter new password
114 send ${TEST_PASSWORD_SHORT}\n
115 expect Enter it again
116 send ${TEST_PASSWORD_SHORT}\n
117 expect Password change rejected: Password too short, password must be at least 7 characters long
120 testit_expect_failure "kpasswd check short user password" \
121 $texpect $PREFIX/tmpkpasswdscript $samba_kpasswd $TEST_PRINCIPAL && failed=`expr $failed + 1`
123 ###########################################################
124 ### check that a weak password is rejected
125 ###########################################################
127 cat > $PREFIX/tmpkpasswdscript <<EOF
128 expect Password for $TEST_PRINCIPAL
129 password ${TEST_PASSWORD}\n
130 expect Enter new password
131 send ${TEST_PASSWORD_WEAK}\n
132 expect Enter it again
133 send ${TEST_PASSWORD_WEAK}\n
134 expect Password change rejected: Password does not meet complexity requirement
137 testit_expect_failure "kpasswd check weak user password" \
138 $texpect $PREFIX/tmpkpasswdscript $samba_kpasswd $TEST_PRINCIPAL && failed=`expr $failed + 1`
140 ###########################################################
141 ### check that a strong password is accepted
142 ###########################################################
144 cat > $PREFIX/tmpkpasswdscript <<EOF
145 expect Password for $TEST_PRINCIPAL
146 password ${TEST_PASSWORD}\n
147 expect Enter new password
148 send ${TEST_PASSWORD_NEW}\n
149 expect Enter it again
150 send ${TEST_PASSWORD_NEW}\n
151 expect Password changed.
154 testit "kpasswd change user password" \
155 $texpect $PREFIX/tmpkpasswdscript $samba_kpasswd $TEST_PRINCIPAL|| failed=`expr $failed + 1`
157 TEST_PASSWORD=$TEST_PASSWORD_NEW
158 TEST_PASSWORD_NEW="testPaSS@03%"
160 test_smbclient "Test login with user kerberos" 'ls' "$SMB_UNC" --use-kerberos=required -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed=`expr $failed + 1`
162 ###########################################################
163 ### Force password change at login
164 ###########################################################
166 testit "set password on user locally" \
167 $VALGRIND $PYTHON $samba_tool user setpassword $TEST_USERNAME $CONFIG --newpassword=$TEST_PASSWORD_NEW --must-change-at-next-login || failed=`expr $failed + 1`
169 TEST_PASSWORD=$TEST_PASSWORD_NEW
170 TEST_PASSWORD_NEW="testPaSS@04%"
172 cat > $PREFIX/tmpkinitscript <<EOF
173 expect Password for $TEST_PRINCIPAL
174 password ${TEST_PASSWORD}\n
175 expect Password expired
176 expect Enter new password
177 send ${TEST_PASSWORD_NEW}\n
178 expect Enter it again
179 send ${TEST_PASSWORD_NEW}\n
182 testit "kinit and change user password" \
183 $texpect $PREFIX/tmpkinitscript $samba_kinit $TEST_PRINCIPAL|| failed=`expr $failed + 1`
185 TEST_PASSWORD=$TEST_PASSWORD_NEW
186 TEST_PASSWORD_NEW="testPaSS@05%"
188 test_smbclient "Test login with user kerberos" \
189 "ls" "$SMB_UNC" --use-kerberos=required -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed=`expr $failed + 1`
191 ###########################################################
192 ### Test kpasswd service via 'net ads password'
193 ###########################################################
195 testit "change user password with 'net ads password', admin: $DOMAIN/$TEST_USERNAME, target: $TEST_PRINCIPAL" \
196 $VALGRIND $net_tool ads password -W$DOMAIN -U$TEST_PRINCIPAL%$TEST_PASSWORD $TEST_PRINCIPAL "$TEST_PASSWORD_NEW" || failed=`expr $failed + 1`
198 #TEST_PASSWORD=$TEST_PASSWORD_NEW
199 #TEST_PASSWORD_NEW="testPaSS@06%"
201 #test_smbclient "Test login with smbclient (ntlm)" \
202 # "ls" "$SMB_UNC" --use-kerberos=disabled -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed=`expr $failed + 1`
204 ###########################################################
205 ### Test kpasswd service via 'net ads password' as admin
206 ###########################################################
208 testit "set user password with 'net ads password', admin: $DOMAIN/$USERNAME, target: $TEST_PRINCIPAL" \
209 $VALGRIND $net_tool ads password -W$DOMAIN -U$USERNAME@$REALM%$PASSWORD $TEST_PRINCIPAL "$TEST_PASSWORD_NEW" || failed=`expr $failed + 1`
211 TEST_PASSWORD=$TEST_PASSWORD_NEW
212 TEST_PASSWORD_NEW="testPaSS@07%"
214 test_smbclient "Test login with smbclient (ntlm)" \
215 "ls" "$SMB_UNC" --use-kerberos=disabled -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed=`expr $failed + 1`
217 ###########################################################
218 ### Cleanup
219 ###########################################################
221 testit "reset password policies" \
222 $VALGRIND $PYTHON $samba_tool domain passwordsettings set $CONFIG --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
224 testit "delete user" \
225 $VALGRIND $PYTHON $samba_tool user delete $TEST_USERNAME -U"$USERNAME%$PASSWORD" $CONFIG -k no || failed=`expr $failed + 1`
227 rm -f $PREFIX/tmpuserccache $PREFIX/tmpkpasswdscript $PREFIX/tmpkinitscript
228 exit $failed