winbindd: as DC we should try to get the target_domain from @SOMETHING part of the...
[Samba.git] / testprogs / blackbox / test_password_settings.sh
blob97adb3c9db294015dfff9ca2be060f2ff033e266
1 #!/bin/sh
2 # Blackbox tests for different password settings
4 # Copyright (c) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
5 # Copyright (c) 2006-2008 Andrew Bartlett <abartlet@samba.org>
6 # Copyright (c) 2016 Andreas Schneider <asn@samba.org>
8 if [ $# -lt 6 ]; then
9 cat <<EOF
10 Usage: test_passwords_settings.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX
11 EOF
12 exit 1;
15 SERVER=$1
16 USERNAME=$2
17 PASSWORD=$3
18 REALM=$4
19 DOMAIN=$5
20 PREFIX=$6
21 shift 6
22 failed=0
24 samba_bindir="$BINDIR"
26 samba_kinit=kinit
27 if test -x $samba_bindir/samba4kinit; then
28 samba_kinit=$samba_bindir/samba4kinit
31 smbclient="$samba_bindir/smbclient"
32 samba_tool="$samba_bindir/samba-tool"
33 smbpasswd="$samba_bindir/smbpasswd"
34 texpect="$samba_bindir/texpect"
36 newuser="$samba_tool user create"
37 SMB_UNC="//$SERVER/tmp"
39 . `dirname $0`/subunit.sh
40 . `dirname $0`/common_test_fns.inc
42 do_kinit() {
43 principal="$1"
44 password="$2"
45 shift
46 shift
47 if test -x $samba_bindir/samba4kinit; then
48 echo $password > $PREFIX/tmpuserpassfile
49 $samba_kinit --password-file=$PREFIX/tmpuserpassfile $principal $@
50 else
51 echo $password | $samba_kinit $principal $@
55 UID_WRAPPER_ROOT=1
56 export UID_WRAPPER_ROOT
58 CONFIG="--configfile=$PREFIX/etc/smb.conf"
59 export CONFIG
61 testit "reset password policies beside of minimum password age of 0 days" \
62 $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`
64 TEST_USERNAME="$(mktemp -u alice-XXXXXX)"
65 TEST_PASSWORD="testPaSS@00%"
66 TEST_PASSWORD_NEW="testPaSS@01%"
67 TEST_PASSWORD_SHORT="secret"
68 TEST_PASSWORD_WEAK="Supersecret"
69 TEST_PRINCIPAL="$TEST_USERNAME@$REALM"
71 testit "create user locally" \
72 $VALGRIND $newuser $CONFIG $TEST_USERNAME $TEST_PASSWORD || failed=`expr $failed + 1`
74 ###########################################################
75 ### Test normal operation as user
76 ###########################################################
78 KRB5CCNAME_PATH="$PREFIX/test_password_settings_krb5ccache"
79 rm -f $KRB5CCNAME_PATH
81 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
82 export KRB5CCNAME
84 testit "kinit with user password" \
85 do_kinit $TEST_PRINCIPAL $TEST_PASSWORD || failed=`expr $failed + 1`
87 test_smbclient "Test login with user kerberos ccache" \
88 "ls" "$SMB_UNC" -k yes || failed=`expr $failed + 1`
90 rm -f $KRB5CCNAME_PATH
92 ###########################################################
93 ### Change the users password
94 ###########################################################
96 testit "change user password with 'samba-tool user password' (unforced)" \
97 $VALGRIND $samba_tool user password -W$DOMAIN -U$TEST_USERNAME%$TEST_PASSWORD -k no --newpassword=$TEST_PASSWORD_NEW || failed=`expr $failed + 1`
99 TEST_PASSWORD_OLD=$TEST_PASSWORD
100 TEST_PASSWORD=$TEST_PASSWORD_NEW
101 TEST_PASSWORD_NEW="testPaSS@02%"
103 testit "kinit with user password" \
104 do_kinit $TEST_PRINCIPAL $TEST_PASSWORD || failed=`expr $failed + 1`
106 test_smbclient "Test login with user kerberos ccache" \
107 "ls" "$SMB_UNC" -k yes || failed=`expr $failed + 1`
110 # These tests demonstrate that a credential cache in the environment does not
111 # override a username/password, even an incorrect one, on the command line
114 testit_expect_failure "Test login with user kerberos ccache, but wrong password specified" \
115 $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -k yes -U$TEST_PRINCIPAL%invalidpass && failed=`expr $failed + 1`
116 testit_expect_failure "Test login with user kerberos ccache, but old password specified" \
117 $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -k yes -U$TEST_PRINCIPAL%$TEST_PASSWORD_OLD && failed=`expr $failed + 1`
119 rm -f $KRB5CCNAME_PATH
121 ###########################################################
122 ### Set the password with smbpasswd
123 ###########################################################
125 cat > $PREFIX/tmpsmbpasswdscript <<EOF
126 expect New SMB password:
127 send ${TEST_PASSWORD_NEW}\n
128 expect Retype new SMB password:
129 send ${TEST_PASSWORD_NEW}\n
132 testit "set user password with smbpasswd" \
133 $texpect $PREFIX/tmpsmbpasswdscript $smbpasswd -L -c $PREFIX/etc/smb.conf $TEST_USERNAME || failed=`expr $failed + 1`
135 TEST_PASSWORD=$TEST_PASSWORD_NEW
136 TEST_PASSWORD_NEW="testPaSS@03%"
138 test_smbclient "Test login with user (ntlm)" \
139 "ls" "$SMB_UNC" -k no -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed=`expr $failed + 1`
141 testit "set password on user locally" $VALGRIND $samba_tool user setpassword $TEST_USERNAME $CONFIG --newpassword=$TEST_PASSWORD_NEW --must-change-at-next-login || failed=`expr $failed + 1`
143 TEST_PASSWORD=$TEST_PASSWORD_NEW
144 TEST_PASSWORD_NEW="testPaSS@04%"
146 test_smbclient_expect_failure "Test login with user (NT_STATUS_PASSWORD_MUST_CHANGE)" \
147 "ls" "$SMB_UNC" -k no -U$TEST_PRINCIPAL%$TEST_PASSWORD && failed=`expr $failed + 1`
149 testit "change user password with 'samba-tool user password' (after must change flag set)" \
150 $VALGRIND $samba_tool user password -W$DOMAIN -U$DOMAIN/$TEST_USERNAME%$TEST_PASSWORD -k no --newpassword=$TEST_PASSWORD_NEW || failed=`expr $failed + 1`
152 TEST_PASSWORD=$TEST_PASSWORD_NEW
153 TEST_PASSWORD_NEW="testPaSS@05%"
155 test_smbclient "Test login with user kerberos" 'ls' "$SMB_UNC" -k yes -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed=`expr $failed + 1`
157 rm -f $KRB5CCNAME_PATH
159 cat > $PREFIX/tmpsmbpasswdscript <<EOF
160 expect Old SMB password:
161 password ${TEST_PASSWORD}\n
162 expect New SMB password:
163 send ${TEST_PASSWORD_NEW}\n
164 expect Retype new SMB password:
165 send ${TEST_PASSWORD_NEW}\n
168 testit "change user password with smbpasswd (after must change flag set)" \
169 $texpect $PREFIX/tmpsmbpasswdscript $smbpasswd -r $SERVER -c $PREFIX/etc/smb.conf -U $TEST_USERNAME || failed=`expr $failed + 1`
171 TEST_PASSWORD=$TEST_PASSWORD_NEW
172 TEST_PASSWORD_NEW="testPaSS@06%"
174 test_smbclient "Test login with user kerberos" \
175 "ls" "$SMB_UNC" -k yes -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed=`expr $failed + 1`
177 rm -f $KRB5CCNAME_PATH
179 testit_expect_failure "try to set a non-complex password (command should not succeed)" \
180 $VALGRIND $samba_tool user password -W$DOMAIN "-U$DOMAIN/$TEST_USERNAME%$TEST_PASSWORD" -k no --newpassword="$TEST_PASSWORD_WEAK" && failed=`expr $failed + 1`
182 testit "allow non-complex passwords" \
183 $VALGRIND $samba_tool domain passwordsettings set $CONFIG --complexity=off || failed=`expr $failed + 1`
185 testit "try to set a non-complex password (command should succeed)" \
186 $VALGRIND $samba_tool user password -W$DOMAIN "-U$DOMAIN/$TEST_USERNAME%$TEST_PASSWORD" -k no --newpassword="$TEST_PASSWORD_WEAK" || failed=`expr $failed + 1`
188 TEST_PASSWORD=$TEST_PASSWORD_WEAK
190 test_smbclient "test login with non-complex password" \
191 "ls" "$SMB_UNC" -k no -U$TEST_PRINCIPAL%$TEST_PASSWORD || failed=`expr $failed + 1`
193 testit_expect_failure "try to set a short password (command should not succeed)" \
194 $VALGRIND $samba_tool user password -W$DOMAIN "-U$DOMAIN/$TEST_USERNAME%$TEST_PASSWORD" -k no --newpassword="$TEST_PASSWORD_SHORT" && failed=`expr $failed + 1`
196 testit "allow short passwords (length 1)" \
197 $VALGRIND $samba_tool domain passwordsettings $CONFIG set --min-pwd-length=1 || failed=`expr $failed + 1`
199 testit "try to set a short password (command should succeed)" \
200 $VALGRIND $samba_tool user password -W$DOMAIN "-U$DOMAIN/$TEST_USERNAME%$TEST_PASSWORD" -k no --newpassword="$TEST_PASSWORD_SHORT" || failed=`expr $failed + 1`
202 TEST_PASSWORD=$TEST_PASSWORD_SHORT
203 TEST_PASSWORD_NEW="testPaSS@07%"
205 testit "require minimum password age of 1 day" \
206 $VALGRIND $samba_tool domain passwordsettings $CONFIG set --min-pwd-age=1 || failed=`expr $failed + 1`
208 testit "show password settings" \
209 $VALGRIND $samba_tool domain passwordsettings $CONFIG show || failed=`expr $failed + 1`
211 testit_expect_failure "try to change password too quickly (command should not succeed)" \
212 $VALGRIND $samba_tool user password -W$DOMAIN "-U$DOMAIN/$TEST_USERNAME%$TEST_PASSWORD" -k no --newpassword="$TEST_PASSWORD_NEW" && failed=`expr $failed + 1`
214 testit "reset password policies" \
215 $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`
217 testit "delete user $TEST_USERNAME" \
218 $VALGRIND $samba_tool user delete $TEST_USERNAME -U"$USERNAME%$PASSWORD" $CONFIG -k no || failed=`expr $failed + 1`
220 rm -f $PREFIX/tmpuserpassfile $PREFIX/tmpsmbpasswdscript
221 rm -f $KRB5CCNAME_PATH
223 exit $failed