Using a database in the check_* rulesets

Last Update 1999-10-06

Enhanced version to use a database in check_mail

Ted Roberts suggested to use a map lookup instead of a plain text file (e.g., a class) to list spammers. This has the advantage that you don't need to restart sendmail when you change the entries in the database. Moreover, if the file gets large (as it may happen since UCEs become nearly ubiquitous) the match should be faster. Stefan Monnier made a nice proposal, on which the following ruleset is based:
# check for junk domain/spammers
Sjunk
# lookup domain in database
R$*<@$+>$*		$:$1<@$(junk $2$)>$3
# exists? return
R$*<@JUNK>$*		$@$1<@JUNK>$2
# lookup address in database
R$*<@$+>$*		$:$1<@$(junk $1@$2 $:$2$)>$3
# exists? return
R$*<@SPAMMER>$*		$@$1<@SPAMMER>$2
# mv one subdomain in front, try again
R$*<@$-.$-.$+>$*	$: $2<@> $>junk $1<@$3.$4>$5
# undo damage
R$*<@>$*<@$+>$*		$2<@$1.$3>$4
This requires a database (map) which contains entries for well-known spammers in the form:
spammer@address.domain SPAMMER
and for junk domains in the form
junk.domain JUNK
Then it can be used in sendmail.cf as:
Kjunk dbm /etc/mail/junk
(you may choose another database type and another location). This is now used in the ruleset as follows:
Scheck_mail
# don't check these
R<$*@$=w>	$@ ok			shortcut
# idea from Steven Schultz
R<>		$: <$n @ $(dequote "" $&{client_name} $) >
R$*		$: $>3 $1			canonify
R$-		$@ ok				local host
# no host without a . in the FQHN ?
R$*<@$->$*	$#error $@ 5.1.8 $: 550 invalid host name $2, check your configuration.
# no DNS entry? this is dangerous!
# R$*<@$*$~P>$*	$#error $@ 4.1.8 $: 451 unresolvable host name $2$3, check your setup.
# now remove the dot
R$*<@$*.>$*	$: $1<@$2>$3
# and check the database
R$*<@$*>$*	$: $>junk $1<@$2>$3
R$*<@$*JUNK>$*	$#error $@ 5.7.1 $: "550 This domain is banned, contact your local admin." 	go away
R$*<@$*SPAMMER>$*	$#error $@ 5.7.1 $: "550 You are banned, contact your local admin." 	go away
It is also available as HACK(check_mail2) in the check.tar file for use in a .mc file.

There are of course many variations how a database can be used. This is just one example. It could be simplified, if you don't need different error messages for banned domains and e-mail addresses (which is currently distinguished by the values SPAMMER and JUNK in the database).


[(links)] [Hints] [Avoiding UBE] [cf/README] [New]
Copyright © Claus Aßmann Please send comments to: <ca at sendmail.org>
Disclaimer: the information provided may be inaccurate or outdated or incomplete. Please contact me if you find an error.