#!/bin/sh
# $Id: t-smar-rvrs-2.sh,v 1.1 2007/03/09 04:38:23 ca Exp $
#
# ------------------------------------------------------------
# Description:
# Script to test access map restrictions (only IP addresses)
# and reverse lookups (PTR).
# 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: MTA_NO_DNS_TEST is set"
  exit 0
fi
# this test requires DNS entries for 10.0.255.*
if test X"${MTA_HAVE_10_INADDRARPA}" != "Xtrue"
then
  echo "SKIPPED: $0: MTA_HAVE_10_INADDRARPA is not set to true"
  exit 0
fi

SD=`dirname $0`
if test "${SD}" = "."
then
   SD=../smar
fi
. ${SD}/common.sh

OUT=smar-rvrs-2.out
IP=smar-rvrs-2.ip
OK=smar-rvrs-2.ok
VERBOSE=false
TPRG=./t-smar-3

if test X"`uname`" != "XOSF1"
then
while getopts V FLAG
do
  case "${FLAG}" in
    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
cltaddr:10.0.255.9	ok
cltresolve:NO	error:450 4.7.1 get a name
EOF

# start SMAR
${SHELL} ${SD}/startsmar.sh || exit 1
rm -f ${OUT} ${IP} ${OK}

TEST=1
# ----------------------------------------
# does not match, but overridden by cltaddr:
${VALGRIND} ${TPRG} 10.0.255.9 > ${OUT} 2>&1
grep '^react=' ${OUT} > ${IP}
cat > ${OK} <<EOF
react=rvrs_st, ret=0, stat=2
EOF
if diff ${OK} ${IP}
then
  :
else
  ERRS=`expr ${ERRS} + 1 `
  echo "$0: test ${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

exit ${ERRS}


syntax highlighted by Code2HTML, v. 0.9.1