#!/bin/sh
# $Id: t-dnsbl-1.sh,v 1.13 2007/01/14 00:19:02 ca Exp $
# Copyright (c) 2004, 2005 Sendmail, Inc. and its suppliers.
# All rights reserved.
#
# By using this file, you agree to the terms and conditions set
# forth in the LICENSE file which can be found at the top level of
# the sendmail distribution.
#
# ------------------------------------------------------------
# Description:
# Script to test DNS BL and access map restrictions (only IP addresses)
# Uses smar, t-smar-3, access map, t-mm, startsmar.sh
# ------------------------------------------------------------
#
test -s stop && exit 1
#
if test X"${MTA_NO_DNS_TEST}" != "X"
then
echo "SKIPPED: $0"
exit 0
fi
SD=`dirname $0`
if test "${SD}" = "."
then
SD=../smar
fi
. ${SD}/common.sh
OUT=dnsbl-0.out
IP=dnsbl-0.ip
OK=dnsbl-0.ok
TPRG=./t-smar-3
VERBOSE=false
CONF=smar.conf
RMTMP=true
if test X"`uname`" != "XOSF1"
then
while getopts kV FLAG
do
case "${FLAG}" in
k) RMTMP=false;;
V) VERBOSE=true;;
esac
done
shift `expr ${OPTIND} - 1`
fi
rm -f ${ACCMAP} ${SOCK} ${PIDS}
# create access map for tests
${MM} -t' ' -F ${ACCMAP} <<EOF
meta1dnsbl:127.0.0.1 error:550 5.7.1 found 127.0.0.1 in meta1dnsbl
meta1dnsbl:127.0.0.2 error:550 5.7.2 found 127.0.0.2 in meta1dnsbl
cltaddr:127.0.0.1 ok
cltaddr:127.0.0.3 ok
meta1dnsbl:127.0.0.3 error:550 5.7.3 found 127.0.0.3 in meta1dnsbl
meta1all:127.0.0.2 error:550 5.7.4 found 127.0.0.2 in meta1all
meta1bl:127.0.0.128 error:550 5.7.5 found 127.0.0.128 in meta1bl
EOF
cat > ${CONF} <<EOF
smar {
Log_Level = 12;
DNS_timeout = 5;
# should tag include ":"?
dnsbl { domain = dnsbl.meta1.org.; tag = "meta1dnsbl"; }
dnsbl { domain = bl.meta1.org.; tag = "meta1bl"; }
dnsbl { domain = all.meta1.org.; tag = "meta1all"; }
}
EOF
# start SMAR
${SHELL} ${SD}/startsmar.sh -f ${CONF} || exit 1
rm -f ${OUT} ${IP} ${OK}
TEST=1
# ----------------------------------------
# test: dnsbl: rejection (wildcard match)
${VALGRIND} ${TPRG} -d '1.2.3.4' > ${OUT} 2>&1
grep '^react=' ${OUT} > ${IP}
cat > ${OK} <<EOF
react=statt, ret=0, statt='550 5.7.4 found 127.0.0.2 in meta1all
EOF
if diff ${OK} ${IP}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
${VERBOSE} && echo ${TEST} failed
fi
TEST=2
# ----------------------------------------
# test: dnsbl: rejection (first dnsbl)
${VALGRIND} ${TPRG} -d '127.0.0.2' > ${OUT} 2>&1
grep '^react=' ${OUT} > ${IP}
cat > ${OK} <<EOF
react=statt, ret=0, statt='550 5.7.2 found 127.0.0.2 in meta1dnsbl
EOF
if diff ${OK} ${IP}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
${VERBOSE} && echo ${TEST} failed
fi
TEST=3
# ----------------------------------------
# test: dnsbl: wildcard match, override
${VALGRIND} ${TPRG} -d '127.0.0.1' > ${OUT} 2>&1
grep '^react=' ${OUT} > ${IP}
cat > ${OK} <<EOF
EOF
if diff ${OK} ${IP}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
${VERBOSE} && echo ${TEST} failed
fi
TEST=4
# ----------------------------------------
# test: dnsbl: rejection (second dnsbl)
${VALGRIND} ${TPRG} -d '127.0.0.128' > ${OUT} 2>&1
grep '^react=' ${OUT} > ${IP}
cat > ${OK} <<EOF
react=statt, ret=0, statt='550 5.7.5 found 127.0.0.128 in meta1bl
EOF
if diff ${OK} ${IP}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
${VERBOSE} && echo ${TEST} failed
fi
# stop SMAR
for i in `cat ${PIDS}`
do
kill ${i}
done
# ----------------
# thanks kids for not following the POSIX standard...
if test X"`uname`" = "XLinux"
then
killall smar
fi
sleep 3
if test ${ERRS} -eq 0
then
${RMTMP} && rm -f ${OUT} ${IP} ${OK}
fi
exit ${ERRS}
syntax highlighted by Code2HTML, v. 0.9.1