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