29. Rule Sets
Contents:
Rule sets in the configuration file, like subroutines in a program, control the sequence of steps sendmail uses to rewrite addresses. Inside each rule set is a series of zero or more individual rules. Rules are used to select the appropriate delivery agent for any particular address, to detect and reject addressing errors, and to transform addresses to meet particular needs. In this chapter we will cover all aspects of rule sets, showing that rule sets are called in particular orders and explaining why this is so. We will explain many of the rules that typically appear in rule sets. But be forewarned: The examples of rules in this chapter are explanatory only. Your sendmail.cf file is likely to have rules that are somewhat different from these examples. Copying or using these examples, without first understanding the underlying principles, can cause email to begin to fail. 29.1 The S Configuration Command
The
S
The
/etc/sendmail.cf: line
Prior to V8.7
sendmail
the 29.1.1 Rule-Set NumbersPrior to V8.7 sendmail , rule sets could be identified only by numbers. When a rule set is declared with an integer, that integer is taken to be the numeric identity of the rule set:
S
Here,
bad ruleset
Here, the 29.1.2 Rule-Set NamesBeginning with V8.7 sendmail , rule sets may be declared with numbers (as above) or with more meaningful names. The form for a rule-set name declaration looks like this:
S The name may contain only ASCII alphanumeric characters and the underscore character. Any bad character causes that character and the characters following it to be silently ignored:
My_rule good My rule bad, name is ``My''
Case is recognized; that is, There may be at most MAXRWSETS/2 named rule sets (where MAXRWSETS is defined in conf.h ). Each rule set that is declared beyond that amount causes sendmail to print the following error and ignore that rule-set declaration:
When you declare a rule set name, sendmail associates a number with it. That number is selected by counting down from MAXRWSETS. That is, the first name is given the number MAXRWSETS-1, the second is given the number MAXRWSETS-2, and so on. Named rule sets may be used anywhere that numbered rule sets can be used. 29.1.3 Associate Number with NameWhen knowing the number associated with a named rule set is of importance, you can associate a number with a name when the name is declared. The form of such a combined declaration looks like this:
S
Here, the rule set named
/etc/sendmail.cf: line Although it is ugly, different names may share the same number:
Sfoo=1 Sfee=1 However, the same name may not be given a different number. Consider the following example:
SMyrule=1 SMyrule=2 This causes sendmail to print the following error and skip the second declaration:
/etc/sendmail.cf: line
Named rule sets have numbers associated with them when they first appear. If you
use a named rule set in an
Mprog, P=sh, ...., S= The solution is either to move the rule-set declaration (and its rules) so that they reside above the delivery agent declaration or to declare a numeric association in the delivery agent declaration instead of in the rule-set declaration:
Mprog, P=sh, ...., S=
or to place just the
S In general, we recommend that you assign numbers to named rule sets only if there is a genuine need. 29.1.4 Macros in Rule-Set NamesMacros may be used in any or all of a part of a rule-set declaration. They may be used to declare a name:
D{NAME}myname S${NAME} or to declare a number:
D{NUMBER}12 S${NUMBER} or both a name and a number:
D{NAME}myname D{NUMBER}12 S${NAME}=${NUMBER} or even the whole thing:
D{SET}myset=12 S${SET} You may use single- and multicharacter macros in any combination. Macros may be used in any rule-set declaration, including subroutine calls inside rules:
R$* < $=w > $* $@ $>${NAME} $2
But they may not be used in the
Mprog, P=sh, ..., S=$X, R=$X, ... neither of these will work Macros can be used in the command line to modify a configuration file when sendmail is run. Consider the desire to call one rule set when running as a daemon and another when processing the queue. You might declare such a rule like:
R$* < @ $+ > $* $@ $> The two different runs might look like this:
# /usr/lib/sendmail -MAdaemon_rule -bd # /usr/lib/sendmail -MAqueue_rule -q30m
The first defines the
R$* < @ $+ > $* $@ $>
The second defines the
R$* < @ $+ > $* $@ $> Note that you cannot define multi character macros from the command line. Also note that defining macros from the command line can result in sendmail giving up its root privilege. 29.1.5 Rule Sets and Lists of Rules
All rules (
S0 R... rules added to rule set 0 SMyset R... rules added to rule set Myset S1 R... rules added to rule set 1 Rule sets need not be declared in any particular order. Any order that clarifies the intention of the configuration file as a whole is acceptable. If a rule set appears more than once in a configuration file, V8 sendmail will print a warning:
WARNING: Ruleset and append the new rules to the old:
S0 R... rules added to rule set 0 S2 R... rules added to rule set 2 S0 warning issued R... rules appended to earlier rule set 0
Note that the warning is given in all cases prior to V8.8, but beginning
with V8.8, it is issued only in Other configuration commands may be interspersed among rule definitions without affecting the rule set to which the rules are added:
S0 R... rules added to rule set 0 Pjunk=-100 DUuucphost.our.domain R... rules added to rule set 0
Any rules that appear before the first
R... rules added to rule set 0 S1 first S command in configuration file R... rules added to rule set 1
29.1.6 Odds and EndsArbitrary text that follows a rule set declaration is ignored unless it appears to be part of the declaration:
S11 100 more rule sets rule set 11 S11100 more rule sets rule set 11,100 is illegal SMyset 100 more rule sets rule set Myset
Although the first and last of the above examples work, we recommend that
you use the
S11 #100 more rule sets rule set 11 S11#100 more rule sets rule set 11 SMyset #100 more rule sets rule set Myset A rule-set declaration that has no rules associated with it is exactly the same as a rule set that is not declared. Both are like do-nothing subroutines:
rule set 1 not declared. Same as S2 rule set 2 without rules S3 R... |
|