tests/ntlm_auth: Port ntlm_auth tests to python: ntlm_auth ntlm-server-1 with plainte...
[bbaumbach/samba-autobuild/.git] / source3 / script / tests / test_ntlm_auth_s3.sh
1 #!/bin/sh
2
3 if [ $# -lt 2 ]; then
4 cat <<EOF
5 Usage: test_ntlm_auth_s3.sh PYTHON SRC3DIR NTLM_AUTH
6 EOF
7 exit 1;
8 fi
9
10 PYTHON=$1
11 SRC3DIR=$2
12 NTLM_AUTH=$3
13 DOMAIN=$4
14 USERNAME=$5
15 PASSWORD=$6
16 shift 6
17 ADDARGS="$*"
18
19 incdir=`dirname $0`/../../../testprogs/blackbox
20 . $incdir/subunit.sh
21
22 SID=`eval $BINDIR/wbinfo -n $USERNAME | cut -d ' ' -f1`
23 BADSID=`eval $BINDIR/wbinfo -n $USERNAME | cut -d ' ' -f1 | sed 's/..$//'`
24
25 failed=0
26
27 test_ntlm_server_1_check_winbind_output_fail()
28 {
29         tmpfile=$PREFIX/ntlm_commands
30
31         # This isn't the correct password
32         cat > $tmpfile <<EOF
33 LANMAN-Challenge: 0123456789abcdef
34 NT-Response: 25a98c1c31e81847466b29b2df4680f39958fb8c213a9cc6
35 NT-Domain: $DOMAIN
36 Username: $USERNAME
37 Request-User-Session-Key: Yes
38 .
39 EOF
40         cmd='$NTLM_AUTH "$@" --helper-protocol=ntlm-server-1 < $tmpfile 2>&1'
41         eval echo "$cmd"
42         out=`eval $cmd`
43         ret=$?
44         rm -f $tmpfile
45
46         if [ $ret != 0 ] ; then
47                 echo "$out"
48                 echo "command failed"
49                 false
50                 return
51         fi
52
53         echo "$out" | grep "Authenticated: No" >/dev/null 2>&1
54
55         if [ $? = 0 ] ; then
56                 # failed to authenticate .. success
57                 true
58         else
59                 echo "incorrectly gave a successful authentication"
60                 false
61         fi
62 }
63
64 # This should work even with NTLMv2
65 testit "ntlm_auth ntlm-server-1 with incorrect fixed password against winbind" test_ntlm_server_1_check_winbind_output_fail || failed=`expr $failed + 1`
66
67 testok $0 $failed