#!/bin/sh -
# A sample "POP before SMTP"-enabler script for tcp_wrappers
# This script should be installed in /usr/local/etc
# If you are thinking of using this script on heavily loaded host,
# you had better to choose tcpserver instead of tcp_wrappers.
# 
ALLOWTMP="/var/log/ATMP"
if [ -f /usr/local/etc/hosts.allow ]; then
 ALLOW="/usr/local/etc/hosts.allow"
else
 ALLOW=/etc/hosts.allow
fi
ALLOWSRC=${ALLOW}.src
ALLOWNEW=${ALLOW}.new

# for debug
# (env;echo "1=$1") | Mail -s pop3access yuuji

case $0 in
  *record)
	echo "tcp-env : $RELAYCLIENT : setenv = RELAYCLIENT" >> $ALLOWTMP.1
	;;
  *age)
	rm -f $ALLOWTMP.2
	[ -f $ALLOWTMP.1 ] && mv -f $ALLOWTMP.1 $ALLOWTMP.2
	;;
  *)
	# else generate master hosts.allow file
	;;
esac
touch $ALLOWTMP.1 $ALLOWTMP.2
echo "#
# DO NOT EDIT THIS FILE!
# This file is generated from $ALLOWSRC file.
# Edit it!
#" > $ALLOWNEW
(cat $ALLOWTMP.[12] | sort -u; cat $ALLOWSRC) >> $ALLOWNEW
/bin/mv -f $ALLOWNEW $ALLOW

# pop3-{age,update,record} for tcp_wrappers ends here
# The following section is the sample routine for tcpserver(ucsp-tcp)
# If you use tcpserver, replace the above section after "case $0...esac"
# by the following section.
# Sample code was contributed by pirozeau(pirozeau@banana-fish.com).

#TCPREMOTEIP=${TCPREMOTEIP:-undefined}
#RELAYCLIENT=${RELAYCLIENT:-$TCPREMOTEIP}
#ALLOW=/usr/local/etc/smtprule
#case $0 in
#  *record)
#	echo "$RELAYCLIENT:allow,RELAYCLIENT=\"\"" >> $ALLOWTMP.1
#	;;
#  *age)
#	rm -f $ALLOWTMP.2
#	[ -f $ALLOWTMP.1 ] && mv -f $ALLOWTMP.1 $ALLOWTMP.2
#	;;
#  *)
#	# else generate master tcprule file
#	;;
#esac
#touch $ALLOWTMP.1 $ALLOWTMP.2
#(cat $ALLOWTMP.[12] | sort -u; cat ${ALLOW}) | /usr/local/bin/tcprules ${ALLOW}.cdb ${ALLOW}.tmp
