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>
10 Usage: test_passwords.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX SMBCLIENT
24 samba_bindir
="$BINDIR"
26 smbclient
="$samba_bindir/smbclient"
27 samba_kinit
=$samba_bindir/samba4kinit
28 samba_kpasswd
=$samba_bindir/samba4kpasswd
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
45 echo $password > $PREFIX/tmppassfile
46 $samba_kinit --password-file=$PREFIX/tmppassfile
$principal $@
50 export UID_WRAPPER_ROOT
52 CONFIG
="--configfile=$PREFIX/etc/smb.conf"
55 testit
"reset password policies beside of minimum password age of 0 days" \
56 $VALGRIND $samba_tool domain passwordsettings
$CONFIG set --complexity=default
--history-length=default
--min-pwd-length=default
--min-pwd-age=0 --max-pwd-age=default || failed
=`expr $failed + 1`
58 TEST_USERNAME
="$(mktemp -u alice-XXXXXX)"
59 TEST_PRINCIPAL
="$TEST_USERNAME@$REALM"
60 TEST_PASSWORD
="testPaSS@00%"
61 TEST_PASSWORD_NEW
="testPaSS@01%"
62 TEST_PASSWORD_SHORT
="secret"
63 TEST_PASSWORD_WEAK
="Supersecret"
65 testit
"create user locally" \
66 $VALGRIND $newuser $CONFIG $TEST_USERNAME $TEST_PASSWORD || failed
=`expr $failed + 1`
68 KRB5CCNAME
="$PREFIX/tmpuserccache"
71 testit
"kinit with user password" \
72 do_kinit
$TEST_PRINCIPAL $TEST_PASSWORD || failed
=`expr $failed + 1`
74 test_smbclient
"Test login with user kerberos ccache" \
75 "ls" "$SMB_UNC" -k yes || failed
=`expr $failed + 1`
77 testit
"change user password with 'samba-tool user password' (unforced)" \
78 $VALGRIND $samba_tool user password
-W$DOMAIN -U$TEST_USERNAME%$TEST_PASSWORD -k no
--newpassword=$TEST_PASSWORD_NEW || failed
=`expr $failed + 1`
80 TEST_PASSWORD_OLD
=$TEST_PASSWORD
81 TEST_PASSWORD
=$TEST_PASSWORD_NEW
82 TEST_PASSWORD_NEW
="testPaSS@02%"
84 testit
"kinit with user password" \
85 do_kinit
$TEST_PRINCIPAL $TEST_PASSWORD || failed
=`expr $failed + 1`
87 test_smbclient
"Test login with user kerberos ccache" \
88 "ls" "$SMB_UNC" -k yes || failed
=`expr $failed + 1`
90 ###########################################################
91 ### check that a short password is rejected
92 ###########################################################
94 cat > $PREFIX/tmpkpasswdscript
<<EOF
96 password ${TEST_PASSWORD}\n
98 send ${TEST_PASSWORD_SHORT}\n
99 expect Verify password
100 send ${TEST_PASSWORD_SHORT}\n
101 expect Password too short
104 testit
"kpasswd check short user password" \
105 $texpect $PREFIX/tmpkpasswdscript
$samba_kpasswd $TEST_PRINCIPAL || failed
=`expr $failed + 1`
107 ###########################################################
108 ### check that a weak password is rejected
109 ###########################################################
111 echo "check that a short password is rejected"
112 cat > .
/tmpkpasswdscript
<<EOF
114 password ${TEST_PASSWORD}\n
116 send $TEST_PASSWORD_WEAK\n
117 expect Verify password
118 send $TEST_PASSWORD_WEAK\n
119 expect Password does not meet complexity requirements
122 testit
"kpasswd check weak user password" \
123 $texpect $PREFIX/tmpkpasswdscript
$samba_kpasswd $TEST_PRINCIPAL || failed
=`expr $failed + 1`
125 ###########################################################
126 ### check that a strong password is accepted
127 ###########################################################
129 cat > .
/tmpkpasswdscript
<<EOF
131 password ${TEST_PASSWORD}\n
133 send ${TEST_PASSWORD_NEW}\n
134 expect Verify password
135 send ${TEST_PASSWORD_NEW}\n
139 testit
"kpasswd change user password" \
140 $texpect $PREFIX/tmpkpasswdscript
$samba_kpasswd $TEST_PRINCIPAL || failed
=`expr $failed + 1`
142 TEST_PASSWORD
=$TEST_PASSWORD_NEW
143 TEST_PASSWORD_NEW
="testPaSS@03%"
145 ###########################################################
146 ### Force password change at login
147 ###########################################################
149 testit
"set password on user locally" \
150 $VALGRIND $samba_tool user setpassword
$TEST_USERNAME $CONFIG --newpassword=$TEST_PASSWORD_NEW --must-change-at-next-login || failed
=`expr $failed + 1`
152 TEST_PASSWORD
=$TEST_PASSWORD_NEW
153 TEST_PASSWORD_NEW
="testPaSS@04%"
155 rm -f $PREFIX/tmpuserccache
157 cat > $PREFIX/tmpkinitscript
<<EOF
159 password ${TEST_PASSWORD}\n
160 expect Changing password
162 send ${TEST_PASSWORD_NEW}\n
163 expect Repeat new password
164 send ${TEST_PASSWORD_NEW}\n
168 testit
"kinit and change user password" \
169 $texpect $PREFIX/tmpkinitscript
$samba_kinit $TEST_PRINCIPAL || failed
=`expr $failed + 1`
171 TEST_PASSWORD
=$TEST_PASSWORD_NEW
172 TEST_PASSWORD_NEW
="testPaSS@07%"
174 test_smbclient
"Test login with user (kerberos)" \
175 "ls" "$SMB_UNC" -k yes -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed
=`expr $failed + 1`
177 ###########################################################
178 ### Test kpasswd service via 'net ads password'
179 ###########################################################
181 # NOTE: This works with heimdal because the krb5_set_password function tries
182 # set_password call first and falls back to change_password if it doesn't
184 testit
"change user password with 'net ads password', admin: $DOMAIN/$TEST_USERNAME, target: $TEST_PRINCIPAL" \
185 $VALGRIND $net_tool ads password
-W$DOMAIN -U$TEST_PRINCIPAL%$TEST_PASSWORD $TEST_PRINCIPAL "$TEST_PASSWORD_NEW" || failed
=`expr $failed + 1`
187 TEST_PASSWORD
=$TEST_PASSWORD_NEW
188 TEST_PASSWORD_NEW
="testPaSS@08%"
190 test_smbclient
"Test login with smbclient (ntlm)" \
191 "ls" "$SMB_UNC" -k no
-U$TEST_PRINCIPAL%$TEST_PASSWORD || failed
=`expr $failed + 1`
193 ###########################################################
194 ### Test kpasswd service via 'net ads password' as admin
195 ###########################################################
197 testit
"set user password with 'net ads password', admin: $DOMAIN/$USERNAME, target: $TEST_PRINCIPAL" \
198 $VALGRIND $net_tool ads password
-W$DOMAIN -U$USERNAME@
$REALM%$PASSWORD $TEST_PRINCIPAL "$TEST_PASSWORD_NEW" || failed
=`expr $failed + 1`
200 TEST_PASSWORD
=$TEST_PASSWORD_NEW
201 TEST_PASSWORD_NEW
="testPaSS@07%"
203 test_smbclient
"Test login with smbclient (ntlm)" \
204 "ls" "$SMB_UNC" -k no
-U$TEST_PRINCIPAL%$TEST_PASSWORD || failed
=`expr $failed + 1`
206 ###########################################################
208 ###########################################################
210 testit
"reset password policies" \
211 $VALGRIND $samba_tool domain passwordsettings
$CONFIG set --complexity=default
--history-length=default
--min-pwd-length=default
--min-pwd-age=default
--max-pwd-age=default || failed
=`expr $failed + 1`
213 testit
"delete user" \
214 $VALGRIND $samba_tool user delete
$TEST_USERNAME -U"$USERNAME%$PASSWORD" $CONFIG -k no || failed
=`expr $failed + 1`
216 rm -f $PREFIX/tmpuserccache
$PREFIX/tmpkpasswdscript
$PREFIX/tmpkinitscript