e8f90060de834e51ca59f513bc2f8d61345a5ab0
[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 # Generate random file
41 cat >tmpfile<<EOF
42 foo
43 bar
44 bloe
45 blah
46 EOF
47
48 # put that file
49 echo mput tmpfile | runcmd "MPutting file" || failed=`expr $failed + 1`
50 # check file info
51 echo altname tmpfile | runcmd "Getting alternative name" || failed=`expr $failed + 1`
52 # run allinfo on that file
53 echo allinfo tmpfile | runcmd "Checking info on file" || failed=`expr $failed + 1`
54 # get that file
55 mv tmpfile tmpfile-old
56 echo mget tmpfile | runcmd "MGetting file" || failed=`expr $failed + 1`
57 # remove that file
58 echo rm tmpfile | runcmd "Removing file" || failed=`expr $failed + 1`
59 # compare locally
60 testit "Comparing files" diff tmpfile-old tmpfile || failed=`expr $failed + 1`
61 # create directory
62 # cd to directory
63 # cd to top level directory
64 # remove directory
65 echo "mkdir bla; cd bla; cd ..; rmdir bla" | runcmd "Creating directory, Changing directory, Going back, " || failed=`expr $failed + 1`
66 # enable recurse, create nested directory
67 echo "recurse; echo mkdir bla/bloe; exit" | runcmd "Creating nested directory" || failed=`expr $failed + 1`
68 # remove parent directory
69 echo rmdir bla/bloe | runcmd "Removing directory" || failed=`expr $failed + 1`
70 # remove child directory
71 echo rmdir bla | runcmd "Removing directory" || failed=`expr $failed + 1`
72 # run fsinfo
73 echo fsinfo objectid | runcmd "Getting file system info" || failed=`expr $failed + 1`
74
75 # put that file
76 echo put tmpfile | runcmd "Putting file" || failed=`expr $failed + 1`
77 # get that file
78 mv tmpfile tmpfile-old
79 echo get tmpfile | runcmd "Getting file" || failed=`expr $failed + 1`
80 # remove that file
81 echo rm tmpfile | runcmd "Removing file" || failed=`expr $failed + 1`
82 # compare locally
83 testit "Comparing files" diff tmpfile-old tmpfile || failed=`expr $failed + 1`
84 # put that file
85 echo put tmpfile tmpfilex | runcmd "Putting file with different name" || failed=`expr $failed + 1`
86 # get that file
87 echo get tmpfilex | runcmd "Getting file again" || failed=`expr $failed + 1`
88 # compare locally
89 testit "Comparing files" diff tmpfilex tmpfile || failed=`expr $failed + 1`
90 # remove that file
91 echo rm tmpfilex | runcmd "Removing file" || failed=`expr $failed + 1`
92
93 # do some simple operations using old protocol versions
94 echo ls | runcmd "List directory with LANMAN1" -m LANMAN1 || failed=`expr $failed + 1`
95 echo ls | runcmd "List directory with LANMAN2" -m LANMAN2 || failed=`expr $failed + 1`
96
97 echo ls | testit "Test login with --machine-pass" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp --machine-pass  || failed=`expr $failed + 1`
98
99 (
100     echo "password=$PASSWORD"
101     echo "username=$USERNAME"
102     echo "domain=$DOMAIN"
103 ) > tmpauthfile
104
105 echo ls | testit "Test login with --authentication-file" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp --authentication-file=tmpauthfile  || failed=`expr $failed + 1`
106
107 PASSWD_FILE="tmppassfile" 
108 echo "$PASSWORD" > $PASSWD_FILE
109 export PASSWD_FILE
110 echo ls | testit "Test login with PASSWD_FILE" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" -U"$USERNAME" || failed=`expr $failed + 1`
111 PASSWD_FILE=""
112 export PASSWD_FILE
113 unset PASSWD_FILE
114
115 PASSWD="$PASSWORD" 
116 export PASSWD
117 echo ls | testit "Test login with PASSWD" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" -U"$USERNAME" || failed=`expr $failed + 1`
118
119 oldUSER=$USER
120 USER="$USERNAME" 
121 export USER
122 echo ls | testit "Test login with USER and PASSWD" $VALGRIND bin/smbclient $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" | failed=`expr $failed + 1`
123 PASSWD=
124 export PASSWD
125 unset PASSWD
126 USER=$oldUSER
127 export USER
128
129 rm -f tmpfile tmpfile-old tmpfilex tmpauthfile tmppassfile
130 exit $failed