5a41b8bd9da3cd60154957aaf59892662d1aa401
[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> and others
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|$test_root|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=$test_root"
38     echo "    WHOAMI=$whoami"
39     echo "    LOGLEVEL=$loglevel"
40     echo "    TREE=$tree"
41
42     case "$prefix" in
43     /usr*|/|//)
44         echo "** I don't want to clobber your installation in "
45         echo "**     $prefix"
46         echo "** by running tests there.  Please reconfigure this source tree to"
47         echo "** use a different prefix."
48         exit 1
49     esac
50
51     template_smb_conf_setup 
52     template_smb_conf_setup .hostsequiv
53     template_smb_conf_setup .invalidusers
54
55         echo "127.0.0.1    localhost">$prefix/lib/lmhosts
56         echo "127.0.0.2    BUILDFARM">>$prefix/lib/lmhosts
57     echo "127.0.0.3    SHARE">>$prefix/lib/lmhosts
58     echo "127.0.0.4    USER">>$prefix/lib/lmhosts
59     echo "127.0.0.5    SERVER">>$prefix/lib/lmhosts
60     echo "127.0.0.6    DOMAIN">>$prefix/lib/lmhosts
61     echo "127.0.0.7    HOSTSEQUIV">>$prefix/lib/lmhosts
62
63         echo "127.0.0.1" > $prefix/lib/hosts.equiv
64
65     cp basicsmb.smb.conf.share $prefix/lib/smb.conf.share
66     cp basicsmb.smb.conf.user $prefix/lib/smb.conf.user
67     cp basicsmb.smb.conf.server $prefix/lib/smb.conf.server
68     cp basicsmb.smb.conf.domain $prefix/lib/smb.conf.domain
69
70     touch $prefix/lib/smb.conf.
71     touch $prefix/lib/smb.conf.localhost
72 }
73
74 test_smbpasswd() {
75         test_smbpasswd_password="$1"
76         rm -f $prefix/private/smbpasswd
77         echo "( echo $test_smbpasswd_password ; echo $test_smbpasswd_password; ) | $prefix/bin/smbpasswd -L -s -a $whoami"
78         ( echo $test_smbpasswd_password; echo $test_smbpasswd_password; ) | $prefix/bin/smbpasswd -L -s -a $whoami
79         status=$?
80         if [ $status = 0 ]; then
81             echo "smbpasswd correctly set initial password ($test_smbpasswd_password)"
82         else
83             echo "smbpasswd failed to set initial password ($test_smbpasswd_password)! (status $status)"
84             return 1
85         fi
86         return 0
87 }
88
89 test_smbpasswd_remote() {
90         test_smbpasswd_rem_password="$1"
91         test_smbpasswd_rem_newpassword="$2"
92         echo "( echo $test_smbpasswd_rem_password; echo $test_smbpasswd_rem_newpassword; echo $test_smbpasswd_rem_newpassword; ) | $prefix/bin/smbpasswd -r localhost -s -U $whoami"
93         ( echo $test_smbpasswd_rem_password; echo $test_smbpasswd_rem_newpassword; echo $test_smbpasswd_rem_newpassword; ) | $prefix/bin/smbpasswd -r localhost -s -U $whoami
94         status=$?
95         if [ $status = 0 ]; then
96             echo "smbpasswd correctly remotely changed password ($test_smbpasswd_rem_password -> $test_smbpasswd_rem_newpassword)"
97         else
98             echo "smbpasswd failed to remotely changed password ($test_smbpasswd_rem_password -> $test_smbpasswd_rem_newpassword)! (status $status)"
99             return 1
100         fi
101         return 0
102 }
103
104 test_smbpasswd_local() {
105         test_smbpasswd_newpassword="$2"
106         echo "( echo $test_smbpasswd_newpassword ; echo $test_smbpasswd_newpassword; ) | $prefix/bin/smbpasswd -L -s $whoami"
107         ( echo $test_smbpasswd_newpassword ; echo $test_smbpasswd_newpassword; ) | $prefix/bin/smbpasswd -L -s $whoami
108         status=$?
109         if [ $status = 0 ]; then
110             echo "smbpasswd correctly locally changed password ($test_smbpasswd_password -> $test_smbpasswd_newpassword)"
111         else
112             echo "smbpasswd failed to locallly changed password ($test_smbpasswd_password -> $test_smbpasswd_newpassword)! (status $status)"
113             return 1
114         fi
115         return 0
116 }
117
118 test_listfilesauth() {
119         remote_name="$1"
120         echo $prefix/bin/smbclient //$remote_name/samba  -n buildclient -U$whoami%$password -c 'ls'
121         $prefix/bin/smbclient //$remote_name/samba  -n buildclient -U$whoami%$password -c 'ls'
122         status=$?
123         if [ $status = 0 ]; then
124                 echo "listed files OK"
125         else 
126                 echo "listing files with smbd failed with status $status"
127                 return 1
128         fi
129         return 0
130 }
131
132 test_listfilesnpw() {
133         remote_name="$1"
134         echo $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%  -c 'ls'
135         $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami% -c 'ls'
136         status=$?
137         if [ $status = 0 ]; then
138                 echo "smbd listed files with NO PASSWORD on an authenticated share!"
139                 return 1
140         else 
141                 echo "listing files with smbd failed with status $status (correct)"
142         fi
143         return 0
144 }
145
146 test_listfilesauth_should_deny() {
147         remote_name="$1"
148         echo $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%$password  -c 'ls'
149         $prefix/bin/smbclient //$remote_name/samba -n buildclient -U$whoami%$password -c 'ls'
150         status=$?
151         if [ $status = 0 ]; then
152                 echo "smbd LISTED FILES despite smb.conf entires to the contary!"
153                 return 1
154         else 
155                 echo "listing files with smbd failed with status $status (correct)"
156         fi
157         return 0
158 }
159
160 echo "LIBSMB_PROG=$LIBSMB_PROG" >&2
161
162
163
164 # Give sensible defaults to some variables.  
165
166 # "What's my age again?"
167
168 if [ ! $USER = "" ]; then
169     whoami=$USER
170 else 
171     if [ ! $LOGNAME = "" ]; then
172         whoami=$LOGNAME
173     else
174         whoami=build
175     fi
176 fi
177
178
179
180 if test -z "$loglevel"
181 then
182     loglevel=1
183 fi
184