The sendmail Configuration File

The file that defines the sendmail runtime configuration is, which is a large, complex file that is divided into seven different sections. The file is so large and so complex that system administrators are often intimidated by it. You needn't be. The file is designed to be easily parsed by sendmail, not to be easily written by a system administrator. But normally, you don't directly write to this file. Instead, you build the file with the m4 commands described later in this chapter. It is important to have a basic understanding of the syntax and structure of the file in order to better understand the effect of the m4 commands and to gain the mastery needed for troubleshooting. Yet it is equally important to realize that you don't have to build the file by hand.

The section labels from the Red Hat file provide an overview of the structure and the function of the file. The sections, each examined in detail in this chapter, are as follows:

Local Info This section defines the configuration information specific to the local host.

Options This section sets the options that define the sendmail environment.

Message Precedence This section defines the sendmail message precedence values.

Trusted Users This section defines the users who are allowed to change the sender address when they are sending mail.

Format of Headers This section defines the headers that sendmail inserts into mail.

Rewriting Rules This section holds the commands that rewrite e-mail addresses from user mail programs into the form required by the mail-delivery programs.

Mailer Definitions This section defines the programs used to deliver the mail. The rewrite rules used by the mailers are also defined in this section.

Note All Linux files have the same structure because they are all created from the m4 macros (covered later in this chapter and in Appendix C, "The M4 Macros for Sendmail") that come in the sendmail distribution. The Local Info Section

Local Info, the first section in the file, contains the hostname, the names of any mail relay hosts, and the mail domain. It also contains the name that sendmail uses to identify itself when it returns error messages, as well as the version number of the file.

The local information is defined by D commands that define macros, C commands that define class values, F commands that load class values from files, and K commands that define databases of information. Some sample lines lifted from the Local Info section of the Red Hat file are shown in Listing 5.2. The commands have been reordered, and a comment has been added to make the commands more understandable, but the commands themselves are just as they appear in the original file.

Listing 5.2: Sample of the Local Info Section

# my name for error messages DnMAILER-DAEMON

# operators that cannot be in local usernames CO @ % !

# host name aliases for this system Cwlocalhost

# file containing names of hosts for which we receive email Fw/etc/mail/local-host-names

# Access list database (for spam stomping) Kaccess hash -o /etc/mail/access.db

Lines that begin with # are comments. The first real command in the sample is a define macro (D) command that defines the username that sendmail uses when sending error messages. The macro being defined is n. Many macro names are only a single upper- or lowercase character. When a long name is used, the name is enclosed in curly braces, for example, {verify}.

The value assigned to n is MAILER-DAEMON. After a value is stored in a macro, it can be recalled later in the configuration using the syntax $x, where x is the name of the macro. Thus, commands later in the configuration that need to send error messages can use $n to retrieve the correct sender name. Setting a macro value once at the beginning of the configuration affects commands throughout the configuration, which simplifies customization.

The first class command (C) assigns the values @, %, and ! to the class variable O. These three values are characters that cannot be used in local usernames because they would screw up e-mail. A class is an array of values. Classes are used in pattern-matching to check whether or not a values matches one of the values in a class, using the syntax $=x, where x is the name of the class. A command containing the string $=O is testing a value to see if it is equal to @, % or !.

The second C command stores the string localhost into the class variable w, which holds a list of valid hostnames for which the local computer will accept mail. Normally, if a system running sendmail receives mail addressed to another hostname, it assumes that the mail belongs to that host. If your system should accept the mail, even if it appears to be addressed to another host, the name of that other host should be stored in class w. Listing 5.2 stores only one value in w. You could add additional hostnames, separated by spaces, directly to the C command line, but there is an easier way to add values to a class variable.

The file command (F) adds the values found in the file /etc/mail/local-host-names to the class w variable. F is the command, w is the name of the class variable, and /etc/mail/local-host-names is the path of the file that is to be stored in the variable. External files and databases make it possible to control sendmail's behavior without directly modifying the sendmail configuration. Flat files such as local-host-names are only part of the story. sendmail also uses structured database files.

The last command in Listing 5.2 defines an e-mail address database. The K command declares a database named "access." The database is in the hash format, which is a standard Unix database format. The file that contains the database is /etc/mail/access.db. All of this information (the internal name, the database type, and the file that holds the database) is defined by the K command. Subsequent commands in the file use the database to match patterns, to retrieve values, and to perform security checks. How databases are used is covered in detail in Chapter 11, when the access database is used to control mail relaying and delivery.

These four types of commands illustrate everything that is done in the Local Info section of the file. This section is the most important section of the file from the standpoint of a system administrator trying to understand a configuration because it is the part of the file that stores the variables used to customize the configuration.

Was this article helpful?

0 0

Post a comment