# Assumptions: # We're not running with uid 0 or 1. # We're not running with gid 0 or 2. # supervise is installed. # The DNS cache translates 127.0.0.1<->localhost. # There is no listener for TCP port 16. # There is no listener for TCP port 50016. # There is no use of TCP ports 50017, 50018, 50019, 50020. rm -rf rts-tmp mkdir rts-tmp cd rts-tmp echo '#!/bin/sh trap "" 13 echo PROTO="$PROTO" echo TCPLOCALHOST="${TCPLOCALHOST-unset}" echo TCPLOCALIP="${TCPLOCALIP-unset}" echo TCPLOCALPORT="${TCPLOCALPORT-unset}" echo TCPREMOTEHOST="${TCPREMOTEHOST-unset}" echo TCPREMOTEIP="${TCPREMOTEIP-unset}" echo TCPREMOTEPORT="${TCPREMOTEPORT-unset}" echo TCPREMOTEINFO="${TCPREMOTEINFO-unset}" ' > print chmod 755 print mkdir 50016 echo '#!/bin/sh exec tcpserver \ -c 2 -Bbanner -vo -D -1 -Xx rules.cdb -Rt5 -hp -l Local -b 2 \ 127.0.0.1 50016 ../print ' > 50016/run chmod 755 50016/run supervise 50016 >log 2>&1 & echo '--- tcpclient prints usage message without enough arguments' tcpclient 0 0; echo $? echo '--- tcpclient prints error message with unknown port name' tcpclient 0 nonexistentport echo wrong; echo $? echo '--- tcpclient prints error message when connection fails' tcpclient 0 016 echo wrong; echo $? echo '--- tcpclient -q does not print error message when connection fails' tcpclient -q 0 016 echo wrong; echo $? echo '--- tcpclient understands empty host name as synonym for 0' tcpclient '' 016 echo wrong; echo $? echo '--- tcpclient understands unbracketed IP address' tcpclient '127.000.000.001' 016 echo wrong; echo $? echo '--- tcpclient understands bracketed IP address' tcpclient '[127.000.000.001]' 016 echo wrong; echo $? echo '--- tcpclient prints error message with unknown host name' tcpclient nonexistent.local. 016 echo wrong; echo $? echo '--- tcpclient prints error message with unresolvable host name' tcpclient thislabelistoolongbecausednshasalimitof63charactersinasinglelabel. 016 echo wrong; echo $? echo '--- tcpserver prints usage message without enough arguments' tcpserver 0 0; echo $? echo '--- tcpserver -u 1 attempts to set uid to 1' tcpserver -u 1 0 0 echo wrong; echo $? echo '--- tcpserver -U reads $UID' env UID=1 tcpserver -U 0 0 echo wrong; echo $? echo '--- tcpserver -g 2 attempts to set gid to 2' tcpserver -g 2 0 0 echo wrong; echo $? echo '--- tcpserver -U reads $GID' env GID=2 tcpserver -U 0 0 echo wrong; echo $? echo '--- tcpserver prints error message with unknown port name' tcpserver 0 nonexistentport echo wrong; echo $? echo '--- tcpserver prints error message with unknown host name' tcpserver nonexistent.local. 016 echo wrong; echo $? echo '--- tcpserver prints error message with unresolvable host name' tcpserver thislabelistoolongbecausednshasalimitof63charactersinasinglelabel. 016 echo wrong; echo $? echo '--- tcpserver prints error message with non-local host name' tcpserver 1.2.3.4 016 echo wrong; echo $? echo '--- tcpserver sets basic environment variables' tcpclient -p 50017 -R -H -T 10 -l Local 0 50016 sh -c 'cat <&6' echo $? echo '--- tcpclient recognizes -D, -i, -r, -h, -t' tcpclient -Di 127.0.0.1 -p 50018 -hrt1 -l Local \ 127.0.0.1 50016 sh -c 'cat <&6' echo $? echo '--- tcpclient sets basic environment variables' tcpclient -p 50019 -R -H -l Local 0 50016 ./print echo $? echo '--- tcpclient looks up host names properly' tcpclient -p 50020 -R 0 50016 ./print echo $? echo '--- tcpclient -v works' tcpclient -v -R -H -l Local 0 50016 echo ok echo $? echo '--- tcpserver prints error message with used port' tcpserver -R -H -l Local 127.0.0.1 50016 echo wrong echo $? echo '--- tcpcat works' tcpcat 0 50016 | grep -v TCPREMOTEPORT echo $? echo '--- mconnect works' mconnect 0 50016 &1 >/dev/null \ | sed 's/^[0-9]*/.../' | sed 's/$/$/' echo '--- recordio handles multiple-line packets' ( echo 'test test2'; sleep 1 ) | recordio cat 2>&1 >/dev/null \ | sed 's/^[0-9]*/.../' | sed 's/$/$/' echo '--- recordio handles partial final lines' ( echo test | tr -d '\012'; sleep 1 ) | recordio cat 2>&1 >/dev/null \ | sed 's/^[0-9]*/.../' | sed 's/$/$/' echo '--- argv0 works' argv0 sh zero -c 'echo $0'; echo $? echo '--- argv0 requires arguments' argv0 sh; echo $? echo '--- rblsmtpd does not find 127.0.0.1 on the RBL' ( echo help; echo quit ) \ | ( TCPREMOTEIP=127.0.0.1 rblsmtpd echo ok 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd finds 127.0.0.2 on the RBL' ( echo help; echo quit ) \ | ( TCPREMOTEIP=127.0.0.2 rblsmtpd echo whoops 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd -b uses a permanent error code' ( echo help; echo quit ) \ | ( TCPREMOTEIP=127.0.0.2 rblsmtpd -b echo whoops 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd quits after a timeout' sleep 2 \ | ( TCPREMOTEIP=127.0.0.2 rblsmtpd -cBt1 echo whoops 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd prints an immediate error message with -t0' sleep 2 \ | ( TCPREMOTEIP=127.0.0.2 rblsmtpd -Ct0 echo whoops 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd understands an empty $RBLSMTPD' ( echo help; echo quit ) \ | ( TCPREMOTEIP=127.0.0.2 RBLSMTPD= rblsmtpd echo ok 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd understands a nonempty $RBLSMTPD' ( echo help; echo quit ) \ | ( TCPREMOTEIP=127.0.0.2 RBLSMTPD=Error rblsmtpd echo whoops 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd understands a permanent $RBLSMTPD' ( echo help; echo quit ) \ | ( TCPREMOTEIP=127.0.0.2 RBLSMTPD=-Error rblsmtpd echo whoops 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd understands -r' ( echo help; echo quit ) \ | ( TCPREMOTEIP=127.0.0.2 rblsmtpd -r nonexistent.local echo ok 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' echo '--- rblsmtpd understands -a' ( echo help; echo quit ) \ | ( TCPREMOTEIP=127.0.0.2 rblsmtpd -a rbl.maps.vix.com echo ok 2>&1; echo $? ) \ | sed 's/pid [0-9]*/pid x/' svc -dx 50016 wait echo '--- tcpserver -1v prints proper messages' sed -e 's/::.*/::x/' -e 's/ [0-9]* / x /' < log exit 0