s4-drs: additional delete test cases
[Samba/eduardoll.git] / source3 / script / tests / selftest.sh
bloba13877ddc9227e32fe8fefa2a87ec5d41a539181
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
195 ## Create the common config include file with the basic settings
198 cat >$COMMONCONFFILE<<EOF
199 workgroup = $WORKGROUP
201 private dir = $PRIVATEDIR
202 pid directory = $PIDDIR
203 lock directory = $LOCKDIR
204 log file = $LOGDIR/log.%m
205 log level = 0
207 name resolve order = bcast
210 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'
212 cat >$CONFFILE<<EOF
213 [global]
214 netbios name = TORTURE_6
215 interfaces = $TORTURE_INTERFACES
216 panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
217 include = $COMMONCONFFILE
219 passdb backend = tdbsam
222 cat >$SAMBA4CONFFILE<<EOF
223 [global]
224 netbios name = TORTURE_6
225 interfaces = $TORTURE_INTERFACES
226 panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
227 include = $COMMONCONFFILE
228 modules dir = $SRCDIR/bin/modules
229 ncalrpc dir = $NCALRPCDIR
233 ## calculate uids and gids
236 if [ $USERID -lt $(( 0xffff - 2 )) ]; then
237 MAXUID=0xffff
238 else
239 MAXUID=$USERID
242 UID_ROOT=$(( $MAXUID - 1 ))
243 UID_NOBODY=$(( MAXUID - 2 ))
245 if [ $GROUPID -lt $(( 0xffff - 3 )) ]; then
246 MAXGID=0xffff
247 else
248 MAXGID=$GROUPID
251 GID_NOBODY=$(( $MAXGID - 3 ))
252 GID_NOGROUP=$(( $MAXGID - 2 ))
253 GID_ROOT=$(( $MAXGID - 1 ))
255 cat >$SERVERCONFFILE<<EOF
256 [global]
257 netbios name = $SERVER
258 interfaces = $SERVER_IP/8
259 bind interfaces only = yes
260 panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
261 include = $COMMONCONFFILE
263 state directory = $LOCKDIR
264 cache directory = $LOCKDIR
266 passdb backend = tdbsam
268 domain master = yes
269 domain logons = yes
270 lanman auth = yes
271 time server = yes
273 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
274 add group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path $NSS_WRAPPER_GROUP --type group --action add --name %g
275 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
276 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
277 delete user script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
278 delete group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path $NSS_WRAPPER_GROUP --type group --action delete --name %g
279 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
281 addprinter command = $PERL $SRCDIR/../source3/script/tests/printing/modprinter.pl -a -s $SERVERCONFFILE --
282 deleteprinter command = $PERL $SRCDIR/../source3/script/tests/printing/modprinter.pl -d -s $SERVERCONFFILE --
284 eventlog list = "dns server" application
285 kernel oplocks = no
286 kernel change notify = no
288 syslog = no
289 printing = bsd
290 printcap name = /dev/null
292 winbindd:socket dir = $WINBINDD_SOCKET_DIR
293 idmap uid = 100000-200000
294 idmap gid = 100000-200000
295 winbind enum users = yes
296 winbind enum groups = yes
298 # min receivefile size = 4000
300 read only = no
301 smbd:sharedelay = 100000
302 # smbd:writetimeupdatedelay = 500000
303 map hidden = no
304 map system = no
305 map readonly = no
306 store dos attributes = yes
307 create mask = 755
308 vfs objects = $BINDIR/xattr_tdb.so $BINDIR/streams_depot.so
310 printing = vlp
311 print command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb print %p %s
312 lpq command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpq %p
313 lp rm command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lprm %p %j
314 lp pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lppause %p %j
315 lp resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpresume %p %j
316 queue pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queuepause %p
317 queue resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queueresume %p
318 lpq cache time = 0
320 #Include user defined custom parameters if set
321 $INCLUDE_CUSTOM_CONF
323 [tmp]
324 path = $SHRDIR
325 [ro-tmp]
326 path = $RO_SHRDIR
327 guest ok = yes
328 [hideunread]
329 copy = tmp
330 hide unreadable = yes
331 [tmpcase]
332 copy = tmp
333 case sensitive = yes
334 [hideunwrite]
335 copy = tmp
336 hide unwriteable files = yes
337 [print1]
338 copy = tmp
339 printable = yes
341 [print2]
342 copy = print1
343 [print3]
344 copy = print1
345 [print4]
346 copy = print1
350 ## create a test account
353 cat >$NSS_WRAPPER_PASSWD<<EOF
354 nobody:x:$UID_NOBODY:$GID_NOBODY:nobody gecos:$PREFIX_ABS:/bin/false
355 $USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false
358 cat >$NSS_WRAPPER_GROUP<<EOF
359 nobody:x:$GID_NOBODY:
360 nogroup:x:$GID_NOGROUP:nobody
361 $USERNAME-group:x:$GROUPID:
365 ## add fake root user when not running as root
367 if [ "$USERID" != 0 ]; then
369 cat >>$NSS_WRAPPER_PASSWD<<EOF
370 root:x:$UID_ROOT:$GID_ROOT:root gecos:$PREFIX_ABS:/bin/false
373 cat >>$NSS_WRAPPER_GROUP<<EOF
374 root:x:$GID_ROOT:
379 touch $EVENTLOGDIR/dns\ server.tdb
380 touch $EVENTLOGDIR/application.tdb
382 MAKE_TEST_BINARY="bin/smbpasswd"
383 export MAKE_TEST_BINARY
385 (echo $PASSWORD; echo $PASSWORD) | \
386 bin/smbpasswd -c $SERVERCONFFILE -L -s -a $USERNAME >/dev/null || exit 1
388 echo "DONE";
390 MAKE_TEST_BINARY=""
392 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
393 export SERVER_TEST_FIFO
394 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
395 export NMBD_TEST_LOG
396 WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log"
397 export WINBINDD_TEST_LOG
398 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
399 export SMBD_TEST_LOG
401 # start off with 0 failures
402 failed=0
403 export failed
405 . $SCRIPTDIR/test_functions.sh
407 SOCKET_WRAPPER_DEFAULT_IFACE=2
408 export SOCKET_WRAPPER_DEFAULT_IFACE
409 samba3_check_or_start
412 # ensure any one smbtorture call doesn't run too long
413 # and smbtorture will use 127.0.0.6 as source address by default
414 SOCKET_WRAPPER_DEFAULT_IFACE=6
415 export SOCKET_WRAPPER_DEFAULT_IFACE
416 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
417 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
418 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
419 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$SHRDIR"
420 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:winbindd_netbios_name=$SERVER"
421 export TORTURE4_OPTIONS
423 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
424 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
429 ## ready to go...now loop through the tests
432 START=`date`
434 # give time for nbt server to register its names
435 echo "delaying for nbt name registration"
436 sleep 10
437 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
438 MAKE_TEST_BINARY="bin/nmblookup"
439 bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
440 bin/nmblookup $CONFIGURATION __SAMBA__
441 bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
442 bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
443 bin/nmblookup $CONFIGURATION $SERVER
444 # make sure smbd is also up set
445 echo "wait for smbd"
446 MAKE_TEST_BINARY="bin/smbclient"
447 bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
448 bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
449 MAKE_TEST_BINARY=""
451 failed=0
453 . $SCRIPTDIR/tests_$SUBTESTS.sh
454 exit $failed
456 failed=$?
458 samba3_stop_sig_term
460 END=`date`
461 echo "START: $START ($0)";
462 echo "END: $END ($0)";
464 # if there were any valgrind failures, show them
465 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
466 if [ "$count" != 0 ]; then
467 for f in $PREFIX/valgrind.log*; do
468 if [ -s $f ]; then
469 echo "VALGRIND FAILURE";
470 failed=`expr $failed + 1`
471 cat $f
473 done
476 sleep 2
477 samba3_stop_sig_kill
479 teststatus $0 $failed