#
# secondary: generate rules to be a secondary mail master
#

REVISION_ID='@(#)secondary	3.7 (motonori/WIDE) 2/26/94'

#|# secondary domain
#|##SECONDARY_DOMAIN='secondary.domain.name'
#|# list of users belong to the domain
#|##SECONDARY_USERS='hash:/etc/aliases.secondary'
#|##SECONDARY_USERS='dbm:/etc/aliases.secondary'
#|##SECONDARY_USERS='nis:aliases.secondary.map'
#|##SECONDARY_USERS='user1 user2 ...'
#|##SECONDARY_USERS=/etc/users.secondary
#|##SECONDARY_USERS='/etc/aliases.secondary %[^: \#]'
#|## the last style is available only with sendmail compiled with SCANF option
#|# addresses for users belong to the domain (yes/no)
#|#USE_SECONDARY_DOMAIN_FROM=no
#|#USE_SECONDARY_DOMAIN_TO=no

if [ "$SECONDARY_DOMAIN" ]
then

	if [ "$REVISION_ID_LIST" ]
	then
		REVISION_ID_LIST="$REVISION_ID_LIST\\
# $REVISION_ID"
	else
		REVISION_ID_LIST="# $REVISION_ID"
	fi

	# allocate class/macro character pair
	case "$SECONDARY_USERS" in
	hash:*|dbm:*|nis:*)
		_ALLOC_TYPE=macro
		_ALLOC_USAGE='secondary domain [secondary]'
		;;
	*)
		_ALLOC_TYPE=pair
		_ALLOC_USAGE='secondary domain/users [secondary]'
		;;
	esac
	_ALLOC_MODE=normal
	_ALLOC_DIR=down
	_ALLOC_PREF=T
	. $MASTERDIR/$CHARALLOC
	case "$SECONDARY_USERS" in
	hash:*|dbm:*|nis:*)
		;;
	*)
		_SU_CHAR=$_ALLOC_CHAR
		;;
	esac
	_SD_CHAR=$_ALLOC_CHAR

	# domainname
	MACRO=${SECONDARY_DOMAIN+D$_SD_CHAR$SECONDARY_DOMAIN}
	if [ "$MACRO" = "" ]
	then
		MACRO='#D'$_SD_CHAR'my.domain.name'
	fi

	# user who should be recognized as local (for secondary domain master)
	case "$SECONDARY_USERS" in
	hash:*)	# newdb hash style alias lookup
		SECNAME=`expr "$SECONDARY_USERS" : 'hash:\(.*\)'`
		SECONDARYMATCH='Kaliases hash -m -a@ '$SECNAME
		SECDBLOOKUP=yes
		;;
	dbm:*)	# dbm style alias lookup
		SECNAME=`expr "$SECONDARY_USERS" : 'dbm:\(.*\)'`
		SECONDARYMATCH='Kaliases dbm -m -a@ '$SECNAME
		SECDBLOOKUP=yes
		;;
	nis:*)	# NIS style alias lookup
		SECNAME=`expr "$SECONDARY_USERS" : 'nis:\(.*\)'`
		SECONDARYMATCH='Kaliases nis -m -a@ '$SECNAME
		SECDBLOOKUP=yes
		;;
	*:*)	# unknown map
		echo 'secondary: unknown map specified in SECONDARY_USERS.' 1>&2
		;;
	"")
		SECONDARYMATCH='#F'$_SU_CHAR'/etc/users.local'
		;;
	/*)     # file definition
		SECONDARYMATCH="F$_SU_CHAR$SECONDARY_USERS"
		SECDBLOOKUP=no
		;;
	*)      # definition in .cf
		exec << EoF
$SECONDARY_USERS
EoF
		SECONDARYMATCH=`sed 's/^/C'$_SU_CHAR' /'`
		SECDBLOOKUP=no
		;;
	esac

HDRSECONDARY="\\
# users to be recognized as local (for secondary domain master)\\
$SECONDARYMATCH\\
# domain name\\
$MACRO"


	: ${USE_SECONDARY_DOMAIN_FROM=no}
	: ${USE_SECONDARY_DOMAIN_TO=no}
	if [ "$SECDBLOOKUP" = yes ]
	then

SECONDARYRULE='\
# special domain to be recognized as local (for socondary domain master)\
R$+<@$'$_SD_CHAR'>		$:$(aliases $1 $) <@$'$_SD_CHAR'>\
R$+@<@$'$_SD_CHAR'>		$:$1'


		if [ "$USE_SECONDARY_DOMAIN_FROM" != no ]
		then

S11SECONDARY='# tack on secondary address to secondary users\
R$+			$:$(aliases $1 $)\
R$+@			$@$1<@$'$_SD_CHAR'>'
		fi

		if [ "$USE_SECONDARY_DOMAIN_TO" != no ]
		then

S21SECONDARY='# tack on secondary address to secondary users\
R$+			$:$(aliases $1 $)\
R$+@			$@$1<@$'$_SD_CHAR'>'

		fi

	else

SECONDARYRULE='\
# special domain to be recognized as local (for socondary domain master)\
R$='$_SU_CHAR'<@$'$_SD_CHAR'>		$1'

		if [ "$USE_SECONDARY_DOMAIN_FROM" != no ]
		then

S11SECONDARY='# tack on secondary address to secondary users\
R$='$_SU_CHAR'			$@$1<@$'$_SD_CHAR'>			secondary'

		fi

		if [ "$USE_SECONDARY_DOMAIN_TO" != no ]
		then

S21SECONDARY='# tack on secondary address to secondary users\
R$='$_SU_CHAR'			$@$1<@$'$_SD_CHAR'>			secondary'

		fi

	fi


fi
