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>
10 Usage: test_passwords_settings.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX
24 samba_bindir
="$BINDIR"
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
47 if test -x $samba_bindir/samba4kinit
; then
48 echo $password > $PREFIX/tmpuserpassfile
49 $samba_kinit --password-file=$PREFIX/tmpuserpassfile
$principal $@
51 echo $password |
$samba_kinit $principal $@
56 export UID_WRAPPER_ROOT
58 CONFIG
="--configfile=$PREFIX/etc/smb.conf"
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"
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