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"
41 .
`dirname $0`/subunit.sh
42 .
`dirname $0`/common_test_fns.inc
49 if test -x $BINDIR/samba4kinit
; then
50 $samba4kinit --password-file=$file --request-pac $@
52 echo $password |
$samba4kinit $@
57 export UID_WRAPPER_ROOT
59 CONFIG
="--configfile=$PREFIX/etc/smb.conf"
62 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`
66 testit
"create user locally" $VALGRIND $newuser $CONFIG nettestuser
$USERPASS $@ || failed
=`expr $failed + 1`
68 KRB5CCNAME
="$PREFIX/tmpuserccache"
71 echo $USERPASS > $PREFIX/tmpuserpassfile
73 testit
"kinit with user password" do_kinit
$PREFIX/tmpuserpassfile
$USERPASS nettestuser@
$REALM || failed
=`expr $failed + 1`
75 test_smbclient
"Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed
=`expr $failed + 1`
77 NEWUSERPASS
=testPaSS@
01%
78 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`
80 echo $NEWUSERPASS > .
/tmpuserpassfile
81 testit
"kinit with user password" do_kinit .
/tmpuserpassfile
$NEWUSERPASS nettestuser@
$REALM || failed
=`expr $failed + 1`
83 test_smbclient
"Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed
=`expr $failed + 1`
86 # These tests demonstrate that a credential cache in the environment does not
87 # override a username/password, even an incorrect one, on the command line
90 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`
91 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`
96 NEWUSERPASS
=testPaSS@
02%
98 # password mismatch check doesn't work yet (kpasswd bug, reported to Love)
99 #echo "check that password mismatch gives the right error"
100 #cat > ./tmpkpasswdscript <<EOF
102 #password ${USERPASS}\n
106 #send ${NEWUSERPASS}\n
107 #expect password mismatch
110 #testit "change user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
113 echo "check that a weak password is rejected"
114 cat > .
/tmpkpasswdscript
<<EOF
116 password ${USERPASS}\n
121 expect Password does not meet complexity requirements
124 testit
"change to weak user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
126 echo "check that a short password is rejected"
127 cat > .
/tmpkpasswdscript
<<EOF
129 password ${USERPASS}\n
134 expect Password too short
137 testit
"change to short user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
140 echo "check that a strong new password is accepted"
141 cat > .
/tmpkpasswdscript
<<EOF
143 password ${USERPASS}\n
145 send ${NEWUSERPASS}\n
147 send ${NEWUSERPASS}\n
151 testit
"change user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
153 test_smbclient
"Test login with user kerberos (unforced)" 'ls' "$unc" -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
155 NEWUSERPASS
=testPaSS@
03%
157 echo "set password with smbpasswd"
158 cat > .
/tmpsmbpasswdscript
<<EOF
159 expect New SMB password:
160 send ${NEWUSERPASS}\n
161 expect Retype new SMB password:
162 send ${NEWUSERPASS}\n
165 testit
"set user password with smbpasswd" $texpect .
/tmpsmbpasswdscript
$smbpasswd -L -c $PREFIX/etc
/smb.conf nettestuser || failed
=`expr $failed + 1`
166 USERPASS
=$NEWUSERPASS
168 test_smbclient
"Test login with user (ntlm)" 'ls' "$unc" -k no
-Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
171 NEWUSERPASS
=testPaSS@
04%
172 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword nettestuser
$CONFIG --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
173 USERPASS
=$NEWUSERPASS
175 NEWUSERPASS
=testPaSS@
05%
176 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`
177 USERPASS
=$NEWUSERPASS
179 NEWUSERPASS
=testPaSS@
06%
180 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword
$CONFIG nettestuser
--newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
181 USERPASS
=$NEWUSERPASS
183 NEWUSERPASS
=testPaSS@
07%
185 cat > .
/tmpkpasswdscript
<<EOF
187 password ${USERPASS}\n
189 send ${NEWUSERPASS}\n
191 send ${NEWUSERPASS}\n
195 testit
"change user password with kpasswd (after must change flag set)" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
196 USERPASS
=$NEWUSERPASS
198 test_smbclient
"Test login with user kerberos" 'ls' "$unc" -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
200 NEWUSERPASS
=testPaSS@
08%
201 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword
$CONFIG nettestuser
--newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
202 USERPASS
=$NEWUSERPASS
204 NEWUSERPASS
=testPaSS@
09%
206 cat > .
/tmpsmbpasswdscript
<<EOF
207 expect Old SMB password:
208 password ${USERPASS}\n
209 expect New SMB password:
210 send ${NEWUSERPASS}\n
211 expect Retype new SMB password:
212 send ${NEWUSERPASS}\n
215 testit
"change user password with smbpasswd (after must change flag set)" $texpect .
/tmpsmbpasswdscript
$smbpasswd -r $SERVER -c $PREFIX/etc
/smb.conf
-U nettestuser || failed
=`expr $failed + 1`
217 USERPASS
=$NEWUSERPASS
219 test_smbclient
"Test login with user kerberos" 'ls' "$unc" -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
222 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`
224 testit
"allow non-complex passwords" $VALGRIND $samba_tool domain passwordsettings
set $CONFIG --complexity=off || failed
=`expr $failed + 1`
226 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`
227 USERPASS
=$NEWUSERPASS
229 test_smbclient
"test login with non-complex password" 'ls' "$unc" -k no
-Unettestuser@
$REALM%$USERPASS || failed
=`expr $failed + 1`
232 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`
234 testit
"allow short passwords (length 1)" $VALGRIND $samba_tool domain passwordsettings
$CONFIG set --min-pwd-length=1 || failed
=`expr $failed + 1`
236 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`
237 USERPASS
="$NEWUSERPASS"
239 # test kpasswd via net ads password (change variant)
240 NEWUSERPASS
="testPaSS@10%"
241 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`
242 USERPASS
="$NEWUSERPASS"
244 test_smbclient
"Test login with smbclient" 'ls' "$unc" -k no
-Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
246 # test kpasswd via net ads password (admin set variant)
247 NEWUSERPASS
="testPaSS@11%"
248 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`
249 USERPASS
="$NEWUSERPASS"
251 test_smbclient
"Test login with smbclient" 'ls' "$unc" -k no
-Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
253 testit
"require minimum password age of 1 day" $VALGRIND $samba_tool domain passwordsettings
$CONFIG set --min-pwd-age=1 || failed
=`expr $failed + 1`
255 testit
"show password settings" $VALGRIND $samba_tool domain passwordsettings
$CONFIG show || failed
=`expr $failed + 1`
257 NEWUSERPASS
="testPaSS@08%"
258 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`
260 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`
262 testit
"del user" $VALGRIND $samba_tool user delete nettestuser
-U"$USERNAME%$PASSWORD" $CONFIG -k no $@ || failed
=`expr $failed + 1`
264 rm -f tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript tmpsmbpasswdscript