413b680a529604a5d906f1e16525905349d48fee
[samba.git] / testprogs / blackbox / test_smbclient.sh
1 #!/bin/sh
2
3 if [ $# -lt 5 ]; then
4 cat <<EOF
5 Usage: test_smbclient.sh SERVER USERNAME PASSWORD DOMAIN PREFIX
6 EOF
7 exit 1;
8 fi
9
10 SERVER=$1
11 USERNAME=$2
12 PASSWORD=$3
13 DOMAIN=$4
14 PREFIX=$5
15 shift 5
16 failed=0
17
18 testit() {
19         name="$1"
20         shift
21         cmdline="$*"
22         echo "test: $name"
23         $cmdline
24         status=$?
25         if [ x$status = x0 ]; then
26                 echo "success: $name"
27         else
28                 echo "failure: $name"
29         fi
30         return $status
31 }
32
33 runcmd() {
34         name="$1"
35         shift
36         testit "$name" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" -U"$USERNAME%$PASSWORD" $@
37         return $?
38 }
39
40 testit "domain join" $VALGRIND bin/net join $DOMAIN $CONFIGURATION  -W "$DOMAIN" -U"$USERNAME%$PASSWORD" $@ || failed=`expr $failed + 1`
41
42 # Generate random file
43 cat >tmpfile<<EOF
44 foo
45 bar
46 bloe
47 blah
48 EOF
49
50 # put that file
51 echo mput tmpfile | runcmd "MPutting file" || failed=`expr $failed + 1`
52 # check file info
53 echo altname tmpfile | runcmd "Getting alternative name" || failed=`expr $failed + 1`
54 # run allinfo on that file
55 echo allinfo tmpfile | runcmd "Checking info on file" || failed=`expr $failed + 1`
56 # get that file
57 mv tmpfile tmpfile-old
58 echo mget tmpfile | runcmd "MGetting file" || failed=`expr $failed + 1`
59 # remove that file
60 echo rm tmpfile | runcmd "Removing file" || failed=`expr $failed + 1`
61 # compare locally
62 testit "Comparing files" diff tmpfile-old tmpfile || failed=`expr $failed + 1`
63 # create directory
64 # cd to directory
65 # cd to top level directory
66 # remove directory
67 echo "mkdir bla; cd bla; cd ..; rmdir bla" | runcmd "Creating directory, Changing directory, Going back, " || failed=`expr $failed + 1`
68 # enable recurse, create nested directory
69 echo "recurse; echo mkdir bla/bloe; exit" | runcmd "Creating nested directory" || failed=`expr $failed + 1`
70 # remove parent directory
71 echo rmdir bla/bloe | runcmd "Removing directory" || failed=`expr $failed + 1`
72 # remove child directory
73 echo rmdir bla | runcmd "Removing directory" || failed=`expr $failed + 1`
74 # run fsinfo
75 echo fsinfo objectid | runcmd "Getting file system info" || failed=`expr $failed + 1`
76
77 # put that file
78 echo put tmpfile | runcmd "Putting file" || failed=`expr $failed + 1`
79 # get that file
80 mv tmpfile tmpfile-old
81 echo get tmpfile | runcmd "Getting file" || failed=`expr $failed + 1`
82 # remove that file
83 echo rm tmpfile | runcmd "Removing file" || failed=`expr $failed + 1`
84 # compare locally
85 testit "Comparing files" diff tmpfile-old tmpfile || failed=`expr $failed + 1`
86 # put that file
87 echo put tmpfile tmpfilex | runcmd "Putting file with different name" || failed=`expr $failed + 1`
88 # get that file
89 echo get tmpfilex | runcmd "Getting file again" || failed=`expr $failed + 1`
90 # compare locally
91 testit "Comparing files" diff tmpfilex tmpfile || failed=`expr $failed + 1`
92 # remove that file
93 echo rm tmpfilex | runcmd "Removing file" || failed=`expr $failed + 1`
94
95 # do some simple operations using old protocol versions
96 echo ls | runcmd "List directory with LANMAN1" -m LANMAN1 || failed=`expr $failed + 1`
97 echo ls | runcmd "List directory with LANMAN2" -m LANMAN2 || failed=`expr $failed + 1`
98
99 echo ls | testit "Test login with --machine-pass without kerberos" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp --machine-pass -k no || failed=`expr $failed + 1`
100
101 echo ls | testit "Test login with --machine-pass and kerberos" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp --machine-pass -k yes || failed=`expr $failed + 1`
102
103 (
104     echo "password=$PASSWORD"
105     echo "username=$USERNAME"
106     echo "domain=$DOMAIN"
107 ) > tmpauthfile
108
109 echo ls | testit "Test login with --authentication-file" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp --authentication-file=tmpauthfile  || failed=`expr $failed + 1`
110
111 PASSWD_FILE="tmppassfile" 
112 echo "$PASSWORD" > $PASSWD_FILE
113 export PASSWD_FILE
114 echo ls | testit "Test login with PASSWD_FILE" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" -U"$USERNAME" || failed=`expr $failed + 1`
115 PASSWD_FILE=""
116 export PASSWD_FILE
117 unset PASSWD_FILE
118
119 PASSWD="$PASSWORD" 
120 export PASSWD
121 echo ls | testit "Test login with PASSWD" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" -U"$USERNAME" || failed=`expr $failed + 1`
122
123 oldUSER=$USER
124 USER="$USERNAME" 
125 export USER
126 echo ls | testit "Test login with USER and PASSWD" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" | failed=`expr $failed + 1`
127 PASSWD=
128 export PASSWD
129 unset PASSWD
130 USER=$oldUSER
131 export USER
132
133 rm -f tmpfile tmpfile-old tmpfilex tmpauthfile tmppassfile
134 exit $failed