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

sendmail

sendmailSearch this book
Previous: 23.9 The qf File InternalsChapter 24Next: 24.2 Forms of Alias Delivery
 

24. Aliases

Contents:
The aliases(5) File
Forms of Alias Delivery
Write a Delivery Agent Script
Special Aliases
The Aliases Database
Prevent Aliasing with -n
Pitfalls

Aliasing is the replacing of one recipient address with one or more different recipient addresses. The replacement address can be that of a single user, a list of recipients, a program, a file, or any mixture of these. In this chapter we cover the aliases(5) file, one of the three methods of aliasing available with the sendmail program. We cover the other two forms, :include: (for including separate files from within the aliases file) and ~/.forward (the user's personal :include: file) in the next chapter.

Aliasing can be used to handle several complex delivery problems:

All the information that is needed to perform these tasks is contained in the aliases(5) file (which is often also stored in database format to make lookups faster).

24.1 The aliases(5) File

The aliases(5) file is one of several sources that can supply system mail aliases. We describe it first because it is the most traditional and because it illustrates the syntax and limitations common to all techniques.

The aliases(5) file is composed of lines of text. Any line that begins with a # is a comment and is ignored. Empty lines (those that contain only a newline character) are also ignored. Any line that begins with a space or a tab is joined (appended) to the line above it. All other lines of text are viewed as alias lines. The format for an alias line is:

local: alias

The local must begin a line. It is an address in the form of a local recipient address (we will discuss this in more detail soon). The colon follows the local on the same line and may be preceded with spaces or tabs. If the colon is missing, sendmail prints and syslog(3)'s the following error message and skips that alias line:

missing colon

The alias (to the right of the colon) is one or more addresses on the same line. Indented continuation lines are permitted. Each address should be separated from the next by a comma and optional space characters. A typical alias looks like this:

root: jim, sysadmin@server,
      gunther
  -^
  indenting whitespace

Here, root is the local address to be aliased. When mail is to be locally delivered to root, it is looked up in the aliases(5) file. If found, root is replaced with the three addresses shown earlier, and mail is instead delivered to those other three addresses.

This process of looking up and possibly aliasing local recipients is repeated for each recipient until no more aliases are found in the aliases(5) file. That is, for example, if one of the aliases for root is jim and if jim also exists to the left of a colon in the aliases file, he too is replaced with his alias:

jim: jim@otherhost

The list of addresses to the right of the colon may be mail addresses (such as gunther or jim@otherhost), the name of a program to run (such as /etc/relocated), the name of a file onto which to append (such as /usr/share/archive), or the name of a file to read for additional addresses (using :include:). The :include: is used in creating mailing lists and will be covered in the next chapter.

24.1.1 The aliases(5) file's location

The location of the aliases(5) file is specified with the ServiceSwitchFile option (see Section 34.8.61, ServiceSwitchFile) and the AliasFile (A) option (see Section 34.8.1, AliasFile (A)) in the configuration file. Be aware that, since these two options interact, it may not suffice to simply declare one or the other. Also be aware that some systems supply service-switch files that will be used even if the ServiceSwitchFile option is omitted.

Note that the service-switch file merely specifies the order in which various methods should be used to look up aliases, not the specific files. If it lists files as a method:

aliases    files

then all the files declared with the AliasFile option will be looked up in the order in which they were declared:

  • If the AliasFile option specifies a file and if a service-switch file omits the files specification, the AliasFile option is ignored.

  • If the AliasFile option specifies a file and if a service-switch file omits the aliases line, the AliasFile option is used.

  • If the AliasFile option specifies a file and if there is no service-switch file, then the AliasFile option file is used.

  • If the AliasFile option is omitted and if there is no service-switch file or if there is a service-switch file but it omits an aliases line, sendmail silently presumes that it should not do aliasing.

Note that service-switch files and AliasFile (A) option can list other techniques for obtaining aliases in addition to, or instead of, an aliases(5) file. But this can lead to a side effect. For example, if your configuration file declares

O AliasFile=/etc/aliases,nis:

and if the service-switch file aliases line specifies:

aliases    nis files

then sendmail looks up aliases first with nis, then in the /etc/aliases file, then with nis a second time.

24.1.2 Local Must Be Local

The local part of an alias must be in the form of a local recipient. This restriction is enforced each time sendmail reads the aliases(5) file. For every name to the left of a colon that it finds, sendmail performs the following normalization and verification steps.

To begin, sendmail normalizes each address by removing everything but the address part. For example, consider the following two alias lines:

george (George Washington): gw
George Washington <george>: gw

When sendmail reads these lines, it normalizes each into its address part:

george (George Washington)    becomes ->  george
George Washington <george>    becomes ->  george

After the address part is extracted, it is converted to lowercase and rewritten by rule sets 3 and 0 to see whether it causes the local delivery agent to be selected or, beginning with V8.7 sendmail, to see whether it causes any delivery agent with the F=A flag set (see Section 30.8.12, F=A) to be selected.

Here, the address george (after processing) selects a local delivery agent, and so these alias lines are legal. Internally (or in its database), sendmail stores the above alias as

george: gw

When mail arrives that is addressed for delivery to george, sendmail rewrites that address with rule sets 3 and 0. Rule set 0 selects the local delivery agent (or, for V8.7, any agent with F=A set). Only if a local delivery agent is selected for an address does sendmail look up an address in its aliases file. The address george is looked up and replaced with gw. Internally, sendmail marks the recipient george as defunct, having been replaced with an alias, and then adds gw to the list of recipients.

The new recipient, gw, is then processed for delivery. Rule sets 3 and 0 are called once more and again select a local delivery agent. As a consequence, gw is also looked up. If it is found to the left of a colon in the aliases file, it too is replaced with yet another address (or addresses). This process repeats until no new local addresses are found.

The entry george is marked defunct rather than being deleted to detect alias loops. To illustrate, consider the following two mutually referencing aliases:

george: gw
gw: george

The sendmail program first replaces george with gw, marking george as defunct. It goes to mark gw as defunct but notices that a loop has been formed. If sendmail is running in verbose mode (see Section 34.8.76, Verbose), it prints

aliasing/forwarding loop broken

and bounces the message.

Note that aliases can get pretty complex. As a consequence, when one address aliases to many new addresses, this autodetection of loops will fail (but the problem will be caught later with "hop counting"; see Section 34.8.36, MaxHopCount (h)).


Previous: 23.9 The qf File InternalssendmailNext: 24.2 Forms of Alias Delivery
23.9 The qf File InternalsBook Index24.2 Forms of Alias Delivery