📄 0119-0121.html
字号:
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:SMTP and POP</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=07 //-->
<!-- PAGES=0097-0130 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0116-0118.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0122-0124.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-119"><P>Page 119</P></A>
<P>The values of macros and classes are matched in the
lhs with the operators shown in Table 7.3.
</P>
<P>Table 7.3. lhs macro and class-matching operators.
</P>
<HR>
<TABLE WIDTH="360">
<TR><TD>
Operator
</TD><TD>
Description
</TD></TR>
<TR><TD>
$X
</TD><TD>
Matches the value of macro X
</TD></TR>
<TR><TD>
$=C
</TD><TD>
Matches any word in class C
</TD></TR>
<TR><TD>
$~C
</TD><TD>
Matches if token is not in class C
</TD></TR>
</TABLE>
<P>The pattern-matching operators and macro- and class-matching operators are necessary
because most rules must match many different input addresses. For example, a rule might
need to match all addresses that end with
gonzo.gov and begin with one or more of anything.
</P>
<H4><A NAME="ch07_ 33">
The Right-Hand Side (rhs) of Rules
</A></H4>
<P>The rhs of a rewriting rule tells sendmail how to rewrite an address that matches the
lhs. The rhs can include text, macros, and positional references to matches in the
lhs. When a pattern-matching operator from Table 7.2 matches the input,
sendmail assigns it to a numeric macro $n, corresponding to the position it matches in the
lhs. For example, suppose the address
joe@pc1.gonzo.gov is passed to the following rule:
</P>
<!-- CODE SNIP //-->
<PRE>
R$+ @ $+ $: $1 < @ $2 > focus on domain
</PRE>
<!-- END CODE SNIP //-->
<P>In this example, joe matches $+ (one or more of anything), so
sendmail assigns the string joe to $1. The @ in the address matches the
@ in the lhs, but constant strings are not assigned
to positional macros. The tokens in the string
pc1.gonzo.gov match the second $+ and are assigned to
$2. The address is rewritten as $1<@$2>, or
joe<@pc1.gonzo.gov>.
</P>
<H4><A NAME="ch07_ 34">
$: and $@—Altering a Ruleset's Evaluation
</A></H4>
<P>Consider the following rule:
</P>
<!-- CODE SNIP //-->
<PRE>
R$* $: $1 < @ $j > add local domain
</PRE>
<!-- END CODE SNIP //-->
<P>After rewriting an address in the rhs, sendmail tries to match the rewritten address with
the lhs of the current rule. Because $* matches zero or more of anything, what prevents
sendmail from going into an infinite loop on this rule? After all, no matter how the
rhs rewrites the address, it will always match $*.
</P>
<P>The $: preface to the rhs comes to the rescue; it tells
sendmail to evaluate the rule only once.
</P>
<P>Sometimes you might want a ruleset to terminate immediately and return the address to
the calling ruleset or the next ruleset in
sendmail's built-in sequence. Prefacing a rule's
rhs with $@ causes sendmail to exit the ruleset immediately after rewriting the address in the
rhs.
</P>
<A NAME="PAGENUM-120"><P>Page 120</P></A>
<H4><A NAME="ch07_ 35">
$>—Calling Another Ruleset
</A></H4>
<P>A ruleset can pass an address to another ruleset by using the
$> preface to the rhs. Consider the following rule:
</P>
<!-- CODE SNIP //-->
<PRE>
R$* $: $>66 $1 call ruleset 66
</PRE>
<!-- END CODE SNIP //-->
<P>The lhs $* matches zero or more of anything, so
sendmail always does the rhs. As you learned in the preceding section, the
$: prevents the rule from being evaluated more than once.
$>66 $1 calls ruleset 66 with $1 as its input address. Because
$1 matches whatever was in the lhs, this rule simply passes the entirety of the current input address to ruleset 66.
Whatever ruleset 66 returns is passed to the next rule in the ruleset.
</P>
<H4><A NAME="ch07_ 36">
Testing Rules and Rulesets—The -bt, -d, and
-C Options
</A></H4>
<P>Debugging sendmail.cf can be a tricky business. Fortunately,
sendmail provides several ways to test rulesets before you install them.
</P>
<CENTER>
<TABLE BGCOLOR="#FFFF99">
<TR><TD><B>
NOTE
</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
The examples in this section assume that you have a working
sendmail. If your system does not, try running these examples again after you have installed V8
sendmail.
</BLOCKQUOTE></TD></TR>
</TABLE></CENTER>
<P>The -bt option tells sendmail to enter its rule-testing mode:
</P>
<!-- CODE SNIP //--><PRE>
$ sendmail -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
>
<!-- END CODE SNIP //-->
</PRE>
<BR>
<CENTER>
<TABLE BGCOLOR="#FFFF99">
<TR><TD><B>
NOTE
</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
Notice the warning ruleset 3 NOT automatically
invoked. Older versions of sendmail ran ruleset 3 automatically when in address test mode, which made sense
because sendmail sends all addresses through ruleset 3 anyway. V8
sendmail does not, but invoking ruleset 3 manually is a good idea because later rulesets expect the address to
be in canonical form.
</BLOCKQUOTE></TD></TR>
</TABLE></CENTER>
</P>
<P>The > prompt means sendmail is waiting for you to enter one or more ruleset numbers,
separated by commas, and an address. Try your login name with rulesets 3 and 0. The result
should look something like this:
</P>
<!-- CODE SNIP //-->
<PRE>
> 3,0 joe
rewrite: ruleset 3 input: joe
rewrite: ruleset 3 returns: joe
rewrite: ruleset 0 input: joe
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-121"><P>Page 121</P></A>
<!-- CODE //-->
<PRE>
rewrite: ruleset 3 input: joe
rewrite: ruleset 3 returns: joe
rewrite: ruleset 6 input: joe
rewrite: ruleset 6 returns: joe
rewrite: ruleset 0 returns: $# local $: joe
>
</PRE>
<!-- END CODE //-->
<P>The output shows how sendmail processes the input address
joe in each ruleset. Each line of output is identified with the number of the ruleset processing it, the input address, and
the address that the ruleset returns. The > is a second prompt indicating that
sendmail is waiting for another line of input. When you're done testing, just press Ctrl+D.
</P>
<P>Indentation and blank lines better show the flow of processing in this example:
</P>
<!-- CODE //-->
<PRE>
rewrite: ruleset 3 input: joe
rewrite: ruleset 3 returns: joe
rewrite: ruleset 0 input: joe
rewrite: ruleset 3 input: joe
rewrite: ruleset 3 returns: joe
rewrite: ruleset 6 input: joe
rewrite: ruleset 6 returns: joe
rewrite: ruleset 0 returns: $# local $: joe
</PRE>
<!-- END CODE //-->
<P>The rulesets called were 3 and 0, in that order. Ruleset 3 was processed and returned the
value joe, and then sendmail called ruleset 0. Ruleset 0 called ruleset 3 again and then ruleset 6,
an example of how a ruleset can call another one by using
$>. Neither ruleset 3 nor ruleset 6 rewrote the input address. Finally, ruleset 0 resolved to a mailer, as it must.
</P>
<P>Often you need more detail than -bt provides—usually just before you tear out a large
handful of hair because you don't understand why an address doesn't match the
lhs of a rule. You can remain hirsute because
sendmail has verbose debugging built in to most of its code.
</P>
<P>You use the -d option to turn on sendmail's verbose debugging. This option is followed by
a numeric code that tells which section of debugging code to turn on and at what level.
The following example shows how to run sendmail in one of its debugging modes and the
output it produces:
</P>
<!-- CODE //-->
<PRE>
$ sendmail -bt -d21.12
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
> 3,0 joe
rewrite: ruleset 3 input: joe
--trying rule: $* < > $*
-- rule fails
--trying rule: $* < $* < $* < $+ > $* > $* > $*
-- rule fails
[etc.]
</PRE>
<!-- END CODE //-->
<P><CENTER>
<a href="0116-0118.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0122-0124.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -