home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    


sendmailSearch this book
Previous: 33.1 Enable at Compile Time Chapter 33
Database Macros
Next: 33.3 The K Configuration Command

33.2 Create Files with makemap

The makemap program is supplied in source form with V8 sendmail . It may be supplied in pre-compiled form by your vendor. It is used to create database files and is run from the command line like this:



switches class file

We'll discuss the switches in the next section. The class can be either dbm (which uses the ndbm (3) library routines), hash , or btree (both of which use the db (3) library routines). The file is the location and name (full path or relative name) for the database file to create. For dbm files, the .pag and .dir suffixes are added automatically. For the db files, the .db suffix will be added automatically if it is not already included in the name.

The makemap program reads from its standard input. That input is line oriented and contains the text from which the database files will be created. Lines that begin with a # are interpreted as comments and ignored. Lines that contain no characters  - pty lines) are also ignored. Whitespace (spaces or tabs) separates the key on the left from the data on the right. An example of such an input file is the following:

lady     relaysite!lady
my.host  relaysite!lady
bug      bug.localuucp

The second line above shows that keys may be multitokened ( my.host is three tokens). In reading from existing files, some conversion may be required to massage the input into a usable form. To make a database of the /etc/hosts file (for converting hostnames into IP addresses), for example, a command line like the following might be required:


awk '/^[^#]/ {print $2, $1}' | makemap ...

Here, awk (1) needs to eliminate comment lines (the /^[^#]/ ). Otherwise, it will wrongly move them to the second column, where makemap will not recognize them as comments.

33.2.1 makemap Command-Line Switches

The command-line switches for makemap must precede the class and the file :


switches class file

Switches are single characters, prefixed with a - character. Switches may also be combined:

-N -o      
<- good

<- also good

The complete list of switches is shown in Table 33.2 . (See getopt (3) for additional information about the way switches are handled.)

Table 33.2: makemap Program's Switches
Switch Description
-d Section, "-d allow duplicate keys" Allow duplicate keys
-f Section, "-f don't fold uppercase to lowercase" Don't fold uppercase to lowercase
-N Section, "-N append a null byte to all keys" Append a null byte to all keys
-o Section, "-o append to, don't overwrite the file" Append to, don't overwrite the file
-r Section, "-r replace (silently) duplicate keys" Replace (silently) duplicate keys
-v Section, "-v watch keys and data being added" Watch keys and data being added -d allow duplicate keys

Ordinarily, makemap will complain if two entries have identical keys and refuse to insert the duplicate. But if it is desirable to allow the same key to appear multiple times in the database, you can use the -d switch to suppress those warnings and allow the duplicates to be inserted. But be aware that this switch is allowed only for the btree and hash forms of the db (3) library. Use of this switch with any other form of database will produce the following error:

makemap: Type 
 does not support -d (allow dups)

See the -r switch for a way to cause duplicates to replace originals. -f don't fold uppercase to lowercase

Normally, the key is converted to lowercase before being stored in the database. When the key entries are case-sensitive, the -f switch may be used to prevent conversion to lowercase. When tokens in rule sets are later looked up in the database, you may choose (with the K command) to leave those tokens as is or convert them to lowercase before the comparison to keys. This switch and the K command should parallel each other. -N append a null byte to all keys

The -N switch tells makemap to include a trailing zero byte with each key that it adds to the database. When V8 sendmail looks up a key in the database, it uses a binary comparison. Some databases, such as /etc/aliases under SunOS, append a zero byte to each key. When a trailing zero byte is included with a key, it must also be included with the tokens being looked up, or the lookup will fail. The use of this switch must match the K command (see Section, "-N append a null byte to all keys (V8.1 and above)" ). -o append to, don't overwrite the file

The -o switch causes sendmail to append to a map, rather than overwrite it. Ordinarily, makemap overwrites any existing map with completely new information. The appended information must be all new information (no duplicate keys), unless the -r switch is also used. -r replace (silently) duplicate keys

Ordinarily, it is an error to specify a key that already exists in a map. That is,

john   john@host1
john   john@host2

Here, the second john line produces an error instead of replacing the first with the second. To allow replacement keys, use the -r switch with makemap . Generally, the -r and -o switches should be combined in updating a database with new information. -v watch keys and data being added

To watch your keys and data being added to a database, use the -v switch. This switch causes the following line of output to be produced for each key processed:

', val=`

Note that the trailing zero added by the -N switch is not displayed with the -v output. Also note that verbose output is printed to the standard output, whereas error messages are printed to the standard error output.

Previous: 33.1 Enable at Compile Time sendmail Next: 33.3 The K Configuration Command
33.1 Enable at Compile Time Book Index 33.3 The K Configuration Command