Add basic DFS tests.
[Samba/gebeck_regimport.git] / source3 / script / tests / selftest.sh
blob2248ecf5b0b84d248043578837debaf7e4858d7f
1 #!/bin/sh
3 if [ $# -lt 2 ]; then
4 echo "$0 <directory> <all | quick> [-t <smbtorture4>] [-s <shrdir>] " \
5 "[-c <custom conf>]"
6 exit 1
7 fi
9 ##
10 ## Setup the required args
12 DIRECTORY=$1; shift;
13 SUBTESTS=$1; shift;
16 ## Parse oprtional args
18 while getopts s:c:t: f
20 case $f in
21 t) SMBTORTURE4=$OPTARG;;
22 s) ALT_SHRDIR_ARG=$OPTARG;;
23 c) CUSTOM_CONF_ARG=$OPTARG;;
24 esac
25 done
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"
34 if [ $CUSTOM_CONF_ARG ]; then
35 INCLUDE_CUSTOM_CONF="include = $CUSTOM_CONF_ARG"
39 ## create the test directory layout
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
53 ## create the test directory
55 mkdir -p $PREFIX || exit $?
56 OLD_PWD=`pwd`
57 cd $PREFIX || exit $?
58 PREFIX_ABS=`pwd`
59 cd $OLD_PWD
61 if [ -z "$TORTURE_MAXTIME" ]; then
62 TORTURE_MAXTIME=300
64 export TORTURE_MAXTIME
67 ## setup the various environment variables we need
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`
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=test
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
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
120 PATH=bin:$PATH
121 export PATH
123 if [ $SMBTORTURE4 ]; then
124 SAMBA4BINDIR=`dirname $SMBTORTURE4`
127 SAMBA4SHAREDDIR="$SAMBA4BINDIR/shared"
129 export SAMBA4SHAREDDIR
130 export SMBTORTURE4
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
138 eval $LIB_PATH_VAR=$BINDIR:$SAMBA4SHAREDDIR:\$$LIB_PATH_VAR
139 export $LIB_PATH_VAR
142 ## verify that we were built with --enable-socket-wrapper
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
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
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
168 ## Create an alternate shrdir if one was specified.
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
182 chmod 777 $SHRDIR
185 ## Create a read-only directory.
187 RO_SHRDIR=`echo $SHRDIR | sed -e 's:/[^/]*$::'`
188 RO_SHRDIR=$RO_SHRDIR/root-tmp
189 mkdir -p $RO_SHRDIR
190 chmod 755 $RO_SHRDIR
191 touch $RO_SHRDIR/unreadable_file
192 chmod 600 $RO_SHRDIR/unreadable_file
194 ## Create an MS-DFS root share.
196 MSDFS_SHRDIR=`echo $SHRDIR | sed -e 's:/[^/]*$::'`
197 MSDFS_SHRDIR=$MSDFS_SHRDIR/msdfsshare
198 mkdir -p $MSDFS_SHRDIR
199 chmod 777 $MSDFS_SHRDIR
200 mkdir -p $MSDFS_SHRDIR/deeppath
201 chmod 777 $MSDFS_SHRDIR/deeppath
202 ## Create something visible in the target.
203 touch $RO_SHRDIR/msdfs-target
204 chmod 666 $RO_SHRDIR/msdfs-target
205 ln -s msdfs:$SERVER_IP\\ro-tmp $MSDFS_SHRDIR/msdfs-src1
206 ln -s msdfs:$SERVER_IP\\ro-tmp $MSDFS_SHRDIR/deeppath/msdfs-src2
209 ## Create the common config include file with the basic settings
212 cat >$COMMONCONFFILE<<EOF
213 workgroup = $WORKGROUP
215 private dir = $PRIVATEDIR
216 pid directory = $PIDDIR
217 lock directory = $LOCKDIR
218 log file = $LOGDIR/log.%m
219 log level = 0
221 name resolve order = bcast
224 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'
226 cat >$CONFFILE<<EOF
227 [global]
228 netbios name = TORTURE_6
229 interfaces = $TORTURE_INTERFACES
230 panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
231 include = $COMMONCONFFILE
233 passdb backend = tdbsam
236 cat >$SAMBA4CONFFILE<<EOF
237 [global]
238 netbios name = TORTURE_6
239 interfaces = $TORTURE_INTERFACES
240 panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
241 include = $COMMONCONFFILE
242 modules dir = $SRCDIR/bin/modules
243 ncalrpc dir = $NCALRPCDIR
247 ## calculate uids and gids
250 if [ $USERID -lt $(( 0xffff - 2 )) ]; then
251 MAXUID=0xffff
252 else
253 MAXUID=$USERID
256 UID_ROOT=$(( $MAXUID - 1 ))
257 UID_NOBODY=$(( MAXUID - 2 ))
259 if [ $GROUPID -lt $(( 0xffff - 3 )) ]; then
260 MAXGID=0xffff
261 else
262 MAXGID=$GROUPID
265 GID_NOBODY=$(( $MAXGID - 3 ))
266 GID_NOGROUP=$(( $MAXGID - 2 ))
267 GID_ROOT=$(( $MAXGID - 1 ))
269 cat >$SERVERCONFFILE<<EOF
270 [global]
271 netbios name = $SERVER
272 interfaces = $SERVER_IP/8
273 bind interfaces only = yes
274 panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
275 include = $COMMONCONFFILE
277 state directory = $LOCKDIR
278 cache directory = $LOCKDIR
280 passdb backend = tdbsam
282 domain master = yes
283 domain logons = yes
284 lanman auth = yes
285 time server = yes
287 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
288 add group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path $NSS_WRAPPER_GROUP --type group --action add --name %g
289 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
290 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
291 delete user script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
292 delete group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path $NSS_WRAPPER_GROUP --type group --action delete --name %g
293 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
295 addprinter command = $PERL $SRCDIR/../source3/script/tests/printing/modprinter.pl -a -s $SERVERCONFFILE --
296 deleteprinter command = $PERL $SRCDIR/../source3/script/tests/printing/modprinter.pl -d -s $SERVERCONFFILE --
298 eventlog list = "dns server" application
299 kernel oplocks = no
300 kernel change notify = no
302 syslog = no
303 printing = bsd
304 printcap name = /dev/null
306 winbindd:socket dir = $WINBINDD_SOCKET_DIR
307 idmap uid = 100000-200000
308 idmap gid = 100000-200000
309 winbind enum users = yes
310 winbind enum groups = yes
312 # min receivefile size = 4000
314 read only = no
315 smbd:sharedelay = 100000
316 # smbd:writetimeupdatedelay = 500000
317 map hidden = no
318 map system = no
319 map readonly = no
320 store dos attributes = yes
321 create mask = 755
322 vfs objects = $BINDIR/xattr_tdb.so $BINDIR/streams_depot.so
324 printing = vlp
325 print command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb print %p %s
326 lpq command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpq %p
327 lp rm command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lprm %p %j
328 lp pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lppause %p %j
329 lp resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpresume %p %j
330 queue pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queuepause %p
331 queue resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queueresume %p
332 lpq cache time = 0
334 #Include user defined custom parameters if set
335 $INCLUDE_CUSTOM_CONF
337 [tmp]
338 path = $SHRDIR
339 [ro-tmp]
340 path = $RO_SHRDIR
341 guest ok = yes
342 [msdfs-share]
343 path = $MSDFS_SHRDIR
344 msdfs root = yes
345 guest ok = yes
346 [hideunread]
347 copy = tmp
348 hide unreadable = yes
349 [tmpcase]
350 copy = tmp
351 case sensitive = yes
352 [hideunwrite]
353 copy = tmp
354 hide unwriteable files = yes
355 [print1]
356 copy = tmp
357 printable = yes
359 [print2]
360 copy = print1
361 [print3]
362 copy = print1
363 [print4]
364 copy = print1
368 ## create a test account
371 cat >$NSS_WRAPPER_PASSWD<<EOF
372 nobody:x:$UID_NOBODY:$GID_NOBODY:nobody gecos:$PREFIX_ABS:/bin/false
373 $USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false
376 cat >$NSS_WRAPPER_GROUP<<EOF
377 nobody:x:$GID_NOBODY:
378 nogroup:x:$GID_NOGROUP:nobody
379 $USERNAME-group:x:$GROUPID:
383 ## add fake root user when not running as root
385 if [ "$USERID" != 0 ]; then
387 cat >>$NSS_WRAPPER_PASSWD<<EOF
388 root:x:$UID_ROOT:$GID_ROOT:root gecos:$PREFIX_ABS:/bin/false
391 cat >>$NSS_WRAPPER_GROUP<<EOF
392 root:x:$GID_ROOT:
397 touch $EVENTLOGDIR/dns\ server.tdb
398 touch $EVENTLOGDIR/application.tdb
400 MAKE_TEST_BINARY="bin/smbpasswd"
401 export MAKE_TEST_BINARY
403 (echo $PASSWORD; echo $PASSWORD) | \
404 bin/smbpasswd -c $SERVERCONFFILE -L -s -a $USERNAME >/dev/null || exit 1
406 echo "DONE";
408 MAKE_TEST_BINARY=""
410 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
411 export SERVER_TEST_FIFO
412 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
413 export NMBD_TEST_LOG
414 WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log"
415 export WINBINDD_TEST_LOG
416 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
417 export SMBD_TEST_LOG
419 # start off with 0 failures
420 failed=0
421 export failed
423 . $SCRIPTDIR/test_functions.sh
425 SOCKET_WRAPPER_DEFAULT_IFACE=2
426 export SOCKET_WRAPPER_DEFAULT_IFACE
427 samba3_check_or_start
430 # ensure any one smbtorture call doesn't run too long
431 # and smbtorture will use 127.0.0.6 as source address by default
432 SOCKET_WRAPPER_DEFAULT_IFACE=6
433 export SOCKET_WRAPPER_DEFAULT_IFACE
434 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
435 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
436 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
437 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$SHRDIR"
438 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:winbindd_netbios_name=$SERVER"
439 export TORTURE4_OPTIONS
441 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
442 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
447 ## ready to go...now loop through the tests
450 START=`date`
452 # give time for nbt server to register its names
453 echo "delaying for nbt name registration"
454 sleep 10
455 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
456 MAKE_TEST_BINARY="bin/nmblookup"
457 bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
458 bin/nmblookup $CONFIGURATION __SAMBA__
459 bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
460 bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
461 bin/nmblookup $CONFIGURATION $SERVER
462 # make sure smbd is also up set
463 echo "wait for smbd"
464 MAKE_TEST_BINARY="bin/smbclient"
465 bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
466 bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
467 MAKE_TEST_BINARY=""
469 failed=0
471 . $SCRIPTDIR/tests_$SUBTESTS.sh
472 exit $failed
474 failed=$?
476 samba3_stop_sig_term
478 END=`date`
479 echo "START: $START ($0)";
480 echo "END: $END ($0)";
482 # if there were any valgrind failures, show them
483 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
484 if [ "$count" != 0 ]; then
485 for f in $PREFIX/valgrind.log*; do
486 if [ -s $f ]; then
487 echo "VALGRIND FAILURE";
488 failed=`expr $failed + 1`
489 cat $f
491 done
494 sleep 2
495 samba3_stop_sig_kill
497 teststatus $0 $failed