nfs4acls: Introduce a helper variable
[Samba.git] / testprogs / blackbox / test_passwords.sh
blob09d70eb3436bc538d9329c2f33f01de236d8e22e
1 #!/bin/sh
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>
6 if [ $# -lt 5 ]; then
7 cat <<EOF
8 Usage: test_passwords.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX SMBCLIENT
9 EOF
10 exit 1;
13 SERVER=$1
14 USERNAME=$2
15 PASSWORD=$3
16 REALM=$4
17 DOMAIN=$5
18 PREFIX=$6
19 smbclient=$7
20 shift 7
21 failed=0
23 samba4bindir="$BINDIR"
24 samba4kinit=kinit
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"
33 samba4kpasswd=kpasswd
34 if test -x $BINDIR/samba4kpasswd; then
35 samba4kpasswd=$BINDIR/samba4kpasswd
38 newuser="$samba_tool user create"
40 . `dirname $0`/subunit.sh
42 test_smbclient() {
43 name="$1"
44 cmd="$2"
45 shift
46 shift
47 echo "test: $name"
48 $VALGRIND $smbclient //$SERVER/tmp -c "$cmd" $@
49 status=$?
50 if [ x$status = x0 ]; then
51 echo "success: $name"
52 else
53 echo "failure: $name"
55 return $status
58 do_kinit() {
59 file="$1"
60 password="$2"
61 shift
62 shift
63 if test -x $BINDIR/samba4kinit; then
64 $samba4kinit --password-file=$file --request-pac $@
65 else
66 echo $password | $samba4kinit $@
70 UID_WRAPPER_ROOT=1
71 export UID_WRAPPER_ROOT
73 CONFIG="--configfile=$PREFIX/etc/smb.conf"
74 export CONFIG
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`
78 USERPASS=testPaSS@00%
80 testit "create user locally" $VALGRIND $newuser $CONFIG nettestuser $USERPASS $@ || failed=`expr $failed + 1`
82 KRB5CCNAME="$PREFIX/tmpuserccache"
83 export KRB5CCNAME
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
109 WEAKPASS=testpass1
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
115 #expect Password
116 #password ${USERPASS}\n
117 #expect New password
118 #send ${WEAKPASS}\n
119 #expect New password
120 #send ${NEWUSERPASS}\n
121 #expect password mismatch
122 #EOF
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
129 expect Password
130 password ${USERPASS}\n
131 expect New password
132 send ${WEAKPASS}\n
133 expect New password
134 send ${WEAKPASS}\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
142 expect Password
143 password ${USERPASS}\n
144 expect New password
145 send xx1\n
146 expect New password
147 send xx1\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
156 expect Password
157 password ${USERPASS}\n
158 expect New password
159 send ${NEWUSERPASS}\n
160 expect New password
161 send ${NEWUSERPASS}\n
162 expect Success
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/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
200 expect Password
201 password ${USERPASS}\n
202 expect New password
203 send ${NEWUSERPASS}\n
204 expect New password
205 send ${NEWUSERPASS}\n
206 expect Success
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/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`
235 NEWUSERPASS=abcdefg
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`
245 NEWUSERPASS=abc
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
279 exit $failed