smbd: Remove get_Protocol()
[Samba.git] / testprogs / blackbox / test_pdbtest.sh
blob2f4fad7e464793042f2c64884c7ab49cd6dc2e31
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 test_smbpasswd()
34 user=$1
35 newpass=$2
37 echo "set password with smbpasswd"
38 tmpfile=$PREFIX/smbpasswd_change_password_script
39 cat >$tmpfile <<EOF
40 expect New SMB password:
41 send ${newpass}\n
42 expect Retype new SMB password:
43 send ${newpass}\n
44 EOF
46 cmd='UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $texpect $tmpfile $smbpasswd -L $user -c $SMB_CONF'
47 eval echo "$cmd"
48 out=$(eval $cmd)
49 ret=$?
50 rm -f $tmpfile
52 if [ $ret -ne 0 ]; then
53 echo "Failed to change user password $user"
54 return 1
58 testit "pdbtest" $VALGRIND $BINDIR/pdbtest -u $USER "$@" || failed=$(expr $failed + 1)
60 NEWUSERPASS=testPaSS@01%
62 echo "set password with pdbedit"
63 cat >$PREFIX/tmpsmbpasswdscript <<EOF
64 expect new password:
65 send ${NEWUSERPASS}\n
66 expect retype new password:
67 send ${NEWUSERPASS}\n
68 EOF
70 testit "create user with pdbedit" $texpect $PREFIX/tmpsmbpasswdscript $VALGRIND $pdbedit --configfile=$SMB_CONF -a $USER --account-desc="pdbedit-test-user" "$@" || failed=$(expr $failed + 1)
71 USERPASS=$NEWUSERPASS
73 test_smbclient "Test login with user (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS "$@" || failed=$(expr $failed + 1)
75 testit "modify user" $VALGRIND $pdbedit --configfile=$SMB_CONF --modify $USER --drive="D:" "$@" || failed=$(expr $failed + 1)
77 test_smbclient "Test login with user (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS "$@" || failed=$(expr $failed + 1)
79 NEWUSERPASS=testPaSS@02%
81 testit "set user password with smbpasswd" \
82 test_smbpasswd $USER $NEWUSERPASS ||
83 failed=$(expr $failed + 1)
85 USERPASS=$NEWUSERPASS
87 test_smbclient "Test login with user (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS "$@" || failed=$(expr $failed + 1)
89 testit "modify user - disabled" $VALGRIND $net sam set disabled $USER yes "$@" || failed=$(expr $failed + 1)
91 testit_expect_failure "Test login with disabled suer" $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -U$USER@%$USERPASS || failed=$(expr $failed + 1)
93 testit "modify user - enabled" $VALGRIND $net sam set disabled $USER no "$@" || failed=$(expr $failed + 1)
95 test_smbclient "Test login with re-enabled user (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS || failed=$(expr $failed + 1)
97 testit "modify user - must change password now" $VALGRIND $net sam set pwdmustchangenow $USER yes "$@" || failed=$(expr $failed + 1)
99 testit_expect_failure "Test login with expired password" $VALGRIND $smbclient //$SERVER/tmp -c 'ls' -U$USER@%$USERPASS || failed=$(expr $failed + 1)
101 testit "modify user - disable password expiry" $VALGRIND $net sam set pwnoexp $USER yes "$@" || failed=$(expr $failed + 1)
103 test_smbclient "Test login with no expiry (ntlm)" 'ls' "$unc" -U$USER%$NEWUSERPASS || failed=$(expr $failed + 1)
105 NEWUSERPASS=testPaSS@03%
106 NEWUSERHASH=062519096c45739c1938800f80906731
108 testit "Set user password with password hash" $VALGRIND $pdbedit --configfile=$SMB_CONF -u $USER --set-nt-hash $NEWUSERHASH "$@" || failed=$(expr $failed + 1)
110 test_smbclient "Test login with new password (from hash)" 'ls' "$unc" -U$USER%$NEWUSERPASS || failed=$(expr $failed + 1)
112 testit "del user" $VALGRIND $pdbedit --configfile=$SMB_CONF -x $USER "$@" || failed=$(expr $failed + 1)
114 rm $PREFIX/tmpsmbpasswdscript
116 exit $failed