Give sensible defaults to some variables that are set by the build
[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 # Really what we want is a consistent way to pass the location of the
19 # configuration and all other files into *all* Samba programs
20 # (smbclient, smd, ...) and be able to set them to a temporary
21 # directory when testing.  Some of them take a -c parameter, but tpot
22 # says it's not done consistently.
23
24 template_smb_conf_setup() {
25         cat basicsmb.smb.conf$1.template | \
26               sed "s|PREFIX|$prefix|g" | \
27               sed "s|BUILD_FARM|$pwd|g" | \
28               sed "s|WHOAMI|$whoami|g" | \
29               sed "s|LOGLEVEL|$loglevel|g" \
30         > $prefix/lib/smb.conf$1
31         echo "template_smb_conf_setup: Created $prefix/lib/smb.conf$1"
32 }
33
34 test_smb_conf_setup() {
35     echo "test_smb_conf_setup: Configuring: "
36     echo "    PREFIX=$prefix"
37     echo "    BUILD_FARM=$pwd"
38     echo "    WHOAMI=$whoami"
39     echo "    LOGLEVEL=$loglevel"
40
41     case "$prefix" in
42     /usr*|/|//)
43         echo "** I don't want to clobber your installation in "
44         echo "**     $prefix"
45         echo "** by running tests there.  Please reconfigure this source tree to"
46         echo "** use a different prefix."
47         exit 1
48     esac
49
50     template_smb_conf_setup 
51     template_smb_conf_setup .hostsequiv
52     template_smb_conf_setup .invalidusers
53
54         echo "127.0.0.1    localhost">$prefix/lib/lmhosts
55         echo "127.0.0.2    BUILDFARM">>$prefix/lib/lmhosts
56     echo "127.0.0.3    SHARE">>$prefix/lib/lmhosts
57     echo "127.0.0.4    USER">>$prefix/lib/lmhosts
58     echo "127.0.0.5    SERVER">>$prefix/lib/lmhosts
59     echo "127.0.0.6    DOMAIN">>$prefix/lib/lmhosts
60     echo "127.0.0.7    HOSTSEQUIV">>$prefix/lib/lmhosts
61
62         echo "127.0.0.1" > $prefix/lib/hosts.equiv
63
64     cp basicsmb.smb.conf.share $prefix/lib/smb.conf.share
65     cp basicsmb.smb.conf.user $prefix/lib/smb.conf.user
66     cp basicsmb.smb.conf.server $prefix/lib/smb.conf.server
67     cp basicsmb.smb.conf.domain $prefix/lib/smb.conf.domain
68
69     touch $prefix/lib/smb.conf.
70     touch $prefix/lib/smb.conf.localhost
71 }
72
73 test_smbpasswd() {
74         test_smbpasswd_password="$1"
75         rm -f $prefix/private/smbpasswd
76         echo "( echo $test_smbpasswd_password ; echo $test_smbpasswd_password; ) | $prefix/bin/smbpasswd -L -s -a $whoami"
77         ( echo $password ; echo $password; ) | $prefix/bin/smbpasswd -L -s -a $whoami
78         status=$?
79         if [ $status = 0 ]; then
80             echo "smbpasswd correctly set initial password ($test_smbpasswd_password)"
81         else
82             echo "smbpasswd failed to set initial password ($test_smbpasswd_password)! (status $status)"
83             return 1
84         fi
85         return 0
86 }
87
88 test_listfilesauth() {
89         remote_name="$1"
90         echo $prefix/bin/smbclient//$remote_name/samba  -n buildclient -U$whoami%$password -c 'ls'
91         $prefix/bin/smbclient //$remote_name/samba  -n buildclient -U$whoami%$password -c 'ls'
92         status=$?
93         if [ $status = 0 ]; then
94                 echo "listed files OK"
95         else 
96                 echo "listing files with smbd failed with status $status"
97                 return 1
98         fi
99         return 0
100 }
101
102 test_listfilesnpw() {
103         remote_name="$1"
104         echo $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%  -c 'ls'
105         $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami% -c 'ls'
106         status=$?
107         if [ $status = 0 ]; then
108                 echo "smbd listed files with NO PASSWORD on an authenticated share!"
109                 return 1
110         else 
111                 echo "listing files with smbd failed with status $status (correct)"
112         fi
113         return 0
114 }
115
116 test_listfilesauth_should_deny() {
117         remote_name="$1"
118         echo $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%$password  -c 'ls'
119         $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%$password -c 'ls'
120         status=$?
121         if [ $status = 0 ]; then
122                 echo "smbd LISTED FILES despite smb.conf entires to the contary!"
123                 return 1
124         else 
125                 echo "listing files with smbd failed with status $status (correct)"
126         fi
127         return 0
128 }
129
130 echo "LIBSMB_PROG=$LIBSMB_PROG" >&2
131
132
133
134 # Give sensible defaults to some variables.  
135
136 # "What's my age again?"
137
138 if [ ! $USER = "" ]; then
139     whoami=$USER
140 else 
141     if [ ! $LOGNAME = "" ]; then
142         whoami=$LOGNAME
143     else
144         whoami=build
145     fi
146 fi
147
148
149
150 if test -z "$loglevel"
151 then
152     loglevel=1
153 fi
154
155
156 pwd=`pwd`