s3:client correct a wording
[Samba/gebeck_regimport.git] / testprogs / blackbox / test_passwords.sh
blobc83b46b4fc78075ccdbe07d5006bafccaae6f983
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
9 EOF
10 exit 1;
13 SERVER=$1
14 USERNAME=$2
15 PASSWORD=$3
16 REALM=$4
17 DOMAIN=$5
18 PREFIX=$6
19 shift 6
20 failed=0
22 samba4bindir="$BINDIR"
23 smbclient="$samba4bindir/smbclient"
24 samba4kinit="$samba4bindir/samba4kinit"
25 samba_tool="$samba4bindir/samba-tool"
26 smbpasswd="$samba4bindir/smbpasswd"
27 rkpty="$samba4bindir/rkpty"
28 samba4kpasswd="$samba4bindir/samba4kpasswd"
29 newuser="$samba_tool user create"
31 . `dirname $0`/subunit.sh
33 test_smbclient() {
34 name="$1"
35 cmd="$2"
36 shift
37 shift
38 echo "test: $name"
39 $VALGRIND $smbclient //$SERVER/tmp -c "$cmd" $@
40 status=$?
41 if [ x$status = x0 ]; then
42 echo "success: $name"
43 else
44 echo "failure: $name"
46 return $status
49 CONFIG="--configfile=$PREFIX/dc/etc/smb.conf"
50 export CONFIG
52 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`
54 USERPASS=testPaSS@00%
56 testit "create user locally" $VALGRIND $newuser $CONFIG nettestuser $USERPASS $@ || failed=`expr $failed + 1`
58 KRB5CCNAME="$PREFIX/tmpuserccache"
59 export KRB5CCNAME
61 echo $USERPASS > $PREFIX/tmpuserpassfile
63 testit "kinit with user password" $samba4kinit --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
65 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
67 NEWUSERPASS=testPaSS@01%
68 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`
70 echo $NEWUSERPASS > ./tmpuserpassfile
71 testit "kinit with user password" $samba4kinit --password-file=./tmpuserpassfile --request-pac nettestuser@$REALM || failed=`expr $failed + 1`
73 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
76 USERPASS=$NEWUSERPASS
77 WEAKPASS=testpass1
78 NEWUSERPASS=testPaSS@02%
80 # password mismatch check doesn't work yet (kpasswd bug, reported to Love)
81 #echo "check that password mismatch gives the right error"
82 #cat > ./tmpkpasswdscript <<EOF
83 #expect Password
84 #password ${USERPASS}\n
85 #expect New password
86 #send ${WEAKPASS}\n
87 #expect New password
88 #send ${NEWUSERPASS}\n
89 #expect password mismatch
90 #EOF
92 #testit "change user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
95 echo "check that a weak password is rejected"
96 cat > ./tmpkpasswdscript <<EOF
97 expect Password
98 password ${USERPASS}\n
99 expect New password
100 send ${WEAKPASS}\n
101 expect New password
102 send ${WEAKPASS}\n
103 expect Password does not meet complexity requirements
106 testit "change to weak user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
108 echo "check that a short password is rejected"
109 cat > ./tmpkpasswdscript <<EOF
110 expect Password
111 password ${USERPASS}\n
112 expect New password
113 send xx1\n
114 expect New password
115 send xx1\n
116 expect Password too short
119 testit "change to short user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
122 echo "check that a strong new password is accepted"
123 cat > ./tmpkpasswdscript <<EOF
124 expect Password
125 password ${USERPASS}\n
126 expect New password
127 send ${NEWUSERPASS}\n
128 expect New password
129 send ${NEWUSERPASS}\n
130 expect Success
133 testit "change user password with kpasswd" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
135 test_smbclient "Test login with user kerberos (unforced)" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
137 NEWUSERPASS=testPaSS@03%
139 echo "set password with smbpasswd"
140 cat > ./tmpsmbpasswdscript <<EOF
141 expect New SMB password:
142 send ${NEWUSERPASS}\n
143 expect Retype new SMB password:
144 send ${NEWUSERPASS}\n
147 testit "set user password with smbpasswd" $rkpty ./tmpsmbpasswdscript $smbpasswd -L -c $PREFIX/dc/etc/smb.conf nettestuser || failed=`expr $failed + 1`
148 USERPASS=$NEWUSERPASS
150 test_smbclient "Test login with user (ntlm)" 'ls' -k no -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
153 NEWUSERPASS=testPaSS@04%
154 testit "set password on user locally" $VALGRIND $samba_tool user setpassword nettestuser $CONFIG --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed=`expr $failed + 1`
155 USERPASS=$NEWUSERPASS
157 NEWUSERPASS=testPaSS@05%
158 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`
159 USERPASS=$NEWUSERPASS
161 NEWUSERPASS=testPaSS@06%
162 testit "set password on user locally" $VALGRIND $samba_tool user setpassword $CONFIG nettestuser --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed=`expr $failed + 1`
163 USERPASS=$NEWUSERPASS
165 NEWUSERPASS=testPaSS@07%
167 cat > ./tmpkpasswdscript <<EOF
168 expect Password
169 password ${USERPASS}\n
170 expect New password
171 send ${NEWUSERPASS}\n
172 expect New password
173 send ${NEWUSERPASS}\n
174 expect Success
177 testit "change user password with kpasswd (after must change flag set)" $rkpty ./tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
178 USERPASS=$NEWUSERPASS
180 test_smbclient "Test login with user kerberos" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
182 NEWUSERPASS=testPaSS@08%
183 testit "set password on user locally" $VALGRIND $samba_tool user setpassword $CONFIG nettestuser --newpassword=$NEWUSERPASS --must-change-at-next-login $@ || failed=`expr $failed + 1`
184 USERPASS=$NEWUSERPASS
186 NEWUSERPASS=testPaSS@09%
188 cat > ./tmpsmbpasswdscript <<EOF
189 expect Old SMB password:
190 password ${USERPASS}\n
191 expect New SMB password:
192 send ${NEWUSERPASS}\n
193 expect Retype new SMB password:
194 send ${NEWUSERPASS}\n
197 testit "change user password with smbpasswd (after must change flag set)" $rkpty ./tmpsmbpasswdscript $smbpasswd -r $SERVER -c $PREFIX/dc/etc/smb.conf -U nettestuser || failed=`expr $failed + 1`
199 USERPASS=$NEWUSERPASS
201 test_smbclient "Test login with user kerberos" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS || failed=`expr $failed + 1`
203 NEWUSERPASS=abcdefg
204 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`
206 testit "allow non-complex passwords" $VALGRIND $samba_tool domain passwordsettings set $CONFIG --complexity=off || failed=`expr $failed + 1`
208 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`
209 USERPASS=$NEWUSERPASS
211 test_smbclient "test login with non-complex password" 'ls' -k no -Unettestuser@$REALM%$USERPASS || failed=`expr $failed + 1`
213 NEWUSERPASS=abc
214 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`
216 testit "allow short passwords (length 1)" $VALGRIND $samba_tool domain passwordsettings $CONFIG set --min-pwd-length=1 || failed=`expr $failed + 1`
218 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`
219 USERPASS="$NEWUSERPASS"
221 testit "require minimum password age of 1 day" $VALGRIND $samba_tool domain passwordsettings $CONFIG set --min-pwd-age=1 || failed=`expr $failed + 1`
223 testit "show password settings" $VALGRIND $samba_tool domain passwordsettings $CONFIG show || failed=`expr $failed + 1`
225 NEWUSERPASS="testPaSS@08%"
226 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`
228 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`
230 testit "del user" $VALGRIND $samba_tool user delete nettestuser -U"$USERNAME%$PASSWORD" -k no $@ || failed=`expr $failed + 1`
232 rm -f tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript tmpsmbpasswdscript
233 exit $failed