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 smbpasswd
="$samba4bindir/smbpasswd"
31 texpect
="$samba4bindir/texpect"
33 if test -x $BINDIR/samba4kpasswd
; then
34 samba4kpasswd
=$BINDIR/samba4kpasswd
37 newuser
="$samba_tool user create"
39 .
`dirname $0`/subunit.sh
47 $VALGRIND $smbclient //$SERVER/tmp
-c "$cmd" $@
49 if [ x
$status = x0
]; then
62 if test -x $BINDIR/samba4kinit
; then
63 $samba4kinit --password-file=$file --request-pac $@
65 echo $password |
$samba4kinit $@
70 export UID_WRAPPER_ROOT
72 CONFIG
="--configfile=$PREFIX/dc/etc/smb.conf"
75 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`
79 testit
"create user locally" $VALGRIND $newuser $CONFIG nettestuser
$USERPASS $@ || failed
=`expr $failed + 1`
81 KRB5CCNAME
="$PREFIX/tmpuserccache"
84 echo $USERPASS > $PREFIX/tmpuserpassfile
86 testit
"kinit with user password" do_kinit
$PREFIX/tmpuserpassfile
$USERPASS nettestuser@
$REALM || failed
=`expr $failed + 1`
88 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
90 NEWUSERPASS
=testPaSS@
01%
91 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`
93 echo $NEWUSERPASS > .
/tmpuserpassfile
94 testit
"kinit with user password" do_kinit .
/tmpuserpassfile
$NEWUSERPASS nettestuser@
$REALM || failed
=`expr $failed + 1`
96 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
99 # These tests demonstrate that a credential cache in the environment does not
100 # override a username/password, even an incorrect one, on the command line
103 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`
104 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`
107 USERPASS
=$NEWUSERPASS
109 NEWUSERPASS
=testPaSS@
02%
111 # password mismatch check doesn't work yet (kpasswd bug, reported to Love)
112 #echo "check that password mismatch gives the right error"
113 #cat > ./tmpkpasswdscript <<EOF
115 #password ${USERPASS}\n
119 #send ${NEWUSERPASS}\n
120 #expect password mismatch
123 #testit "change user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
126 echo "check that a weak password is rejected"
127 cat > .
/tmpkpasswdscript
<<EOF
129 password ${USERPASS}\n
134 expect Password does not meet complexity requirements
137 testit
"change to weak user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
139 echo "check that a short password is rejected"
140 cat > .
/tmpkpasswdscript
<<EOF
142 password ${USERPASS}\n
147 expect Password too short
150 testit
"change to short user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
153 echo "check that a strong new password is accepted"
154 cat > .
/tmpkpasswdscript
<<EOF
156 password ${USERPASS}\n
158 send ${NEWUSERPASS}\n
160 send ${NEWUSERPASS}\n
164 testit
"change user password with kpasswd" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
166 test_smbclient
"Test login with user kerberos (unforced)" 'ls' -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
168 NEWUSERPASS
=testPaSS@
03%
170 echo "set password with smbpasswd"
171 cat > .
/tmpsmbpasswdscript
<<EOF
172 expect New SMB password:
173 send ${NEWUSERPASS}\n
174 expect Retype new SMB password:
175 send ${NEWUSERPASS}\n
178 testit
"set user password with smbpasswd" $texpect .
/tmpsmbpasswdscript
$smbpasswd -L -c $PREFIX/dc
/etc
/smb.conf nettestuser || failed
=`expr $failed + 1`
179 USERPASS
=$NEWUSERPASS
181 test_smbclient
"Test login with user (ntlm)" 'ls' -k no
-Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
184 NEWUSERPASS
=testPaSS@
04%
185 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword nettestuser
$CONFIG --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
186 USERPASS
=$NEWUSERPASS
188 NEWUSERPASS
=testPaSS@
05%
189 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`
190 USERPASS
=$NEWUSERPASS
192 NEWUSERPASS
=testPaSS@
06%
193 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword
$CONFIG nettestuser
--newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
194 USERPASS
=$NEWUSERPASS
196 NEWUSERPASS
=testPaSS@
07%
198 cat > .
/tmpkpasswdscript
<<EOF
200 password ${USERPASS}\n
202 send ${NEWUSERPASS}\n
204 send ${NEWUSERPASS}\n
208 testit
"change user password with kpasswd (after must change flag set)" $texpect .
/tmpkpasswdscript
$samba4kpasswd nettestuser@
$REALM || failed
=`expr $failed + 1`
209 USERPASS
=$NEWUSERPASS
211 test_smbclient
"Test login with user kerberos" 'ls' -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
213 NEWUSERPASS
=testPaSS@
08%
214 testit
"set password on user locally" $VALGRIND $samba_tool user setpassword
$CONFIG nettestuser
--newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed
=`expr $failed + 1`
215 USERPASS
=$NEWUSERPASS
217 NEWUSERPASS
=testPaSS@
09%
219 cat > .
/tmpsmbpasswdscript
<<EOF
220 expect Old SMB password:
221 password ${USERPASS}\n
222 expect New SMB password:
223 send ${NEWUSERPASS}\n
224 expect Retype new SMB password:
225 send ${NEWUSERPASS}\n
228 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`
230 USERPASS
=$NEWUSERPASS
232 test_smbclient
"Test login with user kerberos" 'ls' -k yes -Unettestuser@
$REALM%$NEWUSERPASS || failed
=`expr $failed + 1`
235 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`
237 testit
"allow non-complex passwords" $VALGRIND $samba_tool domain passwordsettings
set $CONFIG --complexity=off || failed
=`expr $failed + 1`
239 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`
240 USERPASS
=$NEWUSERPASS
242 test_smbclient
"test login with non-complex password" 'ls' -k no
-Unettestuser@
$REALM%$USERPASS || failed
=`expr $failed + 1`
245 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`
247 testit
"allow short passwords (length 1)" $VALGRIND $samba_tool domain passwordsettings
$CONFIG set --min-pwd-length=1 || failed
=`expr $failed + 1`
249 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`
250 USERPASS
="$NEWUSERPASS"
252 testit
"require minimum password age of 1 day" $VALGRIND $samba_tool domain passwordsettings
$CONFIG set --min-pwd-age=1 || failed
=`expr $failed + 1`
254 testit
"show password settings" $VALGRIND $samba_tool domain passwordsettings
$CONFIG show || failed
=`expr $failed + 1`
256 NEWUSERPASS
="testPaSS@08%"
257 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`
259 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`
261 testit
"del user" $VALGRIND $samba_tool user delete nettestuser
-U"$USERNAME%$PASSWORD" $CONFIG -k no $@ || failed
=`expr $failed + 1`
263 rm -f tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript tmpsmbpasswdscript