The K Configuration Command
The K configuration command is used to associate a symbolic name with a database file. The symbolic name will later be used in the RHS of rules. The form of the K command looks like this:
Kname class args
The name is the symbolic name. The class is the kind of database to use (see "The class"). The args specifies the location and properties of the database file (see "The args"). We describe each in turn.
The name
The name portion of the K configuration command immediately follows the K. Whitespace between the K and the name is optional.
Kname class argsoptional whitespace
The name must begin with a letter or digit and may contain only letters, digits, and the underscore character. For example:
K local_hostsgood K $andCents
bad
If you begin a name with a bad character, the following error will be printed and that K line will be ignored:
configfile: linenum: readcf: config K line: no map name
If a bad character appears in the middle of a name, the part preceding the bad character will be taken as the name, and the part following the bad character will be taken as the class. For example, the name me@home will produce this error:
configfile: linenum: readcf: map me: class home not available
The case of the letters in name does not matter. All names are converted to lowercase before they are stored.
The class
Recall that the class portion of the K configuration command follows the name:
Kname class args
Note that whitespace between the name and the class may be a joined indented line, which allows commenting and improves readability:
Kname# Why this nameclass# Why this classargs# and so on
The class is the database type. It must be one of the classes listed in Table 33.3.
| Class | Version | Description | |
|---|---|---|---|
| btree | and above | Berkeley's db form of database | |
| bestmx | bestmx | and above | Look up the best MX record for a host |
| dbm | and above | Really ndbm supplied with most versions of UNIX | |
| dequote | dequote | and above | A pseudo map for removing quotation marks |
| hash | hash | and above | Berkeley's db form of database |
| hesiod | and above | MIT network user authentication services | |
| host | "$[ and $]: A Special Case" | and above | Internal table to store and look up hostnames |
| implicit | implicit | and above | Search for an aliases database file |
| ldapx | and above | The Lightweight Directory Access Protocol | |
| netinfo | and above | NeXT Computers network information services | |
| nis | and above | Sun's Network Information Services (NIS) | |
| nisplus | and above | Sun's newer Network Information Services (NIS+) | |
| null | null | and above | Provide a never found service |
| program | program | and above | Run an external program to look up the key |
| sequence | sequence | and above | Search a series of maps |
| stab | stab | and above | Internally load aliases into the symbol table |
| switch | switch | and above | Internal hook to auto-build sequences |
| text | text | and above | Look up in flat text files |
| userdb | userdb | and above | Look up in the User Database |
| user | user | and above | Look up local passwd information |
All of these classes are described in "Alphabetized Reference" at the end of this chapter. If the class is not one of those listed, or if support for the class was not compiled in, the following error is printed and the K command is ignored:
configfile: linenum: readcf: map mehome: class badclass not available
The case of the class is ignored by sendmail. That is, hash, Hash, and HASH are all the same.
The args
The args of the K configuration command follow symbolic name and class type:
Kname class args
The args specify (among other things) the location of the database file or the name of a network map. The args is like a miniature command line, and its general form looks like this:
switches file_or_map
The switches are letters prefixed with a - character that modify the use of the database. (We'll discuss them in the next section.) The file_or_map is the location of the database file or the name of a network map. The file_or_map should exclude the pag and dir suffixes for dbm class files and exclude the db suffix for hash or btree class files.
A database or map is opened for reading when the configuration file is processed. If the file cannot be opened (and the -o is omitted; see "-o the database file is optional (V8.1 and above)"), an appropriate error is printed. The file_or_map should be an absolute pathname of a file (such as /etc/uuhosts) or a literal network map name (such as hosts.byname). An nis map specification can include a domain:
map@domain
Relative filenames (names that omit a leading /) are interpreted as relative to the current directory of the process that invoked sendmail and should never be used.
The switches
The switches must follow the class and precede the file_or_map:
Kname class switches file_or_map
If any switches follow file_or_map, they are silently ignored. [3] All switches begin with a - character and are listed in Table 33.4.
[3] This is true as of version 8.8.4. Future versions may change the semantics of the
Kline such that switches may follow.
| Switch | Version | Description | |
|---|---|---|---|
-A
| "-A append values for duplicate keys (V8.7 and above)" | and above | Append values for duplicate keys |
-a
| "-a append tag on successful match (V8.1 and above)" | and above | Append tag on successful match |
-f
| "-f don't fold keys to lowercase (V8.1 and above)" | and above | Don't fold keys to lowercase |
-k
| "-k specify column for key (V8.7 and above)" | and above | Specify column for key |
-m
| "-m suppress replacement on match (V8.1 and above)" | and above | Suppress replacement on match |
-N
| and above | Append a null byte to all keys | |
-O
| "-O adaptive versus never add a null (V8.2 and above)" | and above | Adaptive versus never add a null |
-o
| and above | The database file is optional | |
-q
| "-q don't strip quotes from key (V8.7 and above)" | and above | Don't strip quotes from key |
-s
| "-s space replacement character (V8.7 and above)" | and above | Space replacement character |
-v
| "-v specify the value's column (V8.7 and above)" | and above | Specify the value's column |
-z
| "-z specify the column delimiter (V8.7 and above)" | and above | Specify the column delimiter |
If a switch other than those listed is specified, that switch is silently ignored.
Not all switches work with all classes. Some classes use many switches; others use none. The switches that are used by each class are shown in Table 33.5.
| Class | Switches |
|---|---|
| btree | -A -a -f -m -N -O -o -q
|
| bestmx | -a -q
|
| dbm | -A -a -f -m -N -O -o -q
|
| dequote | -a -s
|
| hash | -A -a -f -m -N -O -o -q
|
| hesiod | -a -m -o -q
|
| host | -a -m -q
|
| implicit | -q
|
| ldapx | -a -f -m -N -O -o -q
|
| netinfo | -a -k -m -q -v
|
| nisplus | -a -f -k -m -o -q -v -z
|
| nis | -a -f -m -o -q
|
| null | |
| program | -a -m -o -q
|
| sequence | |
| stab | -q
|
| switch | -q
|
| text | -a -f -k -m -o -q -v -z
|
| userdb | -a -f -m -q
|
| user | -a -m -q -v |
Some classes of databases use special switches that are not available to the broad class of databases. Others redefine the meaning of some switches. These special switches are shown in Table 33.6. Future versions of sendmail may be changed in such a way that it may be possible to have only one list.
| Switch | Class or Vendor | Description |
|---|---|---|
-b
| ldapx | Base from which to begin the search |
-d
| Sun | Use domain wide information (see "K Command's -d switch") |
-h
| ldapx | Host that serves this network database |
-l
| ldapx | Time limit to timeout connection |
-n
| ldapx | Retrieve attribute names only, not values |
-p
| ldapx | Port to use when connecting to host |
-R
| ldapx | Don't auto chase referrals |
-s
| ldapx | Search scope of "base," "one," or "sub" |
-A append values for duplicate keys (V8.7 and above)
Ordinarily, when sendmail builds (rebuilds) an aliases database, it objects to duplicate keys on the left of the colon:
staff: bill staff: leopoldthis is an error
But sometimes, in automating for example, such duplicates are necessary. In such instances, the -A switch can be used with the AliasFile (A) option (see AliasFile (A)) to cause duplicates to be silently appended:
staff: bill staff: leopold silently modified by sendmail to internally become staff: bill, leopold
Note that this process is further illustrated in "Duplicate Entries and Automation".
The -A database switch is useful only with alias files, because those are the only files that sendmail rebuilds on its own.
-a append tag on successful match (V8.1 and above)
When a key is looked up in a database (from inside the $( and $) operators of the RHS of rules), a successfully found key is replaced by its data. If the -a switch is given, the text following that switch, up to the first delimiting whitespace character, is appended to the replacement data. For example:
-a appends nothing -a. appends . -a,MAGICTOKEN appends ,MAGICTOKEN
The text to be appended is taken literally. Quotation marks and backslashed characters are included without interpretation, so whitespace cannot be included in that text. Because the rewritten RHS is normalized as an address, special address expressions (such as parentheses) should be avoided. The use of appended text is one of two methods used for recognizing a successful lookup in rules. We'll discuss the other, $:, in "Specify a Default with $:".
-f don't fold keys to lowercase (V8.1 and above)
Ordinarily, sendmail will normalize a key to lowercase before looking it up in the database. If the keys in the database are case-sensitive ("TEX" is considered different from "tex," for example), the -f switch should be used to prevent this normalization. Note that if the -f switch is omitted (the default), the database must have been created with all lowercase keys (also the default).
-k specify column for key (V8.7 and above)
Beginning with V8.7, sendmail began to support a flat text-file form of database. The /etc/hosts file is an example of such a flat file, in that it is organized in a line-by-line manner:
here.our.domain
When such files are read as databases (with the text class; see ), you need to specify which column is the key and which is the value.
For nisplus and netinfo maps, the -k switch specifies the name (text) of the desired column.
When the -k switch specifies which column is the key, its absence defaults to 0 for the text class and to the name of the zeroth column for the nisplus class. Note that the numbered columns are indexed beginning with 0 for the first and 1 for the second. See also -v (see ) for the value's column (text and nisplus only) and -z (see ) for the column delimiter (text only).
-m suppress replacement on match (V8.1 and above)
Ordinarily, a successful lookup in a database or map causes the key to be replaced by its value. When the intention is to merely verify that the key exists (not replace it), the -m switch can be used to suppress replacement. For example, the values that are returned from the hosts.byname NIS map are not generally useful (they contain multiple hostnames). In looking up a key in this map (with $( and $); see ), the -m switch prevents those multiple names from wrongly replacing the single hostname in the key. Note that the -a (see ) can still be used to append a suffix to a successful lookup. Also, the $:default (see ) is still used if the lookup fails.
-N append a null byte to all keys (V8.1 and above)
If a database was created with makemap's -N switch (see ) to include the terminating zero byte with each key, this K configuration command -N switch may be specified to force all lookups to also include a zero byte. Note that -N is not needed for the nis class and, if included, is ignored. See also -O below.
-O adaptive versus never add a null (V8.2 and above)
If neither -N nor -O is specified, sendmail uses an adaptive algorithm to decide whether or not to look for the terminating zero byte. The algorithm starts by accepting either. If the first key looked up is found to end with a terminating zero byte, the algorithm will thereafter look only for keys with terminating zero bytes. If the first key that is looked up is found to not end with a terminating zero byte, the algorithm will thereafter look only for keys without terminating zero bytes.
If this -O switch is specified, sendmail never tries a zero byte, which can speed matches. Note that if both -N and -O are specified, sendmail will never try to match at all, thus causing all lookups to appear to fail.
-o the database file is optional (V8.1 and above)
Ordinarily, sendmail will complain if a database file cannot be opened for reading. If the presence of a database file is optional (as it may be on certain machines), the -o switch should be used to tell sendmail that the database is optional. Note that if a database is optional and cannot be opened, all lookups will silently fail for rules that use that database.
-q don't strip quotes from key (V8.7 and above)
Ordinarily, sendmail strips all the nonescaped quotation marks (those not prefixed with a backslash) from a key before looking it up. For example, the following key:
"Bob \"bigboy\" Roberts \(esq\)"@bob.com
will have its nonescaped quotation marks removed to end up like this:
Bob "bigboy" Roberts (esq)@bob.com
Note that all escaped characters are de-escaped (have the backslash removed) during this process.
When quotation marks and escaped characters need to be preserved in a key before it is looked up, you can use the -q switch with the K configuration command. The -q switch suppresses dequoting and de-escaping.
-s space replacement character (V8.7 and above)
The dequote class (see ) refuses to remove quotation marks if doing so will result in an illegal address. For example, internal space characters are illegal in addresses:
"a b" becomes"a b"
The -s switch causes all the quoted space characters to be changed into a character that you specify just before the dequoting process.
Kdequote dequote -s+
Here, we specify that quoted strings will have quoted spaces converted into a plus before dequoting. Therefore, the above conversion becomes the following:
"a b" becomesa+b
The -s switch is only of use with the dequote class. Note that the lpadx class uses the -s switch differently (see Table 33.6 in "The switches").
-v specify the value's column (V8.7 and above)
The manner in which the key and its value are visually displayed in flat, sequential, text files and certain network services, may not be directly suitable for use in maps. A text class file, for example /etc/hosts, may display the key on the right and the value on the left:
here.our.domain
For such circumstances the -v switch can be used with the K command to specify the column or item that will be returned as the value when a key is matched. For example:
Kaddr text -k1 -v0 /etc/hosts
For nisplus and netinfo maps, the -v switch specifies the name (text) of the value's column.
This -v switch specifies which column is the value to return. If it is omitted, it defaults to 0 for the text class and to the last named column for the nisplus class. Note that text columns are indexed beginning with 0 for the first and 1 for the second. See also -k (see ) for the key's column and -z (see ) for the column delimiter.
-z specify the column delimiter (V8.7 and above)
Flat, sequential text files have columns of information delimited from each other with a variety of characters:
here.our.domain/etc/hosts uses a whitespace nobody:*:65534:65534::/:
/etc/passwd uses a colon
The -z switch can be used to specify a delimiter whenever the default delimiter of whitespace is not appropriate. In the case of the /etc/passwd file, a database declaration might look like this:
Kuid text -z: -k2 -v0 /etc/passwd # map to convert uid to login name
The default is whitespace for the text class. It is a comma for the netinfo class.
optional whitespace
good K $andCents
"a b"