=for comment $Id: aliascheck.pod,v 1.6 2005/07/08 04:16:03 dm Exp $
=head1 NAME
aliascheck - check for existence of mail alias
=head1 SYNOPSIS
aliascheck [--nopwd] I<name> [I<alias-file>]
aliascheck --qmail [--nopwd] I<name> [I<alias-user>]
=head1 DESCRIPTION
aliascheck checks whether I<name> is a valid email alias or a user in
the password file. It converts I<name> to lower-case before
performing any of the checks. If the alias or user exists, aliascheck
exits with status 0 and outputs what the address resolves to. If the
alias does not exist, aliascheck exits with status 1. If aliascheck
cannot determine the validity of I<name> because of some system error,
it exits with status 2.
aliascheck can run in two different modes--sendmail mode and qmail
mode. In sendmail mode the second argument, I<alias-file>, is the
name of the sendmail alias file, typically F</etc/mail/aliases.db>.
If no second argument is supplied, aliascheck first checks for the
existence of F</etc/mail/aliases.db>, then for the existence of
F</etc/aliases.db>, then finally exits with status 2 if neither file
exists. When an alias is found, aliascheck outputs the value of that
alias in the alias database.
When aliascheck is given the argument B<--qmail>, it runs in qmail
mode. In this case, the second argument, I<alias-user>, specifies the
user under which qmail processes mail aliases. aliascheck will check
this user's home directory for files named F<.qmail-XXX> for various
appropriate suffixes F<XXX>. On success, it outputs the full pathname
of the appropriate file.
If aliascheck cannot find an alias, it also checks the password file,
and exits 0 if it can find I<name> there. If I<name> is found,
aliascheck also outputs I<name> (in lower-case) to standard output
before exiting. (This is useful for Mail Avenger, because asmtpd does
not recognize users with invalid shells or UID 0, while MTAs typically
do.) To suppress password file checking, supply the B<--nopwd>
argument to aliascheck.
=head1 EXAMPLES
If you are using Mail Avenger in conjunction with a sendmail
installation, you might want to put the following code in your
F<@etcdir@/unknown> file to reject mail for unknown users who do not
show up in the alias file.
aliascheck "$RECIPIENT_LOCAL" /etc/mail/aliases.db > /dev/null
case "$?" in
0)
# Fall through to default checks
;;
1)
reject unknown user
;;
*)
# Probably safest to do nothing, but could also
# defer the mail with the following command:
#
#defer Temporary error processing alias file
;;
esac
If you have qmail instead of sendmail, assuming the qmail I<alias>
user is called C<alias>, you would change the first line in the
previous example to:
aliascheck --qmail "$RECIPIENT_LOCAL" alias > /dev/null
=head1 FILES
=over
=item F<@etcdir@/unknown>
Mail Avenger rules for local email addresses that do not correspond to
local users, or correspond to local users without valid shells, or
local users with uid 0 (i.e., root). Note the location may be
different if you set B<EtcDir> in your F<asmtpd.conf> file.
=item F</etc/mail/aliases.db>
=item F</etc/aliases.db>
Default locations of sendmail alias file
=item F<~alias/.qmail-*>
Default locations of qmail alias files
=item F</etc/password>
System password file. (Note, however, that aliascheck uses the
I<getpwnam> function, and will thus be compatible with schemes such as
NIS that do not keep all users in the local password file.)
=back
=head1 SEE ALSO
L<avenger(1)|avenger(1)>,
L<asmtpd.conf(5)|asmtpd.conf(5)>,
The Mail Avenger home page: L<http://www.mailavenger.org/>.
=head1 BUGS
aliascheck doesn't necessarily know how to parse the particular
database format your sendmail installation uses for aliases. Make
sure you test it before using it in an avenger script.
In some sendmail installations, the alias database is not world
readable, which can obviously prevent aliascheck from working properly
if run under the wrong user identity (such as the B<AvengerUser>).
It is quite possible for aliascheck to return a system error (exit
code 2), particularly if you run it while you are rebuilding a large
alias database. (aliascheck checks for the existence of special key
C<@> in the database.) Make sure you differentiate between error code
1 (no user) and error code 2 (system error).
aliascheck may not do the right thing if you installed qmail with
F<conf-break> set to a character other than C<->.
Remember that aliascheck does not read your qmail F<users/assign> or
F<users/cdb> files--it only checks for F<.qmail> files in the alias
user's home directory.
=head1 AUTHOR
David MaziE<egrave>res
syntax highlighted by Code2HTML, v. 0.9.1