Testing Your New Configuration

Test whether or not the change made to macro M in the configuration files modifies the rewrite process by directly testing the rewrite rulesets. First, you need to find out what rules are used to rewrite the address.

Use your knowledge of the flow of rulesets from Figure 5.1 to determine which rulesets to test. You know that the ruleset canonify is applied to all addresses. It is followed by different rulesets, depending on whether the address is a delivery address, a sender address, or a recipient address. Furthermore, the rulesets used for sender and recipient addresses vary, depending on the mailer that is used to deliver the mail. All addresses are then processed by ruleset final.

There are two variables that determine the rulesets used to process an address: the type of address and the mailer through which it is processed. The three address types are delivery address, recipient address, and sender address. You know the address type because you select the address being tested. In the example, the concern is the sender address.

There are two types of sender addresses: the sender address in the message header and the sender address in the "envelope." The message header address is the one on the From line sent with the mail. You probably see it in the mail headers when you view the message with your mail reader. The "envelope" address is the address used during the SMTP protocol interactions. The one that we're interested in is the one that remote users see in the mail—the header address.

Locating the Correct Mailer

The other variable that determines the rulesets used to process an address is the mailer. To find out which mailer delivers the mail, run sendmail with the -bv argument:

#$ sendmail -bv [email protected]

[email protected]... deliverable: mailer esmtp, host wrotethebook.com., user [email protected]

To see which mailer is used to deliver mail to remote sites, run sendmail with the -bv argument, and give it a valid e-mail address for the remote site. In the example, the address is [email protected]. sendmail displays the mail delivery triple returned by ruleset parse: the mailer, the host, and the user. From this, you know that the mailer is esmtp.

Testing How Addresses Are Rewritten

To test the new configuration, run sendmail with the -bt option. sendmail displays a welcome message, and waits for you to enter a test. A simple test is a list of ruleset names followed by an e-mail address. For example, entering canonify,parse craig at the prompt would process the e-mail address craig through the rulesets canonify and then parse. This should provide you with the mailer, host, user delivery triple for the address.

Because you know the mailer that you want to test, you can use the /try command at the prompt to process the sender From address for the smtp mailer. The example in Listing 5.6 illustrates the test. First, test the existing configuration to see how the address is processed by the default configuration.

Listing 5.6: Testing the Default sendmail Configuration

# sendmail -bt

ADDRESS TEST MODE (ruleset 3 NOT automatically invoked) Enter <ruleset> <address>

> /tryflags HS

> /try smtp craig

Trying header sender canonify Canonify2 Canonify2 canonify 1 1

HdrFromSMTP

PseudoToReal

PseudoToReal

MasqSMTP

MasqSMTP

MasqHdr

MasqHdr

HdrFromSMTP

final final

Rcode = 0, > /quit input input returns returns input returns input input returns input returns input returns returns input returns address craig craig craig craig craig craig craig craig craig craig craig craig craig craig craig craig for mailer esmtp

. foobirds . foobirds . foobirds foobirds .

. org . org . org org addr = [email protected]

Run sendmail —bt, which starts sendmail in test mode with the default configuration. Listing 5.6 shows exactly how the standard configuration processes e-mail addresses. Specifically, it shows how local sender addresses are rewritten for outbound mail.

The /tryflags command defines the type of address to be processed. Four flags are available: S for sender, R for recipient, H for header, and E for envelope. By combining two of these flags, the /tryflags command tells sendmail to process a header sender (HS) address.

The /try command tells sendmail to process the e-mail address craig through the mailer esmtp. The address returned by ruleset final, which is always the last ruleset to process an address, shows the address used on outbound mail after all of the rulesets have processed the address. With the default configuration, the input address craig is converted to [email protected].

Next, run sendmail -bt with the -C option to use the newly created test.cf configuration file. The -C option permits you to specify the sendmail configuration file on the command line. Listing 5.7 shows this test.

Listing 5.7: Testing sendmail Masquerading

# sendmail -bt -Ctest.cf

ADDRESS TEST MODE (ruleset 3 NOT automatically invoked) Enter <ruleset> <address>

> /tryflags HS

> /try smtp craig

Trying header sender address craig for mailer esmtp

canonify

input:

craig

Canonify2

input:

craig

Canonify2

returns:

craig

canonify

returns:

craig

1

input:

craig

1

returns:

craig

HdrFromSMTP

input:

craig

PseudoToReal

input:

craig

PseudoToReal

returns:

craig

MasqSMTP

input:

craig

MasqSMTP

returns:

craig

<

@ *LOCAL* >

MasqHdr

input:

craig

<

@ *LOCAL* >

MasqHdr

returns:

craig

<

@ foobirds

. org .

>

HdrFromSMTP

returns:

craig

<

@ foobirds

. org .

>

final

input:

craig

<

@ foobirds

. org .

>

final

returns:

craig

@

foobirds .

org

Rcode = 0, addr = [email protected] > /quit

Rcode = 0, addr = [email protected] > /quit

Running sendmail -bt -Ctest.cf starts sendmail in test mode, and tells it to use the new configuration that is stored in test.cf. The test in Listing 5.7 shows that the value entered in the M macro is used to rewrite the sender address in the message header. You know this because the address returned from ruleset final is now [email protected], which is just what you want.

Run additional tests (for example, /try esmtp [email protected]) to see if client addresses are rewritten correctly. When you're confident that the configuration is correct and reliable, move the test.cf configuration file to sendmail.cf to make the new configuration available to sendmail.

If you are called upon to help someone configure sendmail on a system that doesn't already have the m4 source file installed, it may be easier to directly edit the sendmail.cf file, but only if the change is very small. If you can avoid it, don't make changes directly to the sendmail.cf file. If you really want to make major sendmail configuration changes, use m4 to build your configuration.

Was this article helpful?

0 0

Post a comment