s3-selftest: use absolute path when setting SOCKET_WRAPPER_DIR.
[abartlet/samba.git/.git] / source3 / script / tests / selftest.sh
1 #!/bin/sh
2
3 if [ $# -lt 2 ]; then
4         echo "$0 <directory> <all | quick> [-t <smbtorture4>] [-s <shrdir>] " \
5              "[-c <custom conf>]"
6         exit 1
7 fi
8
9 ##
10 ## Setup the required args
11 ##
12 DIRECTORY=$1; shift;
13 SUBTESTS=$1; shift;
14
15 ##
16 ## Parse oprtional args
17 ##
18 while getopts s:c:t: f
19 do
20     case $f in
21         t)      SMBTORTURE4=$OPTARG;;
22         s)      ALT_SHRDIR_ARG=$OPTARG;;
23         c)      CUSTOM_CONF_ARG=$OPTARG;;
24     esac
25 done
26
27 echo "Running selftest with the following"
28 echo "Selftest Directory: $DIRECTORY"
29 echo "Subtests to Run: $SUBTESTS"
30 echo "smbtorture4 Path: $SMBTORTURE4"
31 echo "Alternative Share Dir: $ALT_SHRDIR_ARG"
32 echo "Custom Configuration: $CUSTOM_CONF_ARG"
33
34 if [ $CUSTOM_CONF_ARG ]; then
35     INCLUDE_CUSTOM_CONF="include = $CUSTOM_CONF_ARG"
36 fi
37
38 ##
39 ## create the test directory
40 ##
41 PREFIX=`echo $DIRECTORY | sed s+//+/+`
42 mkdir -p $PREFIX || exit $?
43 OLD_PWD=`pwd`
44 cd $PREFIX || exit $?
45 PREFIX_ABS=`pwd`
46 cd $OLD_PWD
47
48 if [ -z "$TORTURE_MAXTIME" ]; then
49     TORTURE_MAXTIME=300
50 fi
51 export TORTURE_MAXTIME
52
53 ##
54 ## setup the various environment variables we need
55 ##
56
57 WORKGROUP=SAMBA-TEST
58 SERVER=localhost2
59 SERVER_IP=127.0.0.2
60 if [ ! "x$USER" = "x" ]; then
61     USERNAME=$USER
62 else
63     if [ ! "x$LOGNAME" = "x" ]; then
64         USERNAME=$LOGNAME
65     else
66         USERNAME=`PATH=/usr/ucb:$PATH whoami || id -un`
67     fi
68 fi
69 USERID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f1 | sed -e 's/uid=\([0-9]*\).*/\1/g'`
70 GROUPID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f2 | sed -e 's/gid=\([0-9]*\).*/\1/g'`
71 PASSWORD=test
72
73 SRCDIR="`dirname $0`/../.."
74 BINDIR="`pwd`/bin"
75 SCRIPTDIR=$SRCDIR/script/tests
76 LIBDIR=$PREFIX_ABS/lib
77 PIDDIR=$PREFIX_ABS/pid
78 CONFFILE=$LIBDIR/client.conf
79 SAMBA4CONFFILE=$LIBDIR/samba4client.conf
80 SERVERCONFFILE=$LIBDIR/server.conf
81 COMMONCONFFILE=$LIBDIR/common.conf
82 PRIVATEDIR=$PREFIX_ABS/private
83 LOCKDIR=$PREFIX_ABS/lockdir
84 LOGDIR=$PREFIX_ABS/logs
85 SOCKET_WRAPPER_DIR=$PREFIX_ABS/sw
86 CONFIGURATION="--configfile $CONFFILE"
87 SAMBA4CONFIGURATION="-s $SAMBA4CONFFILE"
88 NSS_WRAPPER_PASSWD="$PRIVATEDIR/passwd"
89 NSS_WRAPPER_GROUP="$PRIVATEDIR/group"
90 WINBINDD_SOCKET_DIR=$PREFIX_ABS/winbindd
91 WINBINDD_PRIV_PIPE_DIR=$LOCKDIR/winbindd_privileged
92 TEST_DIRECTORY=$DIRECTORY
93
94 export PREFIX PREFIX_ABS
95 export CONFIGURATION CONFFILE SAMBA4CONFIGURATION SAMBA4CONFFILE
96 export PATH SOCKET_WRAPPER_DIR DOMAIN
97 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE
98 export SRCDIR SCRIPTDIR BINDIR
99 export USERNAME PASSWORD
100 export WORKGROUP SERVER SERVER_IP
101 export NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
102 export WINBINDD_SOCKET_DIR WINBINDD_PRIV_PIPE_DIR
103 export TEST_DIRECTORY
104
105 PATH=bin:$PATH
106 export PATH
107
108 if [ $SMBTORTURE4 ]; then
109     SAMBA4BINDIR=`dirname $SMBTORTURE4`
110 fi
111
112 SAMBA4SHAREDDIR="$SAMBA4BINDIR/shared"
113
114 export SAMBA4SHAREDDIR
115 export SMBTORTURE4
116
117 if [ -z "$LIB_PATH_VAR" ] ; then
118         echo "Warning: LIB_PATH_VAR not set. Using best guess LD_LIBRARY_PATH." >&2
119         LIB_PATH_VAR=LD_LIBRARY_PATH
120         export LIB_PATH_VAR
121 fi
122
123 eval $LIB_PATH_VAR=$BINDIR:$SAMBA4SHAREDDIR:\$$LIB_PATH_VAR
124 export $LIB_PATH_VAR
125
126 ##
127 ## verify that we were built with --enable-socket-wrapper
128 ##
129
130 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
131         echo "***"
132         echo "*** You must include --enable-socket-wrapper when compiling Samba"
133         echo "*** in order to execute 'make test'.  Exiting...."
134         echo "***"
135         exit 1
136 fi
137
138 if test "x`smbd -b | grep NSS_WRAPPER`" = "x"; then
139         echo "***"
140         echo "*** You must include --enable-nss-wrapper when compiling Samba"
141         echo "*** in order to execute 'make test'.  Exiting...."
142         echo "***"
143         exit 1
144 fi
145
146
147 ## 
148 ## create the test directory layout
149 ##
150 printf "%s" "CREATE TEST ENVIRONMENT IN '$PREFIX'"...
151 /bin/rm -rf $PREFIX/*
152 mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR
153 mkdir -p $SOCKET_WRAPPER_DIR
154 mkdir -p $WINBINDD_SOCKET_DIR
155 chmod 755 $WINBINDD_SOCKET_DIR
156
157 ##
158 ## Create an alternate shrdir if one was specified.
159 ##
160 if [ $ALT_SHRDIR_ARG ]; then
161     ALT_SHRDIR=`echo $ALT_SHRDIR_ARG | sed s+//+/+`
162     mkdir -p $ALT_SHRDIR || exit $?
163     OLD_PWD=`pwd`
164     cd $ALT_SHRDIR || exit $?
165     SHRDIR=`pwd`
166     cd $OLD_PWD
167     /bin/rm -rf $SHRDIR/*
168 else
169     SHRDIR=$PREFIX_ABS/tmp
170     mkdir -p $SHRDIR
171 fi
172 chmod 777 $SHRDIR
173
174 ##
175 ## Create the common config include file with the basic settings
176 ##
177
178 cat >$COMMONCONFFILE<<EOF
179         workgroup = $WORKGROUP
180
181         private dir = $PRIVATEDIR
182         pid directory = $PIDDIR
183         lock directory = $LOCKDIR
184         log file = $LOGDIR/log.%m
185         log level = 0
186
187         name resolve order = bcast
188 EOF
189
190 TORTURE_INTERFACES='127.0.0.6/8,127.0.0.7/8,127.0.0.8/8,127.0.0.9/8,127.0.0.10/8,127.0.0.11/8'
191
192 cat >$CONFFILE<<EOF
193 [global]
194         netbios name = TORTURE_6
195         interfaces = $TORTURE_INTERFACES
196         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
197         include = $COMMONCONFFILE
198
199         passdb backend = tdbsam
200 EOF
201
202 cat >$SAMBA4CONFFILE<<EOF
203 [global]
204         netbios name = TORTURE_6
205         interfaces = $TORTURE_INTERFACES
206         panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
207         include = $COMMONCONFFILE
208         modules dir = $SRCDIR/bin/modules
209 EOF
210
211 cat >$SERVERCONFFILE<<EOF
212 [global]
213         netbios name = $SERVER
214         interfaces = $SERVER_IP/8
215         bind interfaces only = yes
216         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
217         include = $COMMONCONFFILE
218
219         state directory = $LOCKDIR
220         cache directory = $LOCKDIR
221
222         passdb backend = tdbsam
223
224         domain master = yes
225         domain logons = yes
226         lanman auth = yes
227         time server = yes
228
229         add user script =               $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
230         add group script =              $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type group  --action add --name %g
231         add user to group script =      $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type member --action add --name %g --member %u --passwd_path $NSS_WRAPPER_PASSWD
232         add machine script =            $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
233         delete user script =            $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
234         delete group script =           $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type group  --action delete --name %g
235         delete user from group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type member --action delete --name %g --member %u --passwd_path $NSS_WRAPPER_PASSWD
236
237         kernel oplocks = no
238         kernel change notify = no
239
240         syslog = no
241         printing = bsd
242         printcap name = /dev/null
243
244         winbindd:socket dir = $WINBINDD_SOCKET_DIR
245         idmap uid = 100000-200000
246         idmap gid = 100000-200000
247         winbind enum users = yes
248         winbind enum groups = yes
249
250 #       min receivefile size = 4000
251
252         read only = no
253         smbd:sharedelay = 100000
254 #       smbd:writetimeupdatedelay = 500000
255         map hidden = no
256         map system = no
257         map readonly = no
258         store dos attributes = yes
259         create mask = 755
260         store create time = yes
261         vfs objects = $BINDIR/xattr_tdb.so $BINDIR/streams_depot.so
262
263         #Include user defined custom parameters if set
264         $INCLUDE_CUSTOM_CONF
265
266 [tmp]
267         path = $SHRDIR
268 [hideunread]
269         copy = tmp
270         hide unreadable = yes
271 [tmpcase]
272         copy = tmp
273         case sensitive = yes
274 [hideunwrite]
275         copy = tmp
276         hide unwriteable files = yes
277 [print1]
278         copy = tmp
279         printable = yes
280         printing = vlp
281         print command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb print %p %s
282         lpq command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpq %p
283         lp rm command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lprm %p %j
284         lp pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lppause %p %j
285         lp resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpresume %p %j
286         queue pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queuepause %p
287         queue resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queueresume %p
288
289 [print2]
290         copy = print1
291 [print3]
292         copy = print1
293 [print4]
294         copy = print1
295 EOF
296
297 ##
298 ## create a test account
299 ##
300
301 cat >$NSS_WRAPPER_PASSWD<<EOF
302 root:x:65533:65532:root gecos:$PREFIX_ABS:/bin/false
303 nobody:x:65534:65533:nobody gecos:$PREFIX_ABS:/bin/false
304 $USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false
305 EOF
306
307 cat >$NSS_WRAPPER_GROUP<<EOF
308 nobody:x:65533:
309 nogroup:x:65534:nobody
310 root:x:65532:
311 $USERNAME-group:x:$GROUPID:
312 EOF
313
314 MAKE_TEST_BINARY="bin/smbpasswd"
315 export MAKE_TEST_BINARY
316
317 (echo $PASSWORD; echo $PASSWORD) | \
318         bin/smbpasswd -c $SERVERCONFFILE -L -s -a $USERNAME >/dev/null || exit 1
319
320 echo "DONE";
321
322 MAKE_TEST_BINARY=""
323
324 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
325 export SERVER_TEST_FIFO
326 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
327 export NMBD_TEST_LOG
328 WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log"
329 export WINBINDD_TEST_LOG
330 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
331 export SMBD_TEST_LOG
332
333 # start off with 0 failures
334 failed=0
335 export failed
336
337 . $SCRIPTDIR/test_functions.sh
338
339 SOCKET_WRAPPER_DEFAULT_IFACE=2
340 export SOCKET_WRAPPER_DEFAULT_IFACE
341 samba3_check_or_start
342
343
344 # ensure any one smbtorture call doesn't run too long
345 # and smbtorture will use 127.0.0.6 as source address by default
346 SOCKET_WRAPPER_DEFAULT_IFACE=6
347 export SOCKET_WRAPPER_DEFAULT_IFACE
348 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
349 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
350 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
351 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$SHRDIR"
352 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:winbindd_netbios_name=$SERVER"
353 export TORTURE4_OPTIONS
354
355 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
356         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
357 fi
358
359
360 ##
361 ## ready to go...now loop through the tests
362 ##
363
364 START=`date`
365 (
366  # give time for nbt server to register its names
367  echo "delaying for nbt name registration"
368  sleep 10
369  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
370  MAKE_TEST_BINARY="bin/nmblookup"
371  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
372  bin/nmblookup $CONFIGURATION __SAMBA__
373  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
374  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
375  bin/nmblookup $CONFIGURATION $SERVER
376  # make sure smbd is also up set
377  echo "wait for smbd"
378  MAKE_TEST_BINARY="bin/smbclient"
379  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
380  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
381  MAKE_TEST_BINARY=""
382
383  failed=0
384
385  . $SCRIPTDIR/tests_$SUBTESTS.sh
386  exit $failed
387 )
388 failed=$?
389
390 samba3_stop_sig_term
391
392 END=`date`
393 echo "START: $START ($0)";
394 echo "END:   $END ($0)";
395
396 # if there were any valgrind failures, show them
397 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
398 if [ "$count" != 0 ]; then
399     for f in $PREFIX/valgrind.log*; do
400         if [ -s $f ]; then
401             echo "VALGRIND FAILURE";
402             failed=`expr $failed + 1`
403             cat $f
404         fi
405     done
406 fi
407
408 sleep 2
409 samba3_stop_sig_kill
410
411 teststatus $0 $failed