#!/bin/sh
# $Id: t-alias-5.sh,v 1.11 2006/10/05 01:32:28 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 alias expansion for RFC2821 addresses using
# different address delimiters.
# Uses smar, t-smar-1, "aliases" map, t-mm, startsmar.sh
# and t-hostname.
# ------------------------------------------------------------
#
test -s stop && exit 1
#
# path to programs
P=..
SD=`dirname $0`
if test "${SD}" = "."
then
SD=../smar
fi
. ${SD}/common.sh
OUT=alias-5.out
RES=alias-5.ip
OK=alias-5.ok
TPRG=./t-smar-1
CONF=smar.conf
# Note: reference to t-hostname! XREF
HOSTNAME=`../libmta/t-hostname -l -V 2>/dev/null`
if test $? -ne 0
then
echo "t-hostname failed"
exit 1
fi
if test X"${HOSTNAME}" = X
then
echo "t-hostname returned empty name"
exit 1
fi
if echo X"${HOSTNAME}" | grep '\.' >/dev/null
then
:
else
echo "t-hostname returned bogus name ${HOSTNAME}"
exit 1
fi
killit()
{
if test -s ${PIDS}
then
# stop MTA components
for i in `cat ${PIDS}`
do
kill ${i}
done
fi
# ----------------
# thanks kids for not following the POSIX standard...
if test X"`uname`" = "XLinux"
then
killall smar
fi
#rm -f ${MTMAP}
exit 1
}
rm -f ${SOCK} ${PIDS}
trap killit 1 2 3
for DELIM in "-" "/" "!"
do
# create map for smar
rm -f ${ALIMAP}
${MM} <<EOF
user: local:
user${DELIM}*: <user@local.dom>
user${DELIM}+: local:
postmaster: <user${DELIM}postmaster@local.dom>
loc: user
nodetail: <user2@local.dom>
EOF
if test $? -ne 0
then
echo t-mm failed
exit 1
fi
# create mailertable (save old version?)
${CAT} > ${MT} <<EOF
local.dom lmtp:
${HOSTNAME} lmtp:
EOF
cat > ${CONF} <<EOF
smar {
Log_Level = 12;
DNS_timeout = 5;
address_delimiter= "${DELIM}";
}
EOF
# start SMAR
${SHELL} ${SD}/startsmar.sh -f ${CONF} || exit 1
rm -f ${OUT} ${RES} ${OK}
TEST=1
# ----------------------------------------
# check output somehow...
${VALGRIND} ${TPRG} -VVV '<no@local.dom>' > ${OUT} 2>&1
egrep '^(IP|alias)' ${OUT} > ${RES}
cat > ${OK} <<EOF
IP[0]=${MTA_LMTPIPV4D} [${MTA_LMTPIPV4H}]
EOF
if diff -i ${OK} ${RES}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
test X"${MTA_STOPONERROR}" != X && killit
fi
TEST=2
# ----------------------------------------
${VALGRIND} ${TPRG} -VVV '<user@local.dom>' > ${OUT} 2>&1
egrep '^(IP|alias)' ${OUT} > ${RES}
cat > ${OK} <<EOF
IP[0]=${MTA_LMTPIPV4D} [${MTA_LMTPIPV4H}]
EOF
if diff -i ${OK} ${RES}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
test X"${MTA_STOPONERROR}" != X && killit
fi
TEST=3
# ----------------------------------------
${VALGRIND} ${TPRG} -VVV "<user${DELIM}det@local.dom>" > ${OUT} 2>&1
egrep '^(IP|alias)' ${OUT} > ${RES}
cat > ${OK} <<EOF
IP[0]=${MTA_LMTPIPV4D} [${MTA_LMTPIPV4H}]
EOF
if diff -i ${OK} ${RES}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
test X"${MTA_STOPONERROR}" != X && killit
fi
TEST=4
# ----------------------------------------
${VALGRIND} ${TPRG} -VVV '<postmaster@local.dom>' > ${OUT} 2>&1
egrep '^(IP|alias)' ${OUT} | sort > ${RES}
sort > ${OK} <<EOF
aliased=<user${DELIM}postmaster@local.dom>
IP[0]=${MTA_LMTPIPV4D} [${MTA_LMTPIPV4H}]
EOF
if diff -i ${OK} ${RES}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
test X"${MTA_STOPONERROR}" != X && killit
fi
TEST=5
# ----------------------------------------
${VALGRIND} ${TPRG} -VVV "<user${DELIM}@local.dom>" > ${OUT} 2>&1
egrep '^(IP|alias)' ${OUT} | sort > ${RES}
sort > ${OK} <<EOF
aliased=<user@local.dom>
IP[0]=${MTA_LMTPIPV4D} [${MTA_LMTPIPV4H}]
EOF
if diff -i ${OK} ${RES}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
test X"${MTA_STOPONERROR}" != X && killit
fi
TEST=6
# ----------------------------------------
${VALGRIND} ${TPRG} -M -VVV '<loc@local.dom>' > ${OUT} 2>&1
egrep '^(IP|alias)' ${OUT} | sort > ${RES}
sort > ${OK} <<EOF
aliased=<user@${HOSTNAME}>
IP[0]=${MTA_LMTPIPV4D} [${MTA_LMTPIPV4H}]
EOF
if diff -i ${OK} ${RES}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
test X"${MTA_STOPONERROR}" != X && killit
fi
TEST=7
# ----------------------------------------
${VALGRIND} ${TPRG} -VVV '<nodetail@local.dom>' > ${OUT} 2>&1
egrep '^(IP|alias)' ${OUT} | sort > ${RES}
sort > ${OK} <<EOF
aliased=<user2@local.dom>
IP[0]=${MTA_LMTPIPV4D} [${MTA_LMTPIPV4H}]
EOF
if diff -i ${OK} ${RES}
then
:
else
ERRS=`expr ${ERRS} + 1 `
echo "$0: test ${TEST} failed."
test X"${MTA_STOPONERROR}" != X && killit
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
# for DELIM loop
done
rm -f ${MTMAP}
exit ${ERRS}
syntax highlighted by Code2HTML, v. 0.9.1