29.10 The check_... Rule Sets
The rapid spread of the Internet has led to an increase of
mail abuses. Prior to V8.8
sendmail
, detecting and rejecting
abusive email required that you write C language code for
use in the
checkcompat
() routine (see
Section 20.1, "How checkcompat() Works"
). Beginning with
V8.8
sendmail
important and useful checking and rejecting
can be done from within four brand new rule sets:
These routines are handled in the same manner. If the rule set
does not exist, the address is accepted. If the rule set returns
anything other than a 29.10.1 The check_mail Rule SetThe MAIL command in the SMTP dialog is used to specify the envelope-sender address:
MAIL From: <sender@host.domain>
If the
To illustrate one use for the
Scheck_mail R$* $: $>3 $1 focus on the host R$* <@ $+. > $* $1 <@ $2> $3 strip trailing dots R$* <@ $+ > $* $: $2 isolate the host R$* . $+ . $+ $: $2 . $3 strip subdomains Rspamming.org $#error $@ 5.7.1 $: "cannot accept mail from spamming.org" Here, we force rule set 3 to preprocess the address so that any RFC822 comments will be thrown away and so that the host part of the address will be focused. We then strip any trailing dots from the hostname to prevent a trailing dot from wrongly effecting our validation. In the third line we throw away everything but the hostname. In the fourth line we throw away all but the rightmost two components of the hostname to eliminate the host part and any subdomain prefixes. What remains is just the domain name. We then compare that domain name to the hostname spamming.org . If they match, we reject the sender. After this rule set is installed (and the sendmail daemon had been restarted), all mail from spamming.org will be rejected during the SMTP dialogue like this:
MAIL From: <badguy@spamming.org> 553 <badguy@spamming.org>... cannot accept mail from spamming.org
This is just one possible use of the
If you need to base a decision to reject mail on both the sender and the recipient,
you may be able to use the 29.10.2 The check_rcpt Rule SetThe RCPT command in the SMTP dialogue specifies an envelope recipient's address:
RCPT To: <recipient@host.domain>
If the
To illustrate one use for the
R$* $: $>3 $1 focus on host R$* <@ $~w > $* $@ ok not @ourhost is okay R$* <@ $+ > $* $: $1 discard host Rfax $#error $@ 5.1.3 $: "cannot send mail to fax" Here, we first call rule set 3 to focus on the host part of the address and normalize it. The second rule accepts anything that is addressed to any host but our own. That way, mail to fax@another.host will work. The third rule discards the host (our local) part of the address. In the fourth line the remaining user part is compared to the name fax . Any mail to fax is thus rejected:
RCPT To: <fax@ourhost> 553 <fax@ourhost>... cannot send mail to fax
Other uses for this
29.10.3 The check_relay Rule Set
V8.8
sendmail
supports two mechanisms for screening incoming SMTP
connections. One is the
libwrap.a
mechanism (see
Section 22.4.1
);
the other is this
The
hostname $| IPnumber
The hostname and IP number are separated by the
One way to use
hostA.edu Spamming site hostB.com Mail Bombing site 123.45.6 Offensive domain Notice that the keys can be hostnames or IP addresses. Such a database might be declared in the configuration file like this:
Kbadhosts dbm -a <> /etc/badhosts Now, each time a site connects to your running daemon, the following rule set will be called:
Scheck_relay R$* $| $* $: $(badhosts $1 $) $| $2 look up host name R$*<> $| $* $#error $@ 5.1.3 $: Sorry, $1 denied R$* $| $* $: $2 select the IP number R$-.$-.$-.$- $: $(badhosts $1.$2.$3 $) look up domain part R$*<> $#error $@ 5.1.3 $: Sorry, $1 denied R$* $@ ok otherwise okay
The second rule looks up the host part in the database. If it is found,
the value (reason for rejection) is returned and the two characters
Sorry, reason for reject denied Rejected connections are handled the same way as connections rejected by the libwrap.a technique (see Section 22.4.1 ).
The rest of the rules do the same thing, except that they check for the IP
number. If the Note that the rules presented here are not nearly as complex or sophisticated as your site will likely need. It does not, for example, reject on the basis of the domain part of hostnames, nor does it reject on the basis of the individual host IP addresses.
Note that such rule sets cannot be tested in rule-testing mode, because
that mode interprets the expression
STranslate R$* $$| $* $: $1 $| $2 fake for -bt mode
This rule set changes a literal
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked) Enter <ruleset> <address> >
Here, the comma-separated list of rule sets begins with
29.10.4 The check_compat Rule Set
Not all situations can be resolved by simply checking the recipient or sender address.
Sometimes you will need to make judgments based on pairs of addresses.
To handle this situation,
V8.8 introduced the
The
sender $| recipient
The sender and recipient address are separated by the
As one example of a way to use the
SGet_domain R$* $: $>3 $1 focus on host R$* <@ $+. > $* $1 <@ $2> $3 strip trailing dots R$* <@ $+ > $* $: $2 isolate the host R$* . $+ . $+ $@ $2 . $3 strip host and subdomains SGet_user R$* $: $>3 $1 focus on host R$* <@ $+ > $* $@ $1 discard host Scheck_compat R$* $| $* $: $1 $| $>Get_domain $2 fetch recipient domain R$* $| $=w $@ ok local is okay R$* $| $m $@ ok local is okay R$* $| $* $: $>Get_user $1 fetch sender user Roperator $#error $@ 5.1.3 $: "operator may not mail offsite"
First we set up two subroutines patterned after the code in the previous two sections.
The first reduces its workspace to just the domain part of an address.
The second reduces an address to just the user part.
These two subroutines are called by
The first rule in
If the domain is an offsite one, we then call
Other uses for the
Note that such rule sets cannot be tested in rule-testing mode because
that mode interprets the expression |
|