diff options
Diffstat (limited to 'source3/script/tests')
-rwxr-xr-x | source3/script/tests/dlopen.sh | 90 | ||||
-rwxr-xr-x | source3/script/tests/gdb_backtrace | 87 | ||||
-rwxr-xr-x | source3/script/tests/selftest.sh | 324 | ||||
-rw-r--r-- | source3/script/tests/test_functions.sh | 333 | ||||
-rwxr-xr-x | source3/script/tests/test_groupmap.sh | 214 | ||||
-rwxr-xr-x | source3/script/tests/test_local_s3.sh | 29 | ||||
-rwxr-xr-x | source3/script/tests/test_net_misc.sh | 50 | ||||
-rwxr-xr-x | source3/script/tests/test_net_registry.sh | 442 | ||||
-rwxr-xr-x | source3/script/tests/test_net_s3.sh | 33 | ||||
-rwxr-xr-x | source3/script/tests/test_ntlm_auth_s3.sh | 21 | ||||
-rwxr-xr-x | source3/script/tests/test_posix_s3.sh | 84 | ||||
-rwxr-xr-x | source3/script/tests/test_smbclient_s3.sh | 87 | ||||
-rwxr-xr-x | source3/script/tests/test_smbtorture_s3.sh | 48 | ||||
-rwxr-xr-x | source3/script/tests/test_testparm_s3.sh | 90 | ||||
-rwxr-xr-x | source3/script/tests/test_wbinfo_s3.sh | 50 | ||||
-rwxr-xr-x | source3/script/tests/tests_all.sh | 94 | ||||
-rw-r--r-- | source3/script/tests/tests_smbclient_s3.sh | 1 | ||||
-rw-r--r-- | source3/script/tests/timelimit.c | 102 |
18 files changed, 2179 insertions, 0 deletions
diff --git a/source3/script/tests/dlopen.sh b/source3/script/tests/dlopen.sh new file mode 100755 index 0000000000..edf44719d3 --- /dev/null +++ b/source3/script/tests/dlopen.sh @@ -0,0 +1,90 @@ +#!/bin/sh +# +# Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2003 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see <http://www.gnu.org/licenses/>. + +tempdir=`mktemp -d /tmp/dlopenXXXXXX` +test -n "$tempdir" || exit 1 +cat >> $tempdir/dlopen.c << _EOF +#include <dlfcn.h> +#include <stdio.h> +#include <limits.h> +#include <sys/stat.h> +/* Simple program to see if dlopen() would succeed. */ +int main(int argc, char **argv) +{ + int i; + struct stat st; + char buf[PATH_MAX]; + for (i = 1; i < argc; i++) { + if (dlopen(argv[i], RTLD_NOW)) { + fprintf(stdout, "dlopen() of \"%s\" succeeded.\n", + argv[i]); + } else { + snprintf(buf, sizeof(buf), "./%s", argv[i]); + if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) { + fprintf(stdout, "dlopen() of \"./%s\" " + "succeeded.\n", argv[i]); + } else { + fprintf(stdout, "dlopen() of \"%s\" failed: " + "%s\n", argv[i], dlerror()); + return 1; + } + } + } + return 0; +} +_EOF + +for arg in $@ ; do + case "$arg" in + "") + ;; + -I*|-D*|-f*|-m*|-g*|-O*|-W*) + cflags="$cflags $arg" + ;; + -l*|-L*) + ldflags="$ldflags $arg" + ;; + /*) + modules="$modules $arg" + ;; + *) + modules="$modules $arg" + ;; + esac +done + +${CC:-gcc} $RPM_OPT_FLAGS $CFLAGS -o $tempdir/dlopen $cflags $tempdir/dlopen.c $ldflags -ldl + +retval=0 +for module in $modules ; do + case "$module" in + "") + ;; + /*) + $tempdir/dlopen "$module" + retval=$? + ;; + *) + $tempdir/dlopen ./"$module" + retval=$? + ;; + esac +done + +rm -f $tempdir/dlopen $tempdir/dlopen.c +rmdir $tempdir +exit $retval diff --git a/source3/script/tests/gdb_backtrace b/source3/script/tests/gdb_backtrace new file mode 100755 index 0000000000..826381e900 --- /dev/null +++ b/source3/script/tests/gdb_backtrace @@ -0,0 +1,87 @@ +#!/bin/sh + +BASENAME=`basename $0` + +if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then + echo "${BASENAME}: Not running debugger under valgrind" + exit 1 +fi + +# we want everything on stderr, so the program is not disturbed +exec 1>&2 + +BASENAME=`basename $0` +UNAME=`uname` + +PID=$1 +BINARY=$2 + +test x"${PID}" = x"" && { + echo "Usage: ${BASENAME} <pid> [<binary>]" + exit 1 +} + +DB_LIST="gdb" +case "${UNAME}" in + # + # on Tru64 we need to try ladebug first + # because gdb crashes itself... + # + OSF1) + DB_LIST="ladebug ${DB_LIST}" + ;; +esac + +for DB in ${DB_LIST}; do + DB_BIN=`which ${DB} 2>/dev/null | grep '^/'` + test x"${DB_BIN}" != x"" && { + break + } +done + +test x"${DB_BIN}" = x"" && { + echo "${BASENAME}: ERROR: No debugger found." + exit 1 +} + +# +# we first try to use /proc/${PID}/exe +# then fallback to the binary from the commandline +# then we search for the commandline argument with +# 'which' +# +test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe" +test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe" +test -f "${BINARY}" || BINARY=`which ${BINARY}` + +test -f "${BINARY}" || { + echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'." + exit 1 +} + +echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}" + +BATCHFILE_PRE=/tmp/gdb_backtrace_pre.$$ +BATCHFILE_MAIN=/tmp/gdb_backtrace_main.$$ +case "${DB}" in + ladebug) +cat << EOF > ${BATCHFILE_PRE} +set \$stoponattach +EOF + +cat << EOF > ${BATCHFILE_MAIN} +where +quit +EOF + ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}" + ;; + gdb) +cat << EOF > ${BATCHFILE_MAIN} +set height 1000 +bt full +quit +EOF + ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}" + ;; +esac +/bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN} diff --git a/source3/script/tests/selftest.sh b/source3/script/tests/selftest.sh new file mode 100755 index 0000000000..15e48b00ef --- /dev/null +++ b/source3/script/tests/selftest.sh @@ -0,0 +1,324 @@ +#!/bin/sh + +if [ $# != 3 ]; then + echo "$0 <directory> <all | quick> <smbtorture4>" + exit 1 +fi + +SMBTORTURE4=$3 +SUBTESTS=$2 + +## +## create the test directory +## +PREFIX=`echo $1 | sed s+//+/+` +mkdir -p $PREFIX || exit $? +OLD_PWD=`pwd` +cd $PREFIX || exit $? +PREFIX_ABS=`pwd` +cd $OLD_PWD + +if [ -z "$TORTURE_MAXTIME" ]; then + TORTURE_MAXTIME=300 +fi +export TORTURE_MAXTIME + +## +## setup the various environment variables we need +## + +WORKGROUP=SAMBA-TEST +SERVER=localhost2 +SERVER_IP=127.0.0.2 +USERNAME=`PATH=/usr/ucb:$PATH whoami` +USERID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f1 | sed -e 's/uid=\([0-9]*\).*/\1/g'` +GROUPID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f2 | sed -e 's/gid=\([0-9]*\).*/\1/g'` +PASSWORD=test + +SRCDIR="`dirname $0`/../.." +BINDIR="`pwd`/bin" +SCRIPTDIR=$SRCDIR/script/tests +SHRDIR=$PREFIX_ABS/tmp +LIBDIR=$PREFIX_ABS/lib +PIDDIR=$PREFIX_ABS/pid +CONFFILE=$LIBDIR/client.conf +SAMBA4CONFFILE=$LIBDIR/samba4client.conf +SERVERCONFFILE=$LIBDIR/server.conf +COMMONCONFFILE=$LIBDIR/common.conf +PRIVATEDIR=$PREFIX_ABS/private +LOCKDIR=$PREFIX_ABS/lockdir +LOGDIR=$PREFIX_ABS/logs +SOCKET_WRAPPER_DIR=$PREFIX/sw +CONFIGURATION="--configfile $CONFFILE" +SAMBA4CONFIGURATION="-s $SAMBA4CONFFILE" +NSS_WRAPPER_PASSWD="$PRIVATEDIR/passwd" +NSS_WRAPPER_GROUP="$PRIVATEDIR/group" +WINBINDD_SOCKET_DIR=$PREFIX_ABS/winbindd +WINBINDD_PRIV_PIPE_DIR=$LOCKDIR/winbindd_privileged + +export PREFIX PREFIX_ABS +export CONFIGURATION CONFFILE SAMBA4CONFIGURATION SAMBA4CONFFILE +export PATH SOCKET_WRAPPER_DIR DOMAIN +export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE +export SRCDIR SCRIPTDIR BINDIR +export USERNAME PASSWORD +export WORKGROUP SERVER SERVER_IP +export NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP +export WINBINDD_SOCKET_DIR WINBINDD_PRIV_PIPE_DIR + +PATH=bin:$PATH +export PATH + +if test x"$LD_LIBRARY_PATH" != x""; then + LD_LIBRARY_PATH="$BINDIR:$LD_LIBRARY_PATH" +else + LD_LIBRARY_PATH="$BINDIR" +fi +echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" +export LD_LIBRARY_PATH + +SAMBA4BINDIR=`dirname $SMBTORTURE4` +SAMBA4SHAREDDIR="$SAMBA4BINDIR/shared" + +export SAMBA4SHAREDDIR +export SMBTORTURE4 + +## +## verify that we were built with --enable-socket-wrapper +## + +if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then + echo "***" + echo "*** You must include --enable-socket-wrapper when compiling Samba" + echo "*** in order to execute 'make test'. Exiting...." + echo "***" + exit 1 +fi + +if test "x`smbd -b | grep NSS_WRAPPER`" = "x"; then + echo "***" + echo "*** You must include --enable-nss-wrapper when compiling Samba" + echo "*** in order to execute 'make test'. Exiting...." + echo "***" + exit 1 +fi + + +## +## create the test directory layout +## +printf "%s" "CREATE TEST ENVIRONMENT IN '$PREFIX'"... +/bin/rm -rf $PREFIX/* +mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR +mkdir -p $SOCKET_WRAPPER_DIR +mkdir -p $WINBINDD_SOCKET_DIR +chmod 755 $WINBINDD_SOCKET_DIR +mkdir -p $PREFIX_ABS/tmp +chmod 777 $PREFIX_ABS/tmp + +## +## Create the common config include file with the basic settings +## + +cat >$COMMONCONFFILE<<EOF + workgroup = $WORKGROUP + + private dir = $PRIVATEDIR + pid directory = $PIDDIR + lock directory = $LOCKDIR + log file = $LOGDIR/log.%m + log level = 0 + + name resolve order = bcast +EOF + +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' + +cat >$CONFFILE<<EOF +[global] + netbios name = TORTURE_6 + interfaces = $TORTURE_INTERFACES + panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY) + include = $COMMONCONFFILE + + passdb backend = tdbsam +EOF + +cat >$SAMBA4CONFFILE<<EOF +[global] + netbios name = TORTURE_6 + interfaces = $TORTURE_INTERFACES + panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG% + include = $COMMONCONFFILE +EOF + +cat >$SERVERCONFFILE<<EOF +[global] + netbios name = $SERVER + interfaces = $SERVER_IP/8 + bind interfaces only = yes + panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY) + include = $COMMONCONFFILE + + passdb backend = tdbsam + + domain master = yes + domain logons = yes + time server = yes + + add user script = $PERL $SRCDIR/lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u + add machine script = $PERL $SRCDIR/lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u + delete user script = $PERL $SRCDIR/lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u + + kernel oplocks = no + kernel change notify = no + + syslog = no + printing = bsd + printcap name = /dev/null + + winbindd:socket dir = $WINBINDD_SOCKET_DIR + idmap uid = 100000-200000 + idmap gid = 100000-200000 + +# min receivefile size = 4000 + +[tmp] + path = $PREFIX_ABS/tmp + read only = no + smbd:sharedelay = 100000 + smbd:writetimeupdatedelay = 500000 + map hidden = yes + map system = yes + create mask = 755 + vfs objects = $BINDIR/xattr_tdb.so $BINDIR/streams_xattr.so +[hideunread] + copy = tmp + hide unreadable = yes +[hideunwrite] + copy = tmp + hide unwriteable files = yes +[print1] + copy = tmp + printable = yes + printing = test +[print2] + copy = print1 +[print3] + copy = print1 +[print4] + copy = print1 +EOF + +## +## create a test account +## + +cat >$NSS_WRAPPER_PASSWD<<EOF +nobody:x:65534:65533:nobody gecos:$PREFIX_ABS:/bin/false +$USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false +EOF + +cat >$NSS_WRAPPER_GROUP<<EOF +nobody:x:65533: +nogroup:x:65534:nobody +$USERNAME-group:x:$GROUPID: +EOF + +MAKE_TEST_BINARY="bin/smbpasswd" +export MAKE_TEST_BINARY + +(echo $PASSWORD; echo $PASSWORD) | \ + bin/smbpasswd -c $CONFFILE -L -s -a $USERNAME >/dev/null || exit 1 + +echo "DONE"; + +MAKE_TEST_BINARY="" + +SERVER_TEST_FIFO="$PREFIX/server_test.fifo" +export SERVER_TEST_FIFO +NMBD_TEST_LOG="$PREFIX/nmbd_test.log" +export NMBD_TEST_LOG +WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log" +export WINBINDD_TEST_LOG +SMBD_TEST_LOG="$PREFIX/smbd_test.log" +export SMBD_TEST_LOG + +# start off with 0 failures +failed=0 +export failed + +. $SCRIPTDIR/test_functions.sh + +SOCKET_WRAPPER_DEFAULT_IFACE=2 +export SOCKET_WRAPPER_DEFAULT_IFACE +samba3_check_or_start + + +# ensure any one smbtorture call doesn't run too long +# and smbtorture will use 127.0.0.6 as source address by default +SOCKET_WRAPPER_DEFAULT_IFACE=6 +export SOCKET_WRAPPER_DEFAULT_IFACE +TORTURE4_OPTIONS="$SAMBA4CONFIGURATION" +TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME" +TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3" +TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$PREFIX_ABS/tmp" +export TORTURE4_OPTIONS + +if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then + TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no" +fi + + +## +## ready to go...now loop through the tests +## + +START=`date` +( + # give time for nbt server to register its names + echo "delaying for nbt name registration" + sleep 10 + # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init + MAKE_TEST_BINARY="bin/nmblookup" + bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__ + bin/nmblookup $CONFIGURATION __SAMBA__ + bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__ + bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER + bin/nmblookup $CONFIGURATION $SERVER + # make sure smbd is also up set + echo "wait for smbd" + MAKE_TEST_BINARY="bin/smbclient" + bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2 + bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2 + MAKE_TEST_BINARY="" + + failed=0 + + . $SCRIPTDIR/tests_$SUBTESTS.sh + exit $failed +) +failed=$? + +samba3_stop_sig_term + +END=`date` +echo "START: $START ($0)"; +echo "END: $END ($0)"; + +# if there were any valgrind failures, show them +count=`find $PREFIX -name 'valgrind.log*' | wc -l` +if [ "$count" != 0 ]; then + for f in $PREFIX/valgrind.log*; do + if [ -s $f ]; then + echo "VALGRIND FAILURE"; + failed=`expr $failed + 1` + cat $f + fi + done +fi + +sleep 2 +samba3_stop_sig_kill + +teststatus $0 $failed diff --git a/source3/script/tests/test_functions.sh b/source3/script/tests/test_functions.sh new file mode 100644 index 0000000000..407d46aa9e --- /dev/null +++ b/source3/script/tests/test_functions.sh @@ -0,0 +1,333 @@ + +samba3_stop_sig_term() { + RET=0 + kill -USR1 `cat $PIDDIR/timelimit.nmbd.pid` >/dev/null 2>&1 || \ + kill -ALRM `cat $PIDDIR/timelimit.nmbd.pid` || RET=$? + + kill -USR1 `cat $PIDDIR/timelimit.winbindd.pid` >/dev/null 2>&1 || \ + kill -ALRM `cat $PIDDIR/timelimit.winbindd.pid` || RET=$? + + kill -USR1 `cat $PIDDIR/timelimit.smbd.pid` >/dev/null 2>&1 || \ + kill -ALRM `cat $PIDDIR/timelimit.smbd.pid` || RET=$? + + return $RET; +} + +samba3_stop_sig_kill() { + kill -ALRM `cat $PIDDIR/timelimit.nmbd.pid` >/dev/null 2>&1 + kill -ALRM `cat $PIDDIR/timelimit.winbindd.pid` >/dev/null 2>&1 + kill -ALRM `cat $PIDDIR/timelimit.smbd.pid` >/dev/null 2>&1 + return 0; +} + +samba3_check_or_start() { + if [ -n "$SERVER_TEST_FIFO" ];then + + trap samba3_stop_sig_kill INT QUIT + trap samba3_stop_sig_kill TERM + + if [ -p "$SERVER_TEST_FIFO" ];then + return 0; + fi + + if [ -n "$SOCKET_WRAPPER_DIR" ];then + if [ -d "$SOCKET_WRAPPER_DIR" ]; then + rm -f $SOCKET_WRAPPER_DIR/* + else + mkdir -p $SOCKET_WRAPPER_DIR + fi + fi + + rm -f $SERVER_TEST_FIFO + mkfifo $SERVER_TEST_FIFO + + rm -f $NMBD_TEST_LOG + printf "%s" "STARTING NMBD..." + (( + if test x"$NMBD_MAXTIME" = x; then + NMBD_MAXTIME=2700 + fi + MAKE_TEST_BINARY=$BINDIR/nmbd + export MAKE_TEST_BINARY + timelimit $NMBD_MAXTIME $NMBD_VALGRIND $BINDIR/nmbd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $NMBD_TEST_LOG 2>&1 & + TIMELIMIT_NMBD_PID=$! + MAKE_TEST_BINARY= + echo $TIMELIMIT_NMBD_PID > $PIDDIR/timelimit.nmbd.pid + wait $TIMELIMIT_NMBD_PID + ret=$?; + rm -f $SERVER_TEST_FIFO + if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then + rm -f $SOCKET_WRAPPER_DIR/* + fi + if [ x"$ret" = x"0" ];then + echo "nmbd exits with status $ret"; + echo "nmbd exits with status $ret" >>$NMBD_TEST_LOG; + elif [ x"$ret" = x"137" ];then + echo "nmbd got SIGXCPU and exits with status $ret!" + echo "nmbd got SIGXCPU and exits with status $ret!">>$NMBD_TEST_LOG; + else + echo "nmbd failed with status $ret!" + echo "nmbd failed with status $ret!">>$NMBD_TEST_LOG; + fi + exit $ret; + ) || exit $? &) 2>/dev/null || exit $? + echo "DONE" + + rm -f $WINBINDD_TEST_LOG + printf "%s" "STARTING WINBINDD..." + (( + if test x"$WINBINDD_MAXTIME" = x; then + WINBINDD_MAXTIME=2700 + fi + MAKE_TEST_BINARY=$BINDIR/winbindd + export MAKE_TEST_BINARY + timelimit $WINBINDD_MAXTIME $WINBINDD_VALGRIND $BINDIR/winbindd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $WINBINDD_TEST_LOG 2>&1 & + TIMELIMIT_WINBINDD_PID=$! + MAKE_TEST_BINARY= + echo $TIMELIMIT_WINBINDD_PID > $PIDDIR/timelimit.winbindd.pid + wait $TIMELIMIT_WINBINDD_PID + ret=$?; + rm -f $SERVER_TEST_FIFO + if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then + rm -f $SOCKET_WRAPPER_DIR/* + fi + if [ x"$ret" = x"0" ];then + echo "winbindd exits with status $ret"; + echo "winbindd exits with status $ret" >>$WINBINDD_TEST_LOG; + elif [ x"$ret" = x"137" ];then + echo "winbindd got SIGXCPU and exits with status $ret!" + echo "winbindd got SIGXCPU and exits with status $ret!">>$WINBINDD_TEST_LOG; + else + echo "winbindd failed with status $ret!" + echo "winbindd failed with status $ret!">>$WINBINDD_TEST_LOG; + fi + exit $ret; + ) || exit $? &) 2>/dev/null || exit $? + echo "DONE" + + rm -f $SMBD_TEST_LOG + printf "%s" "STARTING SMBD..." + (( + if test x"$SMBD_MAXTIME" = x; then + SMBD_MAXTIME=2700 + fi + MAKE_TEST_BINARY=$BINDIR/smbd + export MAKE_TEST_BINARY + timelimit $SMBD_MAXTIME $SMBD_VALGRIND $BINDIR/smbd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $SMBD_TEST_LOG 2>&1 & + TIMELIMIT_SMBD_PID=$! + MAKE_TEST_BINARY= + echo $TIMELIMIT_SMBD_PID > $PIDDIR/timelimit.smbd.pid + wait $TIMELIMIT_SMBD_PID + ret=$?; + rm -f $SERVER_TEST_FIFO + if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then + rm -f $SOCKET_WRAPPER_DIR/* + fi + if [ x"$ret" = x"0" ];then + echo "smbd exits with status $ret"; + echo "smbd exits with status $ret" >>$SMBD_TEST_LOG; + elif [ x"$ret" = x"137" ];then + echo "smbd got SIGXCPU and exits with status $ret!" + echo "smbd got SIGXCPU and exits with status $ret!">>$SMBD_TEST_LOG; + else + echo "smbd failed with status $ret!" + echo "smbd failed with status $ret!">>$SMBD_TEST_LOG; + fi + exit $ret; + ) || exit $? &) 2>/dev/null || exit $? + echo "DONE" + fi + return 0; +} + +samba3_nmbd_test_log() { + if [ -n "$NMBD_TEST_LOG" ];then + if [ -r "$NMBD_TEST_LOG" ];then + return 0; + fi + fi + return 1; +} + +samba3_winbindd_test_log() { + if [ -n "$WINBINDD_TEST_LOG" ];then + if [ -r "$WINBINDD_TEST_LOG" ];then + return 0; + fi + fi + return 1; +} + +samba3_smbd_test_log() { + if [ -n "$SMBD_TEST_LOG" ];then + if [ -r "$SMBD_TEST_LOG" ];then + return 0; + fi + fi + return 1; +} + +samba3_check_only() { + if [ -n "$SERVER_TEST_FIFO" ];then + if [ -p "$SERVER_TEST_FIFO" ];then + return 0; + fi + return 1; + fi + return 0; +} + +testit() { + if [ -z "$PREFIX" ]; then + PREFIX=test_prefix + mkdir -p $PREFIX + fi + name=$1 + shift 1 + binary=$1 + cmdline="$*" + + SERVERS_ARE_UP="no" + + shname=`echo $name | \ + sed -e 's%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\-]%_%g'` + + UNIQUE_PID=`/bin/sh -c 'echo $$'` + TEST_LOG="$PREFIX/test_log.${UNIQUE_PID}" + TEST_PCAP="$PREFIX/test_${shname}_${UNIQUE_PID}.pcap" + trap "rm -f $TEST_LOG $TEST_PCAP" EXIT + + if [ -z "$nmbd_log_size" ]; then + nmbd_log_size=`wc -l < $NMBD_TEST_LOG`; + fi + if [ -z "$winbindd_log_size" ]; then + winbindd_log_size=`wc -l < $WINBINDD_TEST_LOG`; + fi + if [ -z "$smbd_log_size" ]; then + smbd_log_size=`wc -l < $SMBD_TEST_LOG`; + fi + + if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then + echo "--==--==--==--==--==--==--==--==--==--==--" + echo "Running test $name (level 0 stdout)" + echo "--==--==--==--==--==--==--==--==--==--==--" + date + echo "Testing $name" + else + echo "Testing $name ($failed)" + fi + + samba3_check_only && SERVERS_ARE_UP="yes" + if [ x"$SERVERS_ARE_UP" != x"yes" ];then + if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then + echo "SERVERS are down! Skipping: $cmdline" + echo "==========================================" + echo "TEST SKIPPED: $name (reason SERVERS are down)" + echo "==========================================" + else + echo "TEST SKIPPED: $name (reason SERVERS are down)" + fi + return 1 + fi + + if [ x"$MAKE_TEST_ENABLE_PCAP" = x"yes" ];then + SOCKET_WRAPPER_PCAP_FILE=$TEST_PCAP + export SOCKET_WRAPPER_PCAP_FILE + fi + + MAKE_TEST_BINARY=$binary + export MAKE_TEST_BINARY + ( $cmdline > $TEST_LOG 2>&1 ) + status=$? + MAKE_TEST_BINARY= + # show any additional output from smbd that has happened in this test + samba3_nmbd_test_log && { + new_log_size=`wc -l < $NMBD_TEST_LOG`; + test "$new_log_size" = "$nmbd_log_size" || { + echo "NMBD OUTPUT:"; + incr_log_size=`expr $new_log_size - $nmbd_log_size`; + tail -$incr_log_size $NMBD_TEST_LOG; + nmbd_log_size=$new_log_size; + } + } + samba3_winbindd_test_log && { + new_log_size=`wc -l < $WINBINDD_TEST_LOG`; + test "$new_log_size" = "$winbindd_log_size" || { + echo "WINBINDD OUTPUT:"; + incr_log_size=`expr $new_log_size - $winbindd_log_size`; + tail -$incr_log_size $WINBINDD_TEST_LOG; + winbindd_log_size=$new_log_size; + } + } + samba3_smbd_test_log && { + new_log_size=`wc -l < $SMBD_TEST_LOG`; + test "$new_log_size" = "$smbd_log_size" || { + echo "SMBD OUTPUT:"; + incr_log_size=`expr $new_log_size - $smbd_log_size`; + tail -$incr_log_size $SMBD_TEST_LOG; + smbd_log_size=$new_log_size; + } + } + + if [ x"$status" != x"0" ]; then + echo "TEST OUTPUT:" + cat $TEST_LOG; + rm -f $TEST_LOG; + if [ x"$MAKE_TEST_ENABLE_PCAP" = x"yes" ];then + echo "TEST PCAP: $TEST_PCAP" + fi + if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then + echo "==========================================" + echo "TEST FAILED: $name (status $status)" + echo "==========================================" + else + echo "TEST FAILED: $cmdline (status $status)" + fi + trap "" EXIT + return 1; + fi + rm -f $TEST_LOG; + if [ x"$MAKE_TEST_KEEP_PCAP" = x"yes" ];then + echo "TEST PCAP: $TEST_PCAP" + else + rm -f $TEST_PCAP; + fi + if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then + echo "ALL OK: $cmdline" + echo "==========================================" + echo "TEST PASSED: $name" + echo "==========================================" + fi + trap "" EXIT + return 0; +} + +testok() { + name=`basename $1` + failed=$2 + + if [ x"$failed" = x"0" ];then + : + else + echo "$failed TESTS FAILED or SKIPPED ($name)"; + fi + exit $failed +} + +teststatus() { + name=`basename $1` + failed=$2 + + if [ x"$failed" = x"0" ];then + echo "TEST STATUS: $failed"; + else + echo "TEST STATUS: $failed"; + fi + exit $failed +} + +if [ -z "$VALGRIND" ]; then + MALLOC_CHECK_=2 + export MALLOC_CHECK_ +fi + diff --git a/source3/script/tests/test_groupmap.sh b/source3/script/tests/test_groupmap.sh new file mode 100755 index 0000000000..46640a9131 --- /dev/null +++ b/source3/script/tests/test_groupmap.sh @@ -0,0 +1,214 @@ +#!/bin/sh +# test groupmap code tridge@samba.org September 2006 +# note that this needs root access to add unix groups, +# so this cannot be run on the build farm + +testone() { + echo $* + $VALGRIND bin/net groupmap $* +} + +tstart() { + TBASE=`date '+%s'` +} + +treport() { + TNOW=`date '+%s'` + echo "Took `expr $TNOW - $TBASE` seconds" + TBASE=$TNOW +} + +rm -f $PREFIX_ABS/var/locks/group_mapping.?db + +NLOCAL=12 +NGROUP=11 +NBUILTIN=10 +DOMSID=`bin/net getlocalsid | awk '{print $6}'` +FORSID="S-1-2-3-4-5" + +echo "DOMSID $DOMSID" +echo "FORSID $FORSID" + +tstart +echo "Creating unix groups" +for i in `seq 1 1 $NLOCAL`; do + unixgroup=testlocal$i; + gid=`expr 30000 + $i`; + groupdel $unixgroup 2> /dev/null + groupadd -g $gid $unixgroup || exit 1 +done +for i in `seq 1 1 $NGROUP`; do + unixgroup=testgrp$i; + gid=`expr 40000 + $i`; + groupdel $unixgroup 2> /dev/null + groupadd -g $gid $unixgroup || exit 1 +done +for i in `seq 1 1 $NBUILTIN`; do + unixgroup=testb$i; + gid=`expr 50000 + $i`; + groupdel $unixgroup 2> /dev/null + groupadd -g $gid $unixgroup || exit 1 +done +date + +treport + +echo "Creating local groups" +for i in `seq 1 1 $NLOCAL`; do + unixgroup=testlocal$i; + ntgroup=ntlgrp$i; + rid=`expr 10000 + $i`; + testone add rid=$rid unixgroup=$unixgroup ntgroup=$ntgroup type=local || exit 1 +done + +echo "trying a duplicate add" +testone add rid=10001 unixgroup=testlocal1 ntgroup=foo type=local && exit 1 + +treport + +echo "Creating domain groups" +for i in `seq 1 1 $NGROUP`; do + unixgroup=testgrp$i; + ntgroup=ntgrp$i; + rid=`expr 20000 + $i`; + testone add rid=$rid unixgroup=$unixgroup ntgroup=$ntgroup type=domain || exit 1 +done + +treport + +echo "Creating builtin groups" +for i in `seq 1 1 $NBUILTIN`; do + unixgroup=testb$i; + ntgroup=ntbgrp$i; + rid=`expr 30000 + $i`; + testone add rid=$rid unixgroup=$unixgroup ntgroup=$ntgroup type=builtin || exit 1 +done + +treport + +echo "Adding domain groups to local groups" +for i in `seq 1 1 $NLOCAL`; do + for j in `seq 1 1 $i`; do + + lrid=`expr 10000 + $i`; + drid=`expr 20000 + $j`; + + testone addmem $DOMSID-$lrid $DOMSID-$drid || exit 1 + ( testone listmem $DOMSID-$lrid | sort -r ) || exit 1 + done +done + +echo "trying a duplicate addmem" +testone addmem $DOMSID-10001 $DOMSID-20001 && exit 1 + +echo "Adding foreign SIDs to local groups" +for i in `seq 1 1 $NLOCAL`; do + for j in `seq 1 1 $i`; do + + lrid=`expr 10000 + $i`; + frid=`expr 70000 + $j`; + + testone addmem $DOMSID-$lrid $FORSID-$frid || exit 1 + ( testone listmem $DOMSID-$lrid | sort -r ) || exit 1 + done +done + +echo "trying a duplicate foreign addmem" +testone addmem $DOMSID-10001 $FORSID-70001 && exit 1 + +treport + +echo "Listing local group memberships of domain groups" +for i in `seq 1 1 $NGROUP`; do + rid=`expr 20000 + $i`; + ( testone memberships $DOMSID-$rid | sort -r ) || exit 1 +done + +echo "Trying memberships on bogus sid" +testone memberships $DOMSID-999999 || exit 1 + +treport + +testone list | sort + +echo "Deleting some domain groups" +for i in `seq 2 2 $NGROUP`; do + drid=`expr 20000 + $i`; + testone delete sid=$DOMSID-$drid || exit 1 +done + +echo "Trying duplicate domain group delete" +testone delete sid=$DOMSID-20002 && exit 1 + +treport + +echo "Deleting some local groups" +for i in `seq 2 4 $NLOCAL`; do + lrid=`expr 10000 + $i`; + testone delete sid=$DOMSID-$lrid || exit 1 +done + +echo "Trying duplicate local group delete" +testone delete sid=$DOMSID-10002 && exit 1 + +treport + +echo "Modifying some domain groups" +for i in `seq 3 2 $NGROUP`; do + drid=`expr 20000 + $i`; + testone modify sid=$DOMSID-$drid comment="newcomment-$i" type=domain || exit 1 +done + +treport + +testone list | sort + +echo "Listing local group memberships" +for i in `seq 1 1 $NLOCAL`; do + rid=`expr 20000 + $i`; + ( testone memberships $DOMSID-$rid | sort -r ) || exit 1 +done + +treport + +echo "Removing some domain groups from local groups" +for i in `seq 1 2 $NLOCAL`; do + for j in `seq 1 3 $i`; do + + lrid=`expr 10000 + $i`; + drid=`expr 20000 + $j`; + + testone delmem $DOMSID-$lrid $DOMSID-$drid || exit 1 + done +done + +echo "Trying duplicate delmem" +testone delmem $DOMSID-10001 $DOMSID-20001 && exit 1 + +treport + +echo "Listing local group memberships" +for i in `seq 1 1 $NLOCAL`; do + rid=`expr 20000 + $i`; + ( testone memberships $DOMSID-$rid | sort -r ) || exit 1 +done + +treport + +echo "Deleting unix groups" +for i in `seq 1 1 $NLOCAL`; do + unixgroup=testlocal$i; + groupdel $unixgroup 2> /dev/null +done +for i in `seq 1 1 $NGROUP`; do + unixgroup=testgrp$i; + groupdel $unixgroup 2> /dev/null +done +for i in `seq 1 1 $NBUILTIN`; do + unixgroup=testb$i; + groupdel $unixgroup 2> /dev/null +done + +treport + +echo "ALL DONE" diff --git a/source3/script/tests/test_local_s3.sh b/source3/script/tests/test_local_s3.sh new file mode 100755 index 0000000000..aed8637abd --- /dev/null +++ b/source3/script/tests/test_local_s3.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# this runs the file serving tests that are expected to pass with samba3 + +if [ $# != 0 ]; then +cat <<EOF +Usage: test_local_s3.sh +EOF +exit 1; +fi + +incdir=`dirname $0` +. $incdir/test_functions.sh + +failed=0 + +testit "talloctort" $VALGRIND $BINDIR/talloctort || \ + failed=`expr $failed + 1` + +testit "replacetort" $VALGRIND $BINDIR/replacetort || \ + failed=`expr $failed + 1` + +testit "tdbtorture" $VALGRIND $BINDIR/tdbtorture || \ + failed=`expr $failed + 1` + +testit "smbconftort" $VALGRIND $BINDIR/smbconftort $CONFIGURATION || \ + failed=`expr $failed + 1` + +testok $0 $failed diff --git a/source3/script/tests/test_net_misc.sh b/source3/script/tests/test_net_misc.sh new file mode 100755 index 0000000000..0a0636ac8a --- /dev/null +++ b/source3/script/tests/test_net_misc.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +# various tests for the "net" command + +NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION" + +NETTIME="${NET} time" +NETLOOKUP="${NET} lookup" + +incdir=`dirname $0` +. $incdir/test_functions.sh + +failed=0 + +test_time() +{ + PARAM="$1" + + ${NETTIME} ${PARAM} -S localhost2 +} + +test_lookup() +{ + PARAM="$1" + + ${NETLOOKUP} ${PARAM} +} + +testit "get the time" \ + test_time || \ + failed=`expr $failed + 1` + +testit "get the system time" \ + test_time system || \ + failed=`expr $failed + 1` + +testit "get the time zone" \ + test_time zone || \ + failed=`expr $failed + 1` + +testit "lookup the PDC" \ + test_lookup pdc || \ + failed=`expr $failed + 1` + +testit "lookup the master browser" \ + test_lookup master || \ + failed=`expr $failed + 1` + +testok $0 $failed + diff --git a/source3/script/tests/test_net_registry.sh b/source3/script/tests/test_net_registry.sh new file mode 100755 index 0000000000..5edcb061ee --- /dev/null +++ b/source3/script/tests/test_net_registry.sh @@ -0,0 +1,442 @@ +#!/bin/sh + +# Tests for the "net registry" and "net rpc registry" commands. +# rpc tests are chose by specifying "rpc" as commandline parameter. + +RPC="$1" + +NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION" + +if test "x${RPC}" = "xrpc" ; then + NETREG="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc registry" +else + NETREG="${NET} registry" +fi + +incdir=`dirname $0` +. $incdir/test_functions.sh + +failed=0 + +test_enumerate() +{ + KEY="$1" + + ${NETREG} enumerate ${KEY} +} + +test_getsd() +{ + KEY="$1" + + ${NETREG} getsd ${KEY} +} + +test_enumerate_nonexisting() +{ + KEY="$1" + ${NETREG} enumerate ${KEY} + + if test "x$?" = "x0" ; then + echo "ERROR: enumerate succeeded with key '${KEY}'" + false + else + true + fi +} + +test_enumerate_no_key() +{ + ${NETREG} enumerate + if test "x$?" = "x0" ; then + echo "ERROR: enumerate succeeded without any key spcified" + false + else + true + fi +} + +test_create_existing() +{ + KEY="HKLM" + EXPECTED="createkey opened existing ${KEY}" + + OUTPUT=`${NETREG} createkey ${KEY}` + if test "x$?" = "x0" ; then + if test "$OUTPUT" = "$EXPECTED" ; then + true + else + echo "got '$OUTPUT', expected '$EXPECTED'" + false + fi + else + printf "%s\n" "$OUTPUT" + false + fi +} + +test_createkey() +{ + KEY="$1" + BASEKEY=`dirname $KEY` + SUBKEY=`basename $KEY` + + OUTPUT=`${NETREG} createkey ${KEY}` + if test "x$?" != "x0" ; then + echo "ERROR: createkey ${KEY} failed" + echo "output:" + printf "%s\n" "$OUTPUT" + false + return + fi + + # check enumerate of basekey lists new key: + OUTPUT=`${NETREG} enumerate ${BASEKEY}` + if test "x$?" != "x0" ; then + echo "ERROR: failed to enumerate key '${BASEKEY}'" + echo "output:" + printf "%s\n" "$OUTPUT" + false + return + fi + + EXPECTED="Keyname = ${SUBKEY}" + printf "%s\n" "$OUTPUT" | grep '^Keyname' | grep ${SUBKEY} + if test "x$?" != "x0" ; then + echo "ERROR: did not find expexted '$EXPECTED' in output" + echo "output:" + printf "%s\n" "$OUTPUT" + false + fi + + # check enumerate of new key works: + ${NETREG} enumerate ${KEY} +} + +test_deletekey() +{ + KEY="$1" + BASEKEY=`dirname ${KEY}` + SUBKEY=`basename ${KEY}` + + OUTPUT=`test_createkey "${KEY}"` + if test "x$?" != "x0" ; then + printf "%s\n" "${OUTPUT}" + false + return + fi + + OUTPUT=`${NETREG} deletekey ${KEY}` + if test "x$?" != "x0" ; then + printf "%s\n" "${OUTPUT}" + false + return + fi + + # check enumerate of basekey does not show key anymore: + OUTPUT=`${NETREG} enumerate ${BASEKEY}` + if test "x$?" != "x0" ; then + printf "%s\n" "$OUTPUT" + false + return + fi + + UNEXPECTED="Keyname = ${SUBKEY}" + printf "%s\n" "$OUTPUT" | 'grep ^Keyname' | grep ${SUBKEY} + if test "x$?" = "x0" ; then + echo "ERROR: found '$UNEXPECTED' after delete in output" + echo "output:" + printf "%s\n" "$OUTPUT" + false + fi + + # check enumerate of key itself does not work anymore: + ${NETREG} enumerate ${KEY} + if test "x$?" = "x0" ; then + echo "ERROR: 'enumerate ${KEY}' works after 'deletekey ${KEY}'" + false + else + true + fi +} + +test_deletekey_nonexisting() +{ + KEY="$1" + + OUTPUT=`test_deletekey "${KEY}"` + if test "x$?" != "x0" ; then + printf "%s\n" "${OUTPUT}" + false + return + fi + + ${NETREG} deletekey "${KEY}" + if test "x$?" = "x0" ; then + echo "ERROR: delete after delete succeeded for key '${KEY}'" + false + fi +} + +test_createkey_with_subkey() +{ + KEY="$1" + KEY2=`dirname ${KEY}` + SUBKEYNAME2=`basename ${KEY}` + BASENAME=`dirname ${KEY2}` + SUBKEYNAME1=`basename ${KEY2}` + + OUTPUT=`${NETREG} createkey ${KEY}` + if test "x$?" != "x0" ; then + echo "ERROR: createkey ${KEY} failed" + printf "%s\n" "${OUTPUT}" + false + return + fi + + # check we can enumerate to level key + OUTPUT=`${NETREG} enumerate ${KEY}` + if test "x$?" != "x0" ; then + echo "ERROR: failed to enumerate '${KEY}' after creation" + printf "%s\n" "${OUTPUT}" + false + return + fi + + # clear: + ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2} +} + +test_deletekey_with_subkey() +{ + KEY="$1" + KEY2=`dirname ${KEY}` + + OUTPUT=`${NETREG} createkey ${KEY}` + if test "x$?" != "x0" ; then + printf "%s\n" "${OUTPUT}" + false + return + fi + + OUTPUT=`${NETREG} deletekey ${KEY2}` + + if test "x$?" = "x0" ; then + echo "ERROR: delete of key with subkey succeeded" + echo "output:" + printf "%s\n" "$OUTPUT" + false + return + fi + + ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2} +} + +test_setvalue() +{ + KEY="$1" + VALNAME="$2" + VALTYPE="$3" + VALVALUE="$4" + + OUTPUT=`test_createkey ${KEY}` + if test "x$?" != "x0" ; then + printf "%s\n" "${OUTPUT}" + false + return + fi + + OUTPUT=`${NETREG} setvalue ${KEY} ${VALNAME} ${VALTYPE} ${VALVALUE}` + if test "x$?" != "x0" ; then + echo "ERROR: failed to set value testval in key ${KEY}" + printf "%s\n" "${OUTPUT}" + false + return + fi + + OUTPUT=`${NETREG} enumerate ${KEY}` + if test "x$?" != "x0" ; then + echo "ERROR: failure calling enumerate for key ${KEY}" + echo output: + printf "%s\n" "${OUTPUT}" + false + return + fi + + printf "%s\n" "$OUTPUT" | { + FOUND=0 + while read LINE ; do + SEARCH1=`echo $LINE | grep '^Valuename' | grep ${VALNAME}` + if test "x$?" = "x0" ; then + read LINE + read LINE + SEARCH2=`echo $LINE | grep '^Value ' | grep ${VALVALUE}` + if test "x$?" = "x0" ; then + FOUND=1 + break + fi + fi + done + + if test "x$FOUND" != "x1" ; then + echo "ERROR: did not find value '${VALNAME}' with enumerate" + echo "enumerate output:" + printf "%s\n" "$OUTPUT" + false + return + fi + } +} + +test_deletevalue() +{ + KEY="$1" + VALNAME="$2" + + ${NETREG} deletevalue ${KEY} ${VALNAME} +} + +test_deletevalue_nonexisting() +{ + KEY="$1" + VALNAME="$2" + + ${NETREG} deletevalue ${KEY} ${VALNAME} + if test "x$?" = "x0" ; then + echo "ERROR: succeeded deleting value ${VALNAME}" + false + else + true + fi +} + +test_setvalue_twice() +{ + KEY="$1" + VALNAME="$2" + VALTYPE1="$3" + VALVALUE1="$4" + VALTYPE2="$5" + VALVALUE2="$6" + + OUTPUT=`test_setvalue ${KEY} ${VALNAME} ${VALTYPE1} ${VALVALUE1}` + if test "x$?" != "x0" ; then + echo "ERROR: first setvalue call failed" + printf "%s\n" "$OUTPUT" + false + return + fi + + ${NETREG} setvalue ${KEY} ${VALNAME} ${VALTYPE2} ${VALVALUE2} +} + +give_administrative_rights() +{ + bin/net -s $SERVERCONFFILE sam createbuiltingroup Administrators + if test "x$?" != "x0" ; then + echo "ERROR: creating builtin group Administrators" + false + return + fi + + bin/net -s $SERVERCONFFILE sam addmem BUILTIN\\Administrators $USERNAME + if test "x$?" != "x0" ; then + echo "ERROR: adding user $USERNAME to BUILTIN\\Administrators" + false + else + true + fi +} + +take_administrative_rights() +{ + bin/net -s $SERVERCONFFILE sam delmem BUILTIN\\Administrators $USERNAME + if test "x$?" != "x0" ; then + echo "ERROR: removing user $USERNAME from BUILTIN\\Administrators" + false + else + true + fi +} + +if test "x${RPC}" = "xrpc" ; then +testit "giving user ${USERNAME} administrative rights" \ + give_administrative_rights || \ + failed=`expr $failed + 1` +fi + +testit "enumerate HKLM" \ + test_enumerate HKLM || \ + failed=`expr $failed + 1` + +testit "enumerate nonexisting hive" \ + test_enumerate_nonexisting XYZ || \ + failed=`expr $failed + 1` + +testit "enumerate without key" \ + test_enumerate_no_key || \ + failed=`expr $failed + 1` + +# skip getsd test for registry currently: it fails +if test "x${RPC}" != "xrpc" ; then +testit "getsd HKLM" \ + test_getsd HKLM || \ + failed=`expr $failed + 1` +fi + +testit "create existing HKLM" \ + test_create_existing || \ + failed=`expr $failed + 1` + +testit "create key" \ + test_createkey HKLM/testkey || \ + failed=`expr $failed + 1` + +testit "delete key" \ + test_deletekey HKLM/testkey || \ + failed=`expr $failed + 1` + +testit "delete^2 key" \ + test_deletekey_nonexisting HKLM/testkey || \ + failed=`expr $failed + 1` + +testit "enumerate nonexisting key" \ + test_enumerate_nonexisting HKLM/testkey || \ + failed=`expr $failed + 1` + +testit "create key with subkey" \ + test_createkey_with_subkey HKLM/testkey/subkey || \ + failed=`expr $failed + 1` + +testit "delete key with subkey" \ + test_deletekey_with_subkey HKLM/testkey/subkey || \ + failed=`expr $failed + 1` + +testit "set value" \ + test_setvalue HKLM/testkey testval sz moin || \ + failed=`expr $failed + 1` + +testit "delete value" \ + test_deletevalue HKLM/testkey testval || \ + failed=`expr $failed + 1` + +testit "delete nonexisting value" \ + test_deletevalue_nonexisting HKLM/testkey testval || \ + failed=`expr $failed + 1` + +testit "set value to different type" \ + test_setvalue_twice HKLM/testkey testval sz moin dword 42 || \ + failed=`expr $failed + 1` + +testit "delete key with value" \ + test_deletekey HKLM/testkey || \ + failed=`expr $failed + 1` + +if test "x${RPC}" = "xrpc" ; then +testit "taking administrative rights from user ${USERNAME}" \ + take_administrative_rights || \ + failed=`expr $failed + 1` +fi + +testok $0 $failed + diff --git a/source3/script/tests/test_net_s3.sh b/source3/script/tests/test_net_s3.sh new file mode 100755 index 0000000000..f7dc2b7e10 --- /dev/null +++ b/source3/script/tests/test_net_s3.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# tests for the "net" command + +incdir=`dirname $0` +. $incdir/test_functions.sh + +failed=0 + +net_misc() { + echo "RUNNING SUBTESTS net_misc" + $SCRIPTDIR/test_net_misc.sh \ + || failed=`expr $failed + $?` +} + +net_registry() { + echo "RUNNING SUBTESTS net_registry" + $SCRIPTDIR/test_net_registry.sh \ + || failed=`expr $failed + $?` +} + +net_rpc_registry() { + echo "RUNNING SUBTESTS net_rpc_registry" + $SCRIPTDIR/test_net_registry.sh rpc \ + || failed=`expr $failed + $?` +} + +net_misc +net_registry +net_rpc_registry + +testok $0 $failed + diff --git a/source3/script/tests/test_ntlm_auth_s3.sh b/source3/script/tests/test_ntlm_auth_s3.sh new file mode 100755 index 0000000000..6c97f2e650 --- /dev/null +++ b/source3/script/tests/test_ntlm_auth_s3.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +incdir=`dirname $0` +. $incdir/test_functions.sh + +failed=0 + +(/usr/bin/env python --version > /dev/null 2>&1) + +if test $? -ne 0; +then + echo "Python binary not found in path. Skipping ntlm_auth tests." + exit 0 +fi + +testit "ntlm_auth" $VALGRIND $SRCDIR/torture/test_ntlm_auth.py $BINDIR/ntlm_auth --configfile=$CONFFILE || failed=`expr $failed + 1` +# This should work even with NTLMv2 +testit "ntlm_auth" $VALGRIND $SRCDIR/torture/test_ntlm_auth.py $BINDIR/ntlm_auth --configfile=$CONFFILE --client-domain=fOo --server-domain=fOo || failed=`expr $failed + 1` + + +testok $0 $failed diff --git a/source3/script/tests/test_posix_s3.sh b/source3/script/tests/test_posix_s3.sh new file mode 100755 index 0000000000..3e9998666c --- /dev/null +++ b/source3/script/tests/test_posix_s3.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +# this runs the file serving tests that are expected to pass with samba3 + +if [ $# -lt 3 ]; then +cat <<EOF +Usage: test_posix_s3.sh UNC USERNAME PASSWORD <first> <smbtorture args> +EOF +exit 1; +fi + +unc="$1" +username="$2" +password="$3" +start="$4" +shift 4 +ADDARGS="$*" + +incdir=`dirname $0` +. $incdir/test_functions.sh + +base="BASE-ATTR BASE-CHARSET BASE-CHKPATH BASE-DEFER_OPEN BASE-DELAYWRITE BASE-DELETE" +base="$base BASE-DENY1 BASE-DENY2 BASE-DENY3 BASE-DENYDOS BASE-DIR1 BASE-DIR2" +base="$base BASE-DISCONNECT BASE-FDPASS BASE-LOCK" +base="$base BASE-MANGLE BASE-NEGNOWAIT BASE-NTDENY1" +base="$base BASE-NTDENY2 BASE-OPEN BASE-OPENATTR BASE-PROPERTIES BASE-RENAME BASE-RW1" +base="$base BASE-SECLEAK BASE-TCON BASE-TCONDEV BASE-TRANS2 BASE-UNLINK BASE-VUID" +base="$base BASE-XCOPY BASE-SAMBA3ERROR" + +raw="RAW-ACLS RAW-CHKPATH RAW-CLOSE RAW-COMPOSITE RAW-CONTEXT RAW-EAS" +raw="$raw RAW-IOCTL RAW-LOCK RAW-MKDIR RAW-MUX RAW-NOTIFY RAW-OPEN RAW-OPLOCK" +raw="$raw RAW-QFILEINFO RAW-QFSINFO RAW-READ RAW-RENAME RAW-SEARCH RAW-SEEK" +raw="$raw RAW-SFILEINFO RAW-SFILEINFO-BUG RAW-STREAMS RAW-UNLINK RAW-WRITE" +raw="$raw RAW-SAMBA3HIDE RAW-SAMBA3BADPATH RAW-SFILEINFO-RENAME" +raw="$raw RAW-SAMBA3CASEINSENSITIVE RAW-SAMBA3POSIXTIMEDLOCK" +raw="$raw RAW-SAMBA3ROOTDIRFID" + +rpc="RPC-AUTHCONTEXT RPC-BINDSAMBA3 RPC-SAMBA3-SRVSVC RPC-SAMBA3-SHARESEC" +rpc="$rpc RPC-SAMBA3-SPOOLSS RPC-SAMBA3-WKSSVC" +rpc="$rpc RPC-NETLOGSAMBA3 RPC-SAMBA3SESSIONKEY RPC-SAMBA3-GETUSERNAME" + +# NOTE: to enable the UNIX-WHOAMI test, we need to change the default share +# config to allow guest access. I'm not sure whether this would break other +# tests, so leaving it alone for now -- jpeach +unix="UNIX-INFO2" + +tests="$base $raw $rpc $unix" + +if test "x$POSIX_SUBTESTS" != "x" ; then + tests="$POSIX_SUBTESTS" +fi + +skipped="BASE-CHARSET BASE-TCONDEV" +skipped="$skipped RAW-ACLS RAW-COMPOSITE RAW-CONTEXT" +skipped="$skipped RAW-IOCTL" +skipped="$skipped RAW-QFILEINFO RAW-QFSINFO" +skipped="$skipped RAW-SFILEINFO" + +echo "WARNING: Skipping tests $skipped" + +ADDARGS="$ADDARGS --option=torture:sharedelay=100000" +ADDARGS="$ADDARGS --option=torture:writetimeupdatedelay=500000" + +failed=0 +for t in $tests; do + if [ ! -z "$start" -a "$start" != $t ]; then + continue; + fi + skip=0 + for s in $skipped; do + if [ x"$s" = x"$t" ]; then + skip=1; + break; + fi + done + if [ $skip = 1 ]; then + continue; + fi + start="" + name="$t" + testit "$name" $VALGRIND $SMBTORTURE4 $TORTURE4_OPTIONS $ADDARGS $unc -U"$username"%"$password" $t || failed=`expr $failed + 1` +done + +testok $0 $failed diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh new file mode 100755 index 0000000000..c10aed0ee6 --- /dev/null +++ b/source3/script/tests/test_smbclient_s3.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# this runs the file serving tests that are expected to pass with samba3 + +if [ $# -lt 2 ]; then +cat <<EOF +Usage: test_smbclient_s3.sh SERVER SERVER_IP +EOF +exit 1; +fi + +SERVER="$1" +SERVER_IP="$2" +SMBCLIENT="$VALGRIND ${SMBCLIENT:-$BINDIR/smbclient} $CONFIGURATION" +shift 2 +ADDARGS="$*" + +incdir=`dirname $0` +. $incdir/test_functions.sh + +failed=0 + +# Test that a noninteractive smbclient does not prompt +test_noninteractive_no_prompt() +{ + prompt="smb" + + echo du | \ + $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I SERVER_IP $ADDARGS 2>&1 | \ + grep $prompt + + if [ $? = 0 ] ; then + # got a prompt .. fail + echo matched interactive prompt in non-interactive mode + false + else + true + fi +} + +# Test that an interactive smbclient prompts to stdout +test_interactive_prompt_stdout() +{ + prompt="smb" + tmpfile=/tmp/smbclient.in.$$ + + cat > $tmpfile <<EOF +du +quit +EOF + + CLI_FORCE_INTERACTIVE=yes \ + $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP \ + $ADDARGS < $tmpfile 2>/dev/null | \ + grep $prompt + + if [ $? = 0 ] ; then + # got a prompt .. succeed + rm -f $tmpfile + true + else + echo failed to match interactive prompt on stdout + rm -f $tmpfile + false + fi +} + +testit "smbclient -L $SERVER_IP" $SMBCLIENT $CONFIGURATION -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1` +testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT $CONFIGURATION -L $SERVER -I $SERVER_IP -N -p 139 || failed=`expr $failed + 1` + +testit "noninteractive smbclient does not prompt" \ + test_noninteractive_no_prompt || \ + failed=`expr $failed + 1` + +testit "noninteractive smbclient -l does not prompt" \ + test_noninteractive_no_prompt -l /tmp || \ + failed=`expr $failed + 1` + +testit "interactive smbclient prompts on stdout" \ + test_interactive_prompt_stdout || \ + failed=`expr $failed + 1` + +testit "interactive smbclient -l prompts on stdout" \ + test_interactive_prompt_stdout -l /tmp || \ + failed=`expr $failed + 1` + +testok $0 $failed diff --git a/source3/script/tests/test_smbtorture_s3.sh b/source3/script/tests/test_smbtorture_s3.sh new file mode 100755 index 0000000000..acb641b9fb --- /dev/null +++ b/source3/script/tests/test_smbtorture_s3.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# this runs the file serving tests that are expected to pass with samba3 + +if [ $# -lt 3 ]; then +cat <<EOF +Usage: test_smbtorture_s3.sh UNC USERNAME PASSWORD <first> <smbtorture args> +EOF +exit 1; +fi + +unc="$1" +username="$2" +password="$3" +start="$4" +shift 4 +ADDARGS="$*" + +incdir=`dirname $0` +. $incdir/test_functions.sh + +tests="FDPASS LOCK1 LOCK2 LOCK3 LOCK4 LOCK5 LOCK6 LOCK7" +#tests="$tests UNLINK BROWSE ATTR TRANS2 MAXFID TORTURE " +tests="$tests UNLINK BROWSE ATTR TRANS2 TORTURE " +tests="$tests OPLOCK1 OPLOCK2 OPLOCK3" +tests="$tests DIR DIR1 TCON TCONDEV RW1 RW2 RW3" +tests="$tests OPEN XCOPY RENAME DELETE PROPERTIES W2K" +tests="$tests TCON2 IOCTL CHKPATH FDSESS LOCAL-SUBSTITUTE" + +skipped1="RANDOMIPC NEGNOWAIT NBENCH ERRMAPEXTRACT TRANS2SCAN NTTRANSSCAN" +skipped2="DENY1 DENY2 OPENATTR CASETABLE EATEST" +skipped3="MANGLE UTABLE PIPE_NUMBER" +echo "Skipping the following tests:" +echo "$skipped1" +echo "$skipped2" +echo "$skipped3" + +failed=0 +for t in $tests; do + if [ ! -z "$start" -a "$start" != $t ]; then + continue; + fi + start="" + name="$t" + testit "$name" $VALGRIND $BINDIR/smbtorture $unc -U"$username"%"$password" $ADDARGS $t || failed=`expr $failed + 1` +done + +testok $0 $failed diff --git a/source3/script/tests/test_testparm_s3.sh b/source3/script/tests/test_testparm_s3.sh new file mode 100755 index 0000000000..0962ca0764 --- /dev/null +++ b/source3/script/tests/test_testparm_s3.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +# Tests for lp_load() via testparm. +# +# The main purpose (for now) is to test all the special handlers +# and the macro expansions. + +TEMP_CONFFILE=${LIBDIR}/smb.conf.tmp +TESTPARM="$VALGRIND ${TESTPARM:-$BINDIR/testparm} --suppress-prompt --skip-logic-checks" + +incdir=`dirname $0` +. $incdir/test_functions.sh + +failed=0 + +test_include_expand_macro() +{ + MACRO=$1 + rm -f ${TEMP_CONFFILE} + cat >${TEMP_CONFFILE}<<EOF +[global] + include = ${TEMP_CONFFILE}.%${MACRO} +EOF + ${TESTPARM} ${TEMP_CONFFILE} +} + +test_one_global_option() +{ + OPTION=$1 + rm -f ${TEMP_CONFFILE} + cat > ${TEMP_CONFFILE}<<EOF +[global] + ${OPTION} +EOF + ${TESTPARM} ${TEMP_CONFFILE} +} + +test_copy() +{ + rm -f ${TEMP_CONFFILE} + cat > ${TEMP_CONFFILE}<<EOF +[share1] + path = /tmp + read only = no + +[share2] + copy = share1 +EOF + ${TESTPARM} ${TEMP_CONFFILE} +} + + +testit "netbios name" \ + test_one_global_option "netbios name = funky" || \ + failed=`expr ${failed} + 1` + +testit "netbios aliases" \ + test_one_global_option "netbios aliases = funky1 funky2 funky3" || \ + failed=`expr ${failed} + 1` + +testit "netbios scope" \ + test_one_global_option "netbios scope = abc" || \ + failed=`expr ${failed} + 1` + +testit "workgroup" \ + test_one_global_option "workgroup = samba" || \ + failed=`expr ${failed} + 1` + +testit "display charset" \ + test_one_global_option "display charset = UTF8" || \ + failed=`expr ${failed} + 1` + +testit "ldap debug level" \ + test_one_global_option "ldap debug level = 7" || \ + failed=`expr ${failed} + 1` + +for LETTER in U G D I i L N M R T a d h m v w V ; do +testit "include with %${LETTER} macro expansion" \ + test_include_expand_macro "${LETTER}" || \ + failed=`expr ${failed} + 1` +done + +testit "copy" \ + test_copy || \ + failed=`expr ${failed} + 1` + +rm -f ${TEMP_CONFFILE} + +testok $0 ${failed} + diff --git a/source3/script/tests/test_wbinfo_s3.sh b/source3/script/tests/test_wbinfo_s3.sh new file mode 100755 index 0000000000..e3bf1b9e70 --- /dev/null +++ b/source3/script/tests/test_wbinfo_s3.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +if [ $# -lt 4 ]; then +cat <<EOF +Usage: test_wbinfo_s3.sh DOMAIN SERVER USERNAME PASSWORD <wbinfo args> +EOF +exit 1; +fi + +domain="$1" +server="$2" +username="$3" +password="$4" +shift 4 +ADDARGS="$*" + +incdir=`dirname $0` +. $incdir/test_functions.sh + +OLDIFS=$IFS; + +tests="--ping" +tests="$tests:--separator" +tests="$tests:--own-domain" +tests="$tests:--all-domains" +tests="$tests:--trusted-domains" +tests="$tests:--domain-info=BUILTIN" +tests="$tests:--domain-info=$domain" +tests="$tests:--online-status" +tests="$tests:--online-status --domain=BUILTIN" +tests="$tests:--online-status --domain=$domain" +#Didn't pass yet# tests="$tests:--domain-users" +tests="$tests:--domain-groups" +tests="$tests:--name-to-sid=$username" +#Didn't pass yet# tests="$tests:--user-info=$username" +tests="$tests:--user-groups=$username" + +failed=0 + +OLDIFS=$IFS +NEWIFS=$':' +IFS=$NEWIFS +for t in $tests; do + IFS=$OLDIFS + testit "wbinfo $t" $VALGRIND $BINDIR/wbinfo $CONFIGURATION $ADDARGS $t || failed=`expr $failed + 1` + IFS=$NEWIFS +done +IFS=$OLDIFS + +testok $0 $failed diff --git a/source3/script/tests/tests_all.sh b/source3/script/tests/tests_all.sh new file mode 100755 index 0000000000..2b46da0e77 --- /dev/null +++ b/source3/script/tests/tests_all.sh @@ -0,0 +1,94 @@ +local_s3() { + echo "RUNNING TESTS local_s3" + $SCRIPTDIR/test_local_s3.sh \ + || failed=`expr $failed + $?` +} + +smbtorture_s3() { + echo "RUNNING TESTS smbtorture_s3" + $SCRIPTDIR/test_smbtorture_s3.sh \ + //$SERVER_IP/tmp $USERNAME $PASSWORD "" \ + || failed=`expr $failed + $?` +} + +smbtorture_s3_encrypted() { + echo "RUNNING TESTS smbtorture_s3_encrypted" + $SCRIPTDIR/test_smbtorture_s3.sh \ + //$SERVER_IP/tmp $USERNAME $PASSWORD "" "-e" \ + || failed=`expr $failed + $?` +} + +smbclient_s3() { + echo "RUNNING TESTS smbclient_s3" + $SCRIPTDIR/test_smbclient_s3.sh $SERVER $SERVER_IP \ + || failed=`expr $failed + $?` +} + +smbclient_s3_encrypted() { + echo "RUNNING TESTS smbclient_s3_encrypted" + $SCRIPTDIR/test_smbclient_s3.sh $SERVER $SERVER_IP "-e" \ + || failed=`expr $failed + $?` +} + +wbinfo_s3() { + echo "RUNNING TESTS wbinfo_s3" + $SCRIPTDIR/test_wbinfo_s3.sh $WORKGROUP $SERVER $USERNAME $PASSWORD \ + || failed=`expr $failed + $?` +} + +ntlm_auth_s3() { + echo "RUNNING TESTS ntlm_auth_s3" + $SCRIPTDIR/test_ntlm_auth_s3.sh \ + || failed=`expr $failed + $?` +} + +net_s3() { + echo "RUNNING TESTS net_s3" + $SCRIPTDIR/test_net_s3.sh \ + || failed=`expr $failed + $?` +} + +testparm_s3() { + echo "RUNNING TESTS testparm_s3" + $SCRIPTDIR/test_testparm_s3.sh \ + || failed=`expr $failed + $?` +} + +posix_s3() { + echo "RUNNING TESTS posix_s3" + eval "$LIB_PATH_VAR="\$SAMBA4SHAREDDIR:\$$LIB_PATH_VAR"; export $LIB_PATH_VAR" + eval echo "$LIB_PATH_VAR=\$$LIB_PATH_VAR" + if [ -x "$SMBTORTURE4" ]; then + SMBTORTURE4VERSION=`$SMBTORTURE4 --version` + fi + if [ -n "$SMBTORTURE4" -a -n "$SMBTORTURE4VERSION" ];then + echo "Running Tests with Samba4's smbtorture" + echo $SMBTORTURE4VERSION + $SCRIPTDIR/test_posix_s3.sh \ + //$SERVER_IP/tmp $USERNAME $PASSWORD "" \ + || failed=`expr $failed + $?` + else + echo "Skip Tests with Samba4's smbtorture" + echo "Try to compile with --with-smbtorture4-path=PATH to enable" + fi +} + +failed=0 + +if test "x$TESTS" = "x" ; then + local_s3 + smbtorture_s3 + smbtorture_s3_encrypted + smbclient_s3 + smbclient_s3_encrypted + wbinfo_s3 + ntlm_auth_s3 + net_s3 + testparm_s3 + posix_s3 +else + for THIS_TEST in $TESTS; do + $THIS_TEST + done +fi + diff --git a/source3/script/tests/tests_smbclient_s3.sh b/source3/script/tests/tests_smbclient_s3.sh new file mode 100644 index 0000000000..d48a692d4b --- /dev/null +++ b/source3/script/tests/tests_smbclient_s3.sh @@ -0,0 +1 @@ +. $SCRIPTDIR/test_smbclient_s3.sh $SERVER $SERVER_IP diff --git a/source3/script/tests/timelimit.c b/source3/script/tests/timelimit.c new file mode 100644 index 0000000000..886256cb37 --- /dev/null +++ b/source3/script/tests/timelimit.c @@ -0,0 +1,102 @@ +/* run a command with a limited timeout + tridge@samba.org, June 2005 + metze@samba.org, March 2006 + + attempt to be as portable as possible (fighting posix all the way) +*/ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/wait.h> + +static pid_t child_pid; + +static void usage(void) +{ + printf("usage: timelimit <time> <command>\n"); + printf(" SIGUSR1 - passes SIGTERM to command's process group\n"); + printf(" SIGALRM - passes SIGTERM to command's process group\n"); + printf(" after 5s SIGKILL will be passed and exit(1)\n"); + printf(" SIGTERM - passes SIGTERM to command's process group\n"); + printf(" after 1s SIGKILL will be passed and exit(1)\n"); +} + +static void sig_alrm_kill(int sig) +{ + fprintf(stderr, "\nMaximum time expired in timelimit - killing\n"); + kill(-child_pid, SIGKILL); + exit(1); +} + +static void sig_alrm_term(int sig) +{ + kill(-child_pid, SIGTERM); + alarm(5); + signal(SIGALRM, sig_alrm_kill); +} + +static void sig_term(int sig) +{ + kill(-child_pid, SIGTERM); + alarm(1); + signal(SIGALRM, sig_alrm_kill); +} + +static void sig_usr1(int sig) +{ + kill(-child_pid, SIGTERM); +} + +static void new_process_group(void) +{ + if (setpgid(0,0) == -1) { + perror("setpgid"); + exit(1); + } +} + + +int main(int argc, char *argv[]) +{ + int maxtime, ret=1; + + if (argc < 3) { + usage(); + exit(1); + } + + maxtime = atoi(argv[1]); + + child_pid = fork(); + if (child_pid == 0) { + new_process_group(); + execvp(argv[2], argv+2); + perror(argv[2]); + exit(1); + } + + signal(SIGTERM, sig_term); + signal(SIGINT, sig_term); + signal(SIGQUIT, sig_term); + signal(SIGUSR1, sig_usr1); + signal(SIGALRM, sig_alrm_term); + alarm(maxtime); + + do { + int status; + pid_t pid = wait(&status); + if (pid != -1) { + ret = WEXITSTATUS(status); + } else if (errno == ECHILD) { + break; + } + } while (1); + + kill(-child_pid, SIGKILL); + + exit(ret); +} |