b3a00ea78393120f3646d12f558ab1d980dbdf7e
[ira/wip.git] / testsuite / build_farm / basicsmb.fns
1 #! /bin/sh
2
3 # Common functions for Samba build scripts.
4
5 # Copyright (C) 2001 by Martin Pool <mbp@samba.org>
6
7 # The following variables are passed in by the calling script.  They
8 # originate in either the buildfarm scripts or the configured
9 # Makefile.
10
11 # PREFIX = Installed prefix of samba test installation.  Used to
12 # locate binaries, configuration files, etc.  
13
14 # XXX: It's pretty bad to clobber the installed configuration file and
15 # other data in $prefix, because somebody might unwittingly run this
16 # with prefix=/usr.  
17
18 template_smb_conf_setup() {
19         cat basicsmb.smb.conf$1.template | \
20               sed "s|PREFIX|$prefix|g" | \
21               sed "s|BUILD_FARM|$pwd|g" | \
22               sed "s|WHOAMI|$whoami|g" | \
23               sed "s|LOGLEVEL|$loglevel|g" \
24         > $prefix/lib/smb.conf$1
25         echo "template_smb_conf_setup: Created $prefix/lib/smb.conf$1"
26 }
27
28 test_smb_conf_setup() {
29     echo "test_smb_conf_setup: Configuring: "
30     echo "    PREFIX=$prefix"
31     echo "    BUILD_FARM=$pwd"
32     echo "    WHOAMI=$whoami"
33     echo "    LOGLEVEL=$loglevel"
34
35     case "$prefix" in
36     /usr*|/|//)
37         echo "** I don't want to clobber your installation in "
38         echo "**     $prefix"
39         echo "** by running tests there.  Please reconfigure this source tree to"
40         echo "** use a different prefix."
41         exit 1
42     esac
43
44     template_smb_conf_setup 
45     template_smb_conf_setup .hostsequiv
46     template_smb_conf_setup .invalidusers
47
48         echo "127.0.0.1    localhost">$prefix/lib/lmhosts
49         echo "127.0.0.2    BUILDFARM">>$prefix/lib/lmhosts
50     echo "127.0.0.3    SHARE">>$prefix/lib/lmhosts
51     echo "127.0.0.4    USER">>$prefix/lib/lmhosts
52     echo "127.0.0.5    SERVER">>$prefix/lib/lmhosts
53     echo "127.0.0.6    DOMAIN">>$prefix/lib/lmhosts
54     echo "127.0.0.7    HOSTSEQUIV">>$prefix/lib/lmhosts
55
56         echo "127.0.0.1" > $prefix/lib/hosts.equiv
57
58     cp basicsmb.smb.conf.share $prefix/lib/smb.conf.share
59     cp basicsmb.smb.conf.user $prefix/lib/smb.conf.user
60     cp basicsmb.smb.conf.server $prefix/lib/smb.conf.server
61     cp basicsmb.smb.conf.domain $prefix/lib/smb.conf.domain
62
63     touch $prefix/lib/smb.conf.
64     touch $prefix/lib/smb.conf.localhost
65 }
66
67 test_smbpasswd() {
68         test_smbpasswd_password="$1"
69         rm -f $prefix/private/smbpasswd
70         echo "( echo $test_smbpasswd_password ; echo $test_smbpasswd_password; ) | $prefix/bin/smbpasswd -L -s -a $whoami"
71         ( echo $password ; echo $password; ) | $prefix/bin/smbpasswd -L -s -a $whoami
72         status=$?
73         if [ $status = 0 ]; then
74             echo "smbpasswd correctly set initial password ($test_smbpasswd_password)"
75         else
76             echo "smbpasswd failed to set initial password ($test_smbpasswd_password)! (status $status)"
77             return 1
78         fi
79         return 0
80 }
81
82 test_listfilesauth() {
83         remote_name="$1"
84         echo $prefix/bin/smbclient//$remote_name/samba  -n buildclient -U$whoami%$password -c 'ls'
85         $prefix/bin/smbclient //$remote_name/samba  -n buildclient -U$whoami%$password -c 'ls'
86         status=$?
87         if [ $status = 0 ]; then
88                 echo "listed files OK"
89         else 
90                 echo "listing files with smbd failed with status $status"
91                 return 1
92         fi
93         return 0
94 }
95
96 test_listfilesnpw() {
97         remote_name="$1"
98         echo $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%  -c 'ls'
99         $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami% -c 'ls'
100         status=$?
101         if [ $status = 0 ]; then
102                 echo "smbd listed files with NO PASSWORD on an authenticated share!"
103                 return 1
104         else 
105                 echo "listing files with smbd failed with status $status (correct)"
106         fi
107         return 0
108 }
109
110 test_listfilesauth_should_deny() {
111         remote_name="$1"
112         echo $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%$password  -c 'ls'
113         $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%$password -c 'ls'
114         status=$?
115         if [ $status = 0 ]; then
116                 echo "smbd LISTED FILES despite smb.conf entires to the contary!"
117                 return 1
118         else 
119                 echo "listing files with smbd failed with status $status (correct)"
120         fi
121         return 0
122 }
123
124 echo "LIBSMB_PROG=$LIBSMB_PROG" >&2