5059ceab277afb10f1a41fe385da0f1ecd875d16
[mat/samba.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 layout
40 ##
41 PREFIX=`echo $DIRECTORY | sed s+//+/+`
42 printf "%s" "CREATE TEST ENVIRONMENT IN '$PREFIX'"...
43 /bin/rm -rf $PREFIX
44 if [ -e "$PREFIX" ]; then
45         echo "***"
46         echo "*** Failed to delete test environment $PREFIX"
47         echo "*** Was a previous run done as root ?"
48         echo "***"
49         exit 1
50 fi
51
52 ##
53 ## create the test directory
54 ##
55 mkdir -p $PREFIX || exit $?
56 OLD_PWD=`pwd`
57 cd $PREFIX || exit $?
58 PREFIX_ABS=`pwd`
59 cd $OLD_PWD
60
61 if [ -z "$TORTURE_MAXTIME" ]; then
62     TORTURE_MAXTIME=300
63 fi
64 export TORTURE_MAXTIME
65
66 ##
67 ## setup the various environment variables we need
68 ##
69
70 WORKGROUP=SAMBA-TEST
71 SERVER=localhost2
72 SERVER_IP=127.0.0.2
73 if [ ! "x$USER" = "x" ]; then
74     USERNAME=$USER
75 else
76     if [ ! "x$LOGNAME" = "x" ]; then
77         USERNAME=$LOGNAME
78     else
79         USERNAME=`PATH=/usr/ucb:$PATH whoami || id -un`
80     fi
81 fi
82 USERID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f1 | sed -e 's/uid=\([0-9]*\).*/\1/g'`
83 GROUPID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f2 | sed -e 's/gid=\([0-9]*\).*/\1/g'`
84 PASSWORD=testPw
85
86 SRCDIR="`dirname $0`/../.."
87 BINDIR="`pwd`/bin"
88 SCRIPTDIR=$SRCDIR/script/tests
89 LIBDIR=$PREFIX_ABS/lib
90 PIDDIR=$PREFIX_ABS/pid
91 CONFFILE=$LIBDIR/client.conf
92 SAMBA4CONFFILE=$LIBDIR/samba4client.conf
93 SERVERCONFFILE=$LIBDIR/server.conf
94 COMMONCONFFILE=$LIBDIR/common.conf
95 PRIVATEDIR=$PREFIX_ABS/private
96 NCALRPCDIR=$PREFIX_ABS/ncalrpc
97 LOCKDIR=$PREFIX_ABS/lockdir
98 EVENTLOGDIR=$LOCKDIR/eventlog
99 LOGDIR=$PREFIX_ABS/logs
100 SOCKET_WRAPPER_DIR=$PREFIX_ABS/sw
101 CONFIGURATION="--configfile $CONFFILE"
102 SAMBA4CONFIGURATION="-s $SAMBA4CONFFILE"
103 NSS_WRAPPER_PASSWD="$PRIVATEDIR/passwd"
104 NSS_WRAPPER_GROUP="$PRIVATEDIR/group"
105 WINBINDD_SOCKET_DIR=$PREFIX_ABS/winbindd
106 WINBINDD_PRIV_PIPE_DIR=$LOCKDIR/winbindd_privileged
107 TEST_DIRECTORY=$DIRECTORY
108
109 export PREFIX PREFIX_ABS
110 export CONFIGURATION CONFFILE SAMBA4CONFIGURATION SAMBA4CONFFILE
111 export PATH SOCKET_WRAPPER_DIR DOMAIN
112 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE
113 export SRCDIR SCRIPTDIR BINDIR
114 export USERNAME PASSWORD
115 export WORKGROUP SERVER SERVER_IP
116 export NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
117 export WINBINDD_SOCKET_DIR WINBINDD_PRIV_PIPE_DIR
118 export TEST_DIRECTORY
119
120 PATH=bin:$PATH
121 export PATH
122
123 if [ $SMBTORTURE4 ]; then
124     SAMBA4BINDIR=`dirname $SMBTORTURE4`
125 fi
126
127 SAMBA4SHAREDDIR="$SAMBA4BINDIR/shared"
128
129 export SAMBA4SHAREDDIR
130 export SMBTORTURE4
131
132 if [ -z "$LIB_PATH_VAR" ] ; then
133         echo "Warning: LIB_PATH_VAR not set. Using best guess LD_LIBRARY_PATH." >&2
134         LIB_PATH_VAR=LD_LIBRARY_PATH
135         export LIB_PATH_VAR
136 fi
137
138 eval $LIB_PATH_VAR=$BINDIR:$SAMBA4SHAREDDIR:\$$LIB_PATH_VAR
139 export $LIB_PATH_VAR
140
141 ##
142 ## verify that we were built with --enable-socket-wrapper
143 ##
144
145 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
146         echo "***"
147         echo "*** You must include --enable-socket-wrapper when compiling Samba"
148         echo "*** in order to execute 'make test'.  Exiting...."
149         echo "***"
150         exit 1
151 fi
152
153 if test "x`smbd -b | grep NSS_WRAPPER`" = "x"; then
154         echo "***"
155         echo "*** You must include --enable-nss-wrapper when compiling Samba"
156         echo "*** in order to execute 'make test'.  Exiting...."
157         echo "***"
158         exit 1
159 fi
160
161
162 mkdir -p $PRIVATEDIR $NCALRPCDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR $EVENTLOGDIR
163 mkdir -p $SOCKET_WRAPPER_DIR
164 mkdir -p $WINBINDD_SOCKET_DIR
165 chmod 755 $WINBINDD_SOCKET_DIR
166
167 ##
168 ## Create an alternate shrdir if one was specified.
169 ##
170 if [ $ALT_SHRDIR_ARG ]; then
171     ALT_SHRDIR=`echo $ALT_SHRDIR_ARG | sed s+//+/+`
172     mkdir -p $ALT_SHRDIR || exit $?
173     OLD_PWD=`pwd`
174     cd $ALT_SHRDIR || exit $?
175     SHRDIR=`pwd`
176     cd $OLD_PWD
177     /bin/rm -rf $SHRDIR/*
178 else
179     SHRDIR=$PREFIX_ABS/tmp
180     mkdir -p $SHRDIR
181 fi
182 chmod 777 $SHRDIR
183
184 LOCAL_PATH=$SHRDIR
185 export LOCAL_PATH
186
187 ##
188 ## Create driver share dirs
189 ##
190 mkdir $SHRDIR/W32X86
191 mkdir $SHRDIR/x64
192
193 ##
194 ## Create a read-only directory.
195 ##
196 RO_SHRDIR=`echo $SHRDIR | sed -e 's:/[^/]*$::'`
197 RO_SHRDIR=$RO_SHRDIR/root-tmp
198 mkdir -p $RO_SHRDIR
199 chmod 755 $RO_SHRDIR
200 touch $RO_SHRDIR/unreadable_file
201 chmod 600 $RO_SHRDIR/unreadable_file
202 ##
203 ## Create an MS-DFS root share.
204 ##
205 MSDFS_SHRDIR=`echo $SHRDIR | sed -e 's:/[^/]*$::'`
206 MSDFS_SHRDIR=$MSDFS_SHRDIR/msdfsshare
207 mkdir -p $MSDFS_SHRDIR
208 chmod 777 $MSDFS_SHRDIR
209 mkdir -p $MSDFS_SHRDIR/deeppath
210 chmod 777 $MSDFS_SHRDIR/deeppath
211 ## Create something visible in the target.
212 touch $RO_SHRDIR/msdfs-target
213 chmod 666 $RO_SHRDIR/msdfs-target
214 ln -s msdfs:$SERVER_IP\\ro-tmp $MSDFS_SHRDIR/msdfs-src1
215 ln -s msdfs:$SERVER_IP\\ro-tmp $MSDFS_SHRDIR/deeppath/msdfs-src2
216
217 ##
218 ## Create the common config include file with the basic settings
219 ##
220
221 cat >$COMMONCONFFILE<<EOF
222         workgroup = $WORKGROUP
223
224         private dir = $PRIVATEDIR
225         pid directory = $PIDDIR
226         lock directory = $LOCKDIR
227         log file = $LOGDIR/log.%m
228         log level = 0
229
230         name resolve order = bcast
231 EOF
232
233 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'
234
235 cat >$CONFFILE<<EOF
236 [global]
237         netbios name = TORTURE_6
238         interfaces = $TORTURE_INTERFACES
239         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
240         include = $COMMONCONFFILE
241
242         passdb backend = tdbsam
243 EOF
244
245 cat >$SAMBA4CONFFILE<<EOF
246 [global]
247         netbios name = TORTURE_6
248         interfaces = $TORTURE_INTERFACES
249         panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
250         include = $COMMONCONFFILE
251         modules dir = $SRCDIR/bin/modules
252         ncalrpc dir = $NCALRPCDIR
253 EOF
254
255 ##
256 ## calculate uids and gids
257 ##
258
259 if [ $USERID -lt $(( 0xffff - 2 )) ]; then
260         MAXUID=0xffff
261 else
262         MAXUID=$USERID
263 fi
264
265 UID_ROOT=$(( $MAXUID - 1 ))
266 UID_NOBODY=$(( MAXUID - 2 ))
267
268 if [ $GROUPID -lt $(( 0xffff - 3 )) ]; then
269         MAXGID=0xffff
270 else
271         MAXGID=$GROUPID
272 fi
273
274 GID_NOBODY=$(( $MAXGID - 3 ))
275 GID_NOGROUP=$(( $MAXGID - 2 ))
276 GID_ROOT=$(( $MAXGID - 1 ))
277
278 cat >$SERVERCONFFILE<<EOF
279 [global]
280         netbios name = $SERVER
281         interfaces = $SERVER_IP/8
282         bind interfaces only = yes
283         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
284         include = $COMMONCONFFILE
285
286         state directory = $LOCKDIR
287         cache directory = $LOCKDIR
288
289         passdb backend = tdbsam
290
291         domain master = yes
292         domain logons = yes
293         lanman auth = yes
294         time server = yes
295
296         add user script =               $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u --gid $GID_NOGROUP
297         add group script =              $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type group  --action add --name %g
298         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
299         add machine script =            $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u --gid $GID_NOGROUP
300         delete user script =            $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
301         delete group script =           $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type group  --action delete --name %g
302         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
303
304         addprinter command =            $PERL $SRCDIR/../source3/script/tests/printing/modprinter.pl -a -s $SERVERCONFFILE --
305         deleteprinter command =         $PERL $SRCDIR/../source3/script/tests/printing/modprinter.pl -d -s $SERVERCONFFILE --
306
307         eventlog list = "dns server" application
308         kernel oplocks = no
309         kernel change notify = no
310
311         syslog = no
312         printing = bsd
313         printcap name = /dev/null
314
315         winbindd:socket dir = $WINBINDD_SOCKET_DIR
316         idmap uid = 100000-200000
317         idmap gid = 100000-200000
318         winbind enum users = yes
319         winbind enum groups = yes
320
321 #       min receivefile size = 4000
322
323         read only = no
324         smbd:sharedelay = 100000
325 #       smbd:writetimeupdatedelay = 500000
326         map hidden = no
327         map system = no
328         map readonly = no
329         store dos attributes = yes
330         create mask = 755
331         vfs objects = $BINDIR/xattr_tdb.so $BINDIR/streams_depot.so
332
333         printing = vlp
334         print command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb print %p %s
335         lpq command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpq %p
336         lp rm command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lprm %p %j
337         lp pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lppause %p %j
338         lp resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpresume %p %j
339         queue pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queuepause %p
340         queue resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queueresume %p
341         lpq cache time = 0
342
343         #Include user defined custom parameters if set
344         $INCLUDE_CUSTOM_CONF
345
346 [tmp]
347         path = $SHRDIR
348 [ro-tmp]
349         path = $RO_SHRDIR
350         guest ok = yes
351 [msdfs-share]
352         path = $MSDFS_SHRDIR
353         msdfs root = yes
354         guest ok = yes
355 [hideunread]
356         copy = tmp
357         hide unreadable = yes
358 [tmpcase]
359         copy = tmp
360         case sensitive = yes
361 [hideunwrite]
362         copy = tmp
363         hide unwriteable files = yes
364 [print1]
365         copy = tmp
366         printable = yes
367
368 [print2]
369         copy = print1
370 [print3]
371         copy = print1
372 [lp]
373         copy = print1
374 [print$]
375         copy = tmp
376 EOF
377
378 ##
379 ## create a test account
380 ##
381
382 cat >$NSS_WRAPPER_PASSWD<<EOF
383 nobody:x:$UID_NOBODY:$GID_NOBODY:nobody gecos:$PREFIX_ABS:/bin/false
384 $USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false
385 EOF
386
387 cat >$NSS_WRAPPER_GROUP<<EOF
388 nobody:x:$GID_NOBODY:
389 nogroup:x:$GID_NOGROUP:nobody
390 $USERNAME-group:x:$GROUPID:
391 EOF
392
393 ##
394 ## add fake root user when not running as root
395 ##
396 if [ "$USERID" != 0 ]; then
397
398 cat >>$NSS_WRAPPER_PASSWD<<EOF
399 root:x:$UID_ROOT:$GID_ROOT:root gecos:$PREFIX_ABS:/bin/false
400 EOF
401
402 cat >>$NSS_WRAPPER_GROUP<<EOF
403 root:x:$GID_ROOT:
404 EOF
405
406 fi
407
408 touch $EVENTLOGDIR/dns\ server.tdb
409 touch $EVENTLOGDIR/application.tdb
410
411 MAKE_TEST_BINARY="bin/smbpasswd"
412 export MAKE_TEST_BINARY
413
414 (echo $PASSWORD; echo $PASSWORD) | \
415         bin/smbpasswd -c $SERVERCONFFILE -L -s -a $USERNAME >/dev/null || exit 1
416
417 echo "DONE";
418
419 MAKE_TEST_BINARY=""
420
421 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
422 export SERVER_TEST_FIFO
423 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
424 export NMBD_TEST_LOG
425 WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log"
426 export WINBINDD_TEST_LOG
427 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
428 export SMBD_TEST_LOG
429
430 # start off with 0 failures
431 failed=0
432 export failed
433
434 . $SCRIPTDIR/test_functions.sh
435
436 SOCKET_WRAPPER_DEFAULT_IFACE=2
437 export SOCKET_WRAPPER_DEFAULT_IFACE
438 samba3_check_or_start
439
440
441 # ensure any one smbtorture call doesn't run too long
442 # and smbtorture will use 127.0.0.6 as source address by default
443 SOCKET_WRAPPER_DEFAULT_IFACE=6
444 export SOCKET_WRAPPER_DEFAULT_IFACE
445 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
446 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
447 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
448 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$SHRDIR"
449 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:winbindd_netbios_name=$SERVER"
450 export TORTURE4_OPTIONS
451
452 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
453         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
454 fi
455
456
457 ##
458 ## ready to go...now loop through the tests
459 ##
460
461 START=`date`
462 (
463  # give time for nbt server to register its names
464  echo "delaying for nbt name registration"
465  sleep 10
466  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
467  MAKE_TEST_BINARY="bin/nmblookup"
468  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
469  bin/nmblookup $CONFIGURATION __SAMBA__
470  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
471  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
472  bin/nmblookup $CONFIGURATION $SERVER
473  # make sure smbd is also up set
474  echo "wait for smbd"
475  MAKE_TEST_BINARY="bin/smbclient"
476  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
477  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
478  MAKE_TEST_BINARY=""
479
480  failed=0
481
482  . $SCRIPTDIR/tests_$SUBTESTS.sh
483  exit $failed
484 )
485 failed=$?
486
487 samba3_stop_sig_term
488
489 END=`date`
490 echo "START: $START ($0)";
491 echo "END:   $END ($0)";
492
493 # if there were any valgrind failures, show them
494 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
495 if [ "$count" != 0 ]; then
496     for f in $PREFIX/valgrind.log*; do
497         if [ -s $f ]; then
498             echo "VALGRIND FAILURE";
499             failed=`expr $failed + 1`
500             cat $f
501         fi
502     done
503 fi
504
505 sleep 2
506 samba3_stop_sig_kill
507
508 teststatus $0 $failed