testprogs/test_ldb: check rootdse search with extended-dn control
[gd/samba-autobuild/.git] / testprogs / blackbox / test_passwords.sh
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>
5
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;
11 fi
12
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
22
23 samba4bindir="$BINDIR"
24 samba4kinit=kinit
25 if test -x $BINDIR/samba4kinit; then
26         samba4kinit=$BINDIR/samba4kinit
27 fi
28
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
36 fi
37
38 newuser="$samba_tool user create"
39
40 . `dirname $0`/subunit.sh
41
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"
54         fi
55         return $status
56 }
57
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 $@
67         fi
68 }
69
70 UID_WRAPPER_ROOT=1
71 export UID_WRAPPER_ROOT
72
73 CONFIG="--configfile=$PREFIX/dc/etc/smb.conf"
74 export CONFIG
75
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`
77
78 USERPASS=testPaSS@00%
79
80 testit "create user locally" $VALGRIND $newuser $CONFIG nettestuser $USERPASS $@ || failed=`expr $failed + 1`
81
82 KRB5CCNAME="$PREFIX/tmpuserccache"
83 export KRB5CCNAME
84
85 echo $USERPASS > $PREFIX/tmpuserpassfile
86
87 testit "kinit with user password" do_kinit $PREFIX/tmpuserpassfile $USERPASS nettestuser@$REALM   || failed=`expr $failed + 1`
88
89 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
90
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`
93
94 echo $NEWUSERPASS > ./tmpuserpassfile
95 testit "kinit with user password" do_kinit ./tmpuserpassfile $NEWUSERPASS nettestuser@$REALM   || failed=`expr $failed + 1`
96
97 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
98
99 #
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
102 #
103
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`
106
107
108 USERPASS=$NEWUSERPASS
109 WEAKPASS=testpass1
110 NEWUSERPASS=testPaSS@02%
111
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
123 #
124 #testit "change user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
125
126
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
136 EOF
137
138 testit "change to weak user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
139
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
149 EOF
150
151 testit "change to short user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
152
153
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
163 EOF
164
165 testit "change user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
166
167 test_smbclient "Test login with user kerberos (unforced)" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
168
169 NEWUSERPASS=testPaSS@03%
170
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
177 EOF
178
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
181
182 test_smbclient "Test login with user (ntlm)" 'ls' -k no -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
183
184
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
188
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
192
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
196
197 NEWUSERPASS=testPaSS@07%
198
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
207 EOF
208
209 testit "change user password with kpasswd (after must change flag set)" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
210 USERPASS=$NEWUSERPASS
211
212 test_smbclient "Test login with user kerberos" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
213
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
217
218 NEWUSERPASS=testPaSS@09%
219
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
227 EOF
228
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`
230
231 USERPASS=$NEWUSERPASS
232
233 test_smbclient "Test login with user kerberos" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
234
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`
237
238 testit "allow non-complex passwords" $VALGRIND $samba_tool domain passwordsettings set $CONFIG --complexity=off || failed=`expr $failed + 1`
239
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
242
243 test_smbclient "test login with non-complex password" 'ls' -k no -Unettestuser@$REALM%$USERPASS || failed=`expr $failed + 1`
244
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`
247
248 testit "allow short passwords (length 1)" $VALGRIND $samba_tool domain passwordsettings $CONFIG set --min-pwd-length=1 || failed=`expr $failed + 1`
249
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"
252
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"
257
258 test_smbclient "Test login with smbclient" 'ls' -k no -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
259
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"
264
265 test_smbclient "Test login with smbclient" 'ls' -k no -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
266
267 testit "require minimum password age of 1 day" $VALGRIND $samba_tool domain passwordsettings $CONFIG set --min-pwd-age=1 || failed=`expr $failed + 1`
268
269 testit "show password settings" $VALGRIND $samba_tool domain passwordsettings $CONFIG show || failed=`expr $failed + 1`
270
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`
273
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`
275
276 testit "del user" $VALGRIND $samba_tool user delete nettestuser -U"$USERNAME%$PASSWORD" $CONFIG -k no $@ || failed=`expr $failed + 1`
277
278 rm -f tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript tmpsmbpasswdscript
279 exit $failed