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