Полезная информация

sendmail

sendmailSearch this book
Previous: 29.5 Rule Set 4Chapter 29
Rule Sets
Next: 29.7 Rule Set 5
 

29.6 Rule Set 0

The job of rule set 0 is to select a delivery agent for each recipient. It is called once for each recipient and must rewrite each into a special form called a triple. A triple is simply three pieces of information: the symbolic name of the delivery agent, the host part of the address, and the user part of the address. Each part is indicated in the RHS by a special prefix operator, as shown in Table 29.2.

Table 29.2: Rule Set 0 Special RHS Operators
OperatorDescription
$#Delivery agent
$@Recipient host
$:Recipient user

The triple is formed by rewriting with the RHS. It looks like this:

$#delivery_agent $@host $:user

The delivery agent selection must be the first of the three. In addition to specifying the delivery agent, $# also causes rule set 0 to exit. The other two parts of the triple must appear in the order shown ($@ first, then $:).

All three parts of the triple must be present in the RHS. The only exception is the $@host part when the delivery agent has the F=l flag set. It may be present for IDA and V8 sendmail but must be absent for all other versions of sendmail.

Not all rules in rule set 0 are specifically used to select a delivery agent. It may be necessary, for example, to canonicalize an address with $[ and $] (see Section 28.6.6, "Canonicalize Hostname: $[ and $]") before being able to decide whether the address is local or remote.

If an address passes through rule set 0 without selecting a delivery agent, the following error message is produced, and the mail message bounces:

buildaddr: no mailer in parsed address

Therefore it is important to design a rule set 0 that selects a delivery agent for every legitimate address.

If a triple is missing the user part, the following error is produced:

buildaddr: no user

If the delivery agent that is selected is one for which there is no corresponding M configuration file declaration, the error is

buildaddr: unknown mailer bad delivery agent name here

29.6.1 Further Processing: $:user

The user part of the triple is intended for use in the command line of the delivery agent and in the RCPT command in an SMTP connection. For either use, that address is rewritten by rule set 2, the R= equate of the delivery agent, and rule set 4, as illustrated in Figure 29.5. This means that the user part can be in focused form, because the focus is later removed by rule set 4. But the user part must be a single username (no host) for the local delivery agent.

The rewritten result is stored for use when a delivery agent's $u in A= (see Section 30.4.1, A=) argument is expanded. For example, for the local delivery agent, the rewritten result is the username as it will be given to /bin/mail for local delivery.

Figure 29.5: The flow of $:user through rule sets

Figure 29.5

The rewritten result is also given to a remote site during the exchange of mail using the SMTP protocol. The local machine tells the remote machine the name of the recipient by saying RCPT to: followed by the rewritten user portion of the triple.

29.6.2 Selecting S= and R=

When it selects a delivery agent, rule set 0 also selects the rules that will be used in rewriting sender and recipient addresses. A sender address is rewritten by the rule set specified by the S= equate (see Section 30.4.11, S=). The recipient addresses are rewritten by the rule set specified by the R= equate (see Section 30.4.10). If the R= or S= specifies rule set 0 or if either is undeclared, then that portion of rewriting is skipped.

We won't cover individual R= or S= rule sets here, because they depend on the individual needs of delivery agents. Instead, we recommend that you examine how your configuration file uses them. You'll probably be surprised to find that many R= and S= equates reference nonexistent rules (which means that sendmail will do no rewriting).

29.6.3 Delivering to Local Recipient

Typically, some early rules in rule set 0 are intended to detect addresses that should be delivered locally. A rule that accomplishes that end might look like this:

R$+ <@ $w>          $#local $:$1                 local address

Here, the $w macro is the name of the local host. Note that the RHS strips the focused host part from the username.

At some sites, the local host can be known by any of several names. A rule to handle such hosts would begin with a class declaration that adds those names to the class w (like the first line below):

Cw font-server fax printer3
R$+ <@ $=w>        $#local $:$1                 local address

The class w is special because it is the one to which sendmail automatically appends the alternative name of the local host. The class declaration line above adds names that sendmail might not automatically detect. Usually, such a declaration would be near the top of the configuration file, rather than in rule set 0, but technically it can appear anywhere in the file. This rule looks to see whether an address contains any of the names in class w. If it does, the $=w in the LHS matches, and the RHS selects the local delivery agent.

On central mail server machines, rule set 0 may also have to match from a list of hosts for which the central server is an MX recipient machine (see Section 19.6.26, FEATURE(use-cw-file)).

29.6.4 Forwarding to a Knowledgeable Host

After handling mail destined for the local host, rule set 0 generally looks for addresses that require a knowledgeable host to forward messages on the local host's behalf. In the following rule, $B (see Section 31.10.5, $B) is the name of a machine that knows how to deliver BITNET mail (see Section 19.4.5, "Relays"):

R$* <@ $+.BITNET> $*   $#smtp $@$B $:$1<@$2.BITNET>$3    user@host.BITNET

The tag .BITNET would have been added by users when sending mail. Note that BITNET in the LHS is case-insensitive; a user can specify Bitnet, bitnet, or even BiTNeT, and this rule will still match. A similar scheme can be used for other specialty addresses, such as UUCP and DECnet.

29.6.5 Handling UUCP Locally

Hosts sometimes deliver mail to a few UUCP connections locally and forward to other UUCP connections through a knowledgeable host. The rules that handle this situation often make use of another class:

R$* <@ $=V.UUCP>     $#uucp $@$2 $:$1               user@localuucp
R$* <@ $+.UUCP>      $#smtp $@$Y $:$1<@$2.UUCP>     kick upstairs

Here, the class $=V contains a list of local UUCP connections. They are matched by the first rule, which selects the uucp delivery agent. All other UUCP addresses are passed to the knowledgeable host in $Y (see Section 31.10.45, $Y)). The user part ($:) that is given to the knowledgeable host is the original address as it appeared to the LHS.

29.6.6 Forwarding over the Network

Next, rule set 0 typically sees whether it can send the mail message over the network. In the following example we assume that the local host is connected to an IP network:

# deal with other remote names
R$* <@ $*> $*         $#smtp $@$2 $:$1<@$2>$3          user@host.domain

Remember that we have already screened out and handled delivery to the local host, and therefore the focused host (in the <@$*> of the LHS) is on the network. The smtp delivery agent is selected (to deliver using the SMTP protocol), with connection to be made to $2 (the $* part of the <@$*> in the LHS).

The focus is kept in the user portion of the RHS triple. Remember that the user portion will be rewritten by rule sets 2, R=, and 4. Also remember that rule set 4 will defocus the address. The reason we keep the focus here is because rule set 2 and all R= rules expect the host part of addresses to be focused.

29.6.7 Handling Leftover Local Addresses

Whatever is left after all preceding rules in rule set 0 have selected delivery agents is probably a local address. Here, we check for a username without a host part:

R$+       $#local $:$1        regular local names

Notice that the user part is not focused; it is unfocused because there is no host part on lone local usernames.


Previous: 29.5 Rule Set 4sendmailNext: 29.7 Rule Set 5
29.5 Rule Set 4Book Index29.7 Rule Set 5