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>
8 Usage: test_passwords.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX SMBCLIENT
23 samba4bindir
="$BINDIR"
25 if test -x $BINDIR/samba4kinit
; then
26 samba4kinit
=$BINDIR/samba4kinit
29 samba_tool
="$samba4bindir/samba-tool"
30 net_tool
="$samba4bindir/net"
31 smbpasswd
="$samba4bindir/smbpasswd"
32 texpect
="$samba4bindir/texpect"
34 if test -x $BINDIR/samba4kpasswd
; then
35 samba4kpasswd
=$BINDIR/samba4kpasswd
38 newuser
="$samba_tool user create"
40 .
`dirname $0`/subunit.sh
48 $VALGRIND $smbclient //$SERVER/tmp
-c "$cmd" $@
50 if [ x
$status = x0
]; then
63 if test -x $BINDIR/samba4kinit
; then
64 $samba4kinit --password-file=$file --request-pac $@
66 echo $password |
$samba4kinit $@
71 export UID_WRAPPER_ROOT
73 CONFIG
="--configfile=$PREFIX/dc/etc/smb.conf"
76 testit
"reset password policies beside of minimum password age of 0 days" $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`
80 testit
"create user locally" $VALGRIND $newuser $CONFIG nettestuser
$USERPASS $@ || failed
=`expr $failed + 1`
82 KRB5CCNAME
="$PREFIX/tmpuserccache"
85 echo $USERPASS > $PREFIX/tmpuserpassfile
87 testit
"kinit with user password" do_kinit
$PREFIX/tmpuserpassfile
$USERPASS nettestuser@
$REALM || failed
=`expr $failed + 1`
89 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
91 NEWUSERPASS
=testPaSS@
01%
92 testit
"change user password with 'samba-tool user password' (unforced)" $VALGRIND $samba_tool user password
-W$DOMAIN -U$DOMAIN/nettestuser
%$USERPASS -k no
--newpassword=$NEWUSERPASS $@ || failed
=`expr $failed + 1`
94 echo $NEWUSERPASS > .
/tmpuserpassfile
95 testit
"kinit with user password" do_kinit .
/tmpuserpassfile
$NEWUSERPASS nettestuser@
$REALM || failed
=`expr $failed + 1`
97 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
100 # These tests demonstrate that a credential cache in the environment does not
101 # override a username/password, even an incorrect one, on the command line
104 testit_expect_failure
"Test login with user kerberos ccache, but wrong password specified" $VALGRIND $smbclient //$SERVER/tmp
-c 'ls' -k yes -Unettestuser@
$REALM%wrongpass
&& failed
=`expr $failed + 1`
105 testit_expect_failure
"Test login with user kerberos ccache, but old password specified" $VALGRIND $smbclient //$SERVER/tmp
-c 'ls' -k yes -Unettestuser@
$REALM%$USERPASS && failed
=`expr $failed + 1`
108 USERPASS
=$NEWUSERPASS
110 NEWUSERPASS
=testPaSS@
02%
112 # password mismatch check doesn't work yet (kpasswd bug, reported to Love)
113 #echo "check that password mismatch gives the right error"
114 #cat > ./tmpkpasswdscript <<EOF
116 #password ${USERPASS}\n
120 #send ${NEWUSERPASS}\n
121 #expect password mismatch
124 #testit "change user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
127 echo "check that a weak password is rejected"
128 cat > .
/tmpkpasswdscript
<<EOF
130 password ${USERPASS}\n
135 expect Password does not meet complexity requirements
138 testit
"change to weak user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
140 echo "check that a short password is rejected"
141 cat > .
/tmpkpasswdscript
<<EOF
143 password ${USERPASS}\n
148 expect Password too short
151 testit
"change to short user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
154 echo "check that a strong new password is accepted"
155 cat > .
/tmpkpasswdscript
<<EOF
157 password ${USERPASS}\n
159 send ${NEWUSERPASS}\n
161 send ${NEWUSERPASS}\n
165 testit
"change user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
167 test_smbclient
"Test login with user kerberos (unforced)" 'ls' -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
169 NEWUSERPASS
=testPaSS@
03%
171 echo "set password with smbpasswd"
172 cat > .
/tmpsmbpasswdscript
<<EOF
173 expect New SMB password:
174 send ${NEWUSERPASS}\n
175 expect Retype new SMB password:
176 send ${NEWUSERPASS}\n
179 testit
"set user password with smbpasswd" $texpect .
/tmpsmbpasswdscript
$smbpasswd -L -c $PREFIX/dc
/etc
/smb.conf nettestuser || failed
=`expr $failed + 1`
180 USERPASS
=$NEWUSERPASS
182 test_smbclient
"Test login with user (ntlm)" 'ls' -k no
-Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
185 NEWUSERPASS
=testPaSS@
04%
186 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword nettestuser
$CONFIG --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
187 USERPASS
=$NEWUSERPASS
189 NEWUSERPASS
=testPaSS@
05%
190 testit
"change user password with 'samba-tool user password' (after must change flag set)" $VALGRIND $samba_tool user password
-W$DOMAIN -U$DOMAIN/nettestuser
%$USERPASS -k no
--newpassword=$NEWUSERPASS $@ || failed
=`expr $failed + 1`
191 USERPASS
=$NEWUSERPASS
193 NEWUSERPASS
=testPaSS@
06%
194 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword
$CONFIG nettestuser
--newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
195 USERPASS
=$NEWUSERPASS
197 NEWUSERPASS
=testPaSS@
07%
199 cat > .
/tmpkpasswdscript
<<EOF
201 password ${USERPASS}\n
203 send ${NEWUSERPASS}\n
205 send ${NEWUSERPASS}\n
209 testit
"change user password with kpasswd (after must change flag set)" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
210 USERPASS
=$NEWUSERPASS
212 test_smbclient
"Test login with user kerberos" 'ls' -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
214 NEWUSERPASS
=testPaSS@
08%
215 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword
$CONFIG nettestuser
--newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
216 USERPASS
=$NEWUSERPASS
218 NEWUSERPASS
=testPaSS@
09%
220 cat > .
/tmpsmbpasswdscript
<<EOF
221 expect Old SMB password:
222 password ${USERPASS}\n
223 expect New SMB password:
224 send ${NEWUSERPASS}\n
225 expect Retype new SMB password:
226 send ${NEWUSERPASS}\n
229 testit
"change user password with smbpasswd (after must change flag set)" $texpect .
/tmpsmbpasswdscript
$smbpasswd -r $SERVER -c $PREFIX/dc
/etc
/smb.conf
-U nettestuser || failed
=`expr $failed + 1`
231 USERPASS
=$NEWUSERPASS
233 test_smbclient
"Test login with user kerberos" 'ls' -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
236 testit_expect_failure
"try to set a non-complex password (command should not succeed)" $VALGRIND $samba_tool user password
-W$DOMAIN "-U$DOMAIN/nettestuser%$USERPASS" -k no
--newpassword="$NEWUSERPASS" $@
&& failed
=`expr $failed + 1`
238 testit
"allow non-complex passwords" $VALGRIND $samba_tool domain passwordsettings
set $CONFIG --complexity=off || failed
=`expr $failed + 1`
240 testit
"try to set a non-complex password (command should succeed)" $VALGRIND $samba_tool user password
-W$DOMAIN "-U$DOMAIN/nettestuser%$USERPASS" -k no
--newpassword="$NEWUSERPASS" $@ || failed
=`expr $failed + 1`
241 USERPASS
=$NEWUSERPASS
243 test_smbclient
"test login with non-complex password" 'ls' -k no
-Unettestuser@
$REALM%$USERPASS || failed
=`expr $failed + 1`
246 testit_expect_failure
"try to set a short password (command should not succeed)" $VALGRIND $samba_tool user password
-W$DOMAIN "-U$DOMAIN/nettestuser%$USERPASS" -k no
--newpassword="$NEWUSERPASS" $@
&& failed
=`expr $failed + 1`
248 testit
"allow short passwords (length 1)" $VALGRIND $samba_tool domain passwordsettings
$CONFIG set --min-pwd-length=1 || failed
=`expr $failed + 1`
250 testit
"try to set a short password (command should succeed)" $VALGRIND $samba_tool user password
-W$DOMAIN "-U$DOMAIN/nettestuser%$USERPASS" -k no
--newpassword="$NEWUSERPASS" $@ || failed
=`expr $failed + 1`
251 USERPASS
="$NEWUSERPASS"
253 # test kpasswd via net ads password (change variant)
254 NEWUSERPASS
="testPaSS@10%"
255 testit
"change user password with 'net ads password', admin: $DOMAIN/nettestuser, target: nettestuser@$REALM" $VALGRIND $net_tool ads password
-W$DOMAIN -Unettestuser@
$REALM%$USERPASS nettestuser@
$REALM "$NEWUSERPASS" $@ || failed
=`expr $failed + 1`
256 USERPASS
="$NEWUSERPASS"
258 test_smbclient
"Test login with smbclient" 'ls' -k no
-Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
260 # test kpasswd via net ads password (admin set variant)
261 NEWUSERPASS
="testPaSS@11%"
262 testit
"set user password with 'net ads password', admin: $DOMAIN/$USERNAME, target: nettestuser@$REALM" $VALGRIND $net_tool ads password
-W$DOMAIN -U$USERNAME@
$REALM%$PASSWORD nettestuser@
$REALM "$NEWUSERPASS" $@ || failed
=`expr $failed + 1`
263 USERPASS
="$NEWUSERPASS"
265 test_smbclient
"Test login with smbclient" 'ls' -k no
-Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
267 testit
"require minimum password age of 1 day" $VALGRIND $samba_tool domain passwordsettings
$CONFIG set --min-pwd-age=1 || failed
=`expr $failed + 1`
269 testit
"show password settings" $VALGRIND $samba_tool domain passwordsettings
$CONFIG show || failed
=`expr $failed + 1`
271 NEWUSERPASS
="testPaSS@08%"
272 testit_expect_failure
"try to change password too quickly (command should not succeed)" $VALGRIND $samba_tool user password
-W$DOMAIN "-U$DOMAIN/nettestuser%$USERPASS" -k no
--newpassword="$NEWUSERPASS" $@
&& failed
=`expr $failed + 1`
274 testit
"reset password policies" $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`
276 testit
"del user" $VALGRIND $samba_tool user delete nettestuser
-U"$USERNAME%$PASSWORD" $CONFIG -k no $@ || failed
=`expr $failed + 1`
278 rm -f tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript tmpsmbpasswdscript