CVE-2020-25718 tests/krb5: Fix indentation
[Samba.git] / testprogs / blackbox / test_pdbtest.sh
blob43852b3aabe1585ce4148023d27e45d3b61a336a
1 #!/bin/sh
2 # Blackbox tests for pdbtest
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2006-2012 Andrew Bartlett <abartlet@samba.org>
6 if [ $# -lt 2 ]; then
7 cat <<EOF
8 Usage: test_pdbtest.sh SERVER PREFIX USER SMBCLIENT SMB_CONF
9 EOF
10 exit 1;
13 SERVER=$1
14 PREFIX=$2
15 USER=$3
16 smbclient=$4
17 SMB_CONF=$5
18 shift 5
19 failed=0
21 samba4bindir="$BINDIR"
22 pdbtest="$samba4bindir/pdbtest"
23 pdbedit="$samba4bindir/pdbedit"
24 net="$samba4bindir/net"
25 smbpasswd="$samba4bindir/smbpasswd"
26 texpect="$samba4bindir/texpect"
27 unc="//$SERVER/tmp"
29 . `dirname $0`/subunit.sh
30 . `dirname $0`/common_test_fns.inc
32 UID_WRAPPER_ROOT=1
33 export UID_WRAPPER_ROOT
35 test_smbpasswd()
37 user=$1
38 newpass=$2
40 echo "set password with smbpasswd"
41 tmpfile=$PREFIX/smbpasswd_change_password_script
42 cat > $tmpfile <<EOF
43 expect New SMB password:
44 send ${newpass}\n
45 expect Retype new SMB password:
46 send ${newpass}\n
47 EOF
49 cmd='UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $texpect $tmpfile $smbpasswd -L $user -c $SMB_CONF'
50 eval echo "$cmd"
51 out=$(eval $cmd)
52 ret=$?
53 rm -f $tmpfile
55 if [ $ret -ne 0 ]; then
56 echo "Failed to change user password $user"
57 return 1
61 testit "pdbtest" $VALGRIND $BINDIR/pdbtest -u $USER $@ || failed=`expr $failed + 1`
63 NEWUSERPASS=testPaSS@01%
65 echo "set password with pdbedit"
66 cat > $PREFIX/tmpsmbpasswdscript <<EOF
67 expect new password:
68 send ${NEWUSERPASS}\n
69 expect retype new password:
70 send ${NEWUSERPASS}\n
71 EOF
73 testit "create user with pdbedit" $texpect $PREFIX/tmpsmbpasswdscript $VALGRIND $pdbedit --configfile=$SMB_CONF -a $USER --account-desc="pdbedit-test-user" $@ || failed=`expr $failed + 1`
74 USERPASS=$NEWUSERPASS
76 test_smbclient "Test login with user (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS $@ || failed=`expr $failed + 1`
78 testit "modify user" $VALGRIND $pdbedit --configfile=$SMB_CONF --modify $USER --drive="D:" $@ || failed=`expr $failed + 1`
80 test_smbclient "Test login with user (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS $@|| failed=`expr $failed + 1`
82 NEWUSERPASS=testPaSS@02%
84 testit "set user password with smbpasswd" \
85 test_smbpasswd $USER $NEWUSERPASS \
86 || failed=$(expr $failed + 1)
88 USERPASS=$NEWUSERPASS
90 test_smbclient "Test login with user (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS $@|| failed=`expr $failed + 1`
92 testit "modify user - disabled" $VALGRIND $net sam set disabled $USER yes $@ || failed=`expr $failed + 1`
94 testit_expect_failure "Test login with disabled suer" $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -U$USER@%$USERPASS && failed=`expr $failed + 1`
96 testit "modify user - enabled" $VALGRIND $net sam set disabled $USER no $@ || failed=`expr $failed + 1`
98 test_smbclient "Test login with re-enabled user (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS || failed=`expr $failed + 1`
100 testit "modify user - must change password now" $VALGRIND $net sam set pwdmustchangenow $USER yes $@ || failed=`expr $failed + 1`
102 testit_expect_failure "Test login with expired password" $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -U$USER@%$USERPASS && failed=`expr $failed + 1`
104 testit "modify user - disable password expiry" $VALGRIND $net sam set pwnoexp $USER yes $@ || failed=`expr $failed + 1`
106 test_smbclient "Test login with no expiry (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS || failed=`expr $failed + 1`
108 NEWUSERPASS=testPaSS@03%
109 NEWUSERHASH=062519096c45739c1938800f80906731
111 testit "Set user password with password hash" $VALGRIND $pdbedit --configfile=$SMB_CONF -u $USER --set-nt-hash $NEWUSERHASH $@ || failed=`expr $failed + 1`
113 test_smbclient "Test login with new password (from hash)" 'ls' "$unc" -U$USER%$NEWUSERPASS || failed=`expr $failed + 1`
115 testit "del user" $VALGRIND $pdbedit --configfile=$SMB_CONF -x $USER $@ || failed=`expr $failed + 1`
117 rm $PREFIX/tmpsmbpasswdscript
119 exit $failed