testprogs: Add a new test_password_settings.sh script
[garming/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 unc="//$SERVER/tmp"
40
41 . `dirname $0`/subunit.sh
42 . `dirname $0`/common_test_fns.inc
43
44 do_kinit() {
45         file="$1"
46         password="$2"
47         shift
48         shift
49         if test -x $BINDIR/samba4kinit; then
50                 $samba4kinit --password-file=$file --request-pac $@
51         else
52                 echo $password | $samba4kinit $@
53         fi
54 }
55
56 UID_WRAPPER_ROOT=1
57 export UID_WRAPPER_ROOT
58
59 CONFIG="--configfile=$PREFIX/etc/smb.conf"
60 export CONFIG
61
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`
63
64 USERPASS=testPaSS@00%
65
66 testit "create user locally" $VALGRIND $newuser $CONFIG nettestuser $USERPASS $@ || failed=`expr $failed + 1`
67
68 KRB5CCNAME="$PREFIX/tmpuserccache"
69 export KRB5CCNAME
70
71 echo $USERPASS > $PREFIX/tmpuserpassfile
72
73 testit "kinit with user password" do_kinit $PREFIX/tmpuserpassfile $USERPASS nettestuser@$REALM   || failed=`expr $failed + 1`
74
75 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
76
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`
79
80 echo $NEWUSERPASS > ./tmpuserpassfile
81 testit "kinit with user password" do_kinit ./tmpuserpassfile $NEWUSERPASS nettestuser@$REALM   || failed=`expr $failed + 1`
82
83 test_smbclient "Test login with user kerberos ccache" 'ls' "$unc" -k yes || failed=`expr $failed + 1`
84
85 #
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
88 #
89
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`
92
93
94 USERPASS=$NEWUSERPASS
95 WEAKPASS=testpass1
96 NEWUSERPASS=testPaSS@02%
97
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
101 #expect Password
102 #password ${USERPASS}\n
103 #expect New password
104 #send ${WEAKPASS}\n
105 #expect New password
106 #send ${NEWUSERPASS}\n
107 #expect password mismatch
108 #EOF
109 #
110 #testit "change user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
111
112
113 echo "check that a weak password is rejected"
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 ${WEAKPASS}\n
121 expect Password does not meet complexity requirements
122 EOF
123
124 testit "change to weak user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
125
126 echo "check that a short password is rejected"
127 cat > ./tmpkpasswdscript <<EOF
128 expect Password
129 password ${USERPASS}\n
130 expect New password
131 send xx1\n
132 expect New password
133 send xx1\n
134 expect Password too short
135 EOF
136
137 testit "change to short user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
138
139
140 echo "check that a strong new password is accepted"
141 cat > ./tmpkpasswdscript <<EOF
142 expect Password
143 password ${USERPASS}\n
144 expect New password
145 send ${NEWUSERPASS}\n
146 expect New password
147 send ${NEWUSERPASS}\n
148 expect Success
149 EOF
150
151 testit "change user password with kpasswd" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
152
153 test_smbclient "Test login with user kerberos (unforced)" 'ls' "$unc" -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
154
155 NEWUSERPASS=testPaSS@03%
156
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
163 EOF
164
165 testit "set user password with smbpasswd" $texpect ./tmpsmbpasswdscript $smbpasswd -L -c $PREFIX/etc/smb.conf nettestuser || failed=`expr $failed + 1`
166 USERPASS=$NEWUSERPASS
167
168 test_smbclient "Test login with user (ntlm)" 'ls' "$unc" -k no -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
169
170
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
174
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
178
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
182
183 NEWUSERPASS=testPaSS@07%
184
185 cat > ./tmpkpasswdscript <<EOF
186 expect Password
187 password ${USERPASS}\n
188 expect New password
189 send ${NEWUSERPASS}\n
190 expect New password
191 send ${NEWUSERPASS}\n
192 expect Success
193 EOF
194
195 testit "change user password with kpasswd (after must change flag set)" $texpect ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
196 USERPASS=$NEWUSERPASS
197
198 test_smbclient "Test login with user kerberos" 'ls' "$unc" -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
199
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
203
204 NEWUSERPASS=testPaSS@09%
205
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
213 EOF
214
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`
216
217 USERPASS=$NEWUSERPASS
218
219 test_smbclient "Test login with user kerberos" 'ls' "$unc" -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
220
221 NEWUSERPASS=abcdefg
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`
223
224 testit "allow non-complex passwords" $VALGRIND $samba_tool domain passwordsettings set $CONFIG --complexity=off || failed=`expr $failed + 1`
225
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
228
229 test_smbclient "test login with non-complex password" 'ls' "$unc" -k no -Unettestuser@$REALM%$USERPASS || failed=`expr $failed + 1`
230
231 NEWUSERPASS=abc
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`
233
234 testit "allow short passwords (length 1)" $VALGRIND $samba_tool domain passwordsettings $CONFIG set --min-pwd-length=1 || failed=`expr $failed + 1`
235
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"
238
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"
243
244 test_smbclient "Test login with smbclient" 'ls' "$unc" -k no -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
245
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"
250
251 test_smbclient "Test login with smbclient" 'ls' "$unc" -k no -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
252
253 testit "require minimum password age of 1 day" $VALGRIND $samba_tool domain passwordsettings $CONFIG set --min-pwd-age=1 || failed=`expr $failed + 1`
254
255 testit "show password settings" $VALGRIND $samba_tool domain passwordsettings $CONFIG show || failed=`expr $failed + 1`
256
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`
259
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`
261
262 testit "del user" $VALGRIND $samba_tool user delete nettestuser -U"$USERNAME%$PASSWORD" $CONFIG -k no $@ || failed=`expr $failed + 1`
263
264 rm -f tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript tmpsmbpasswdscript
265 exit $failed