24.2 Forms of Alias DeliveryThe right-hand side of an alias entry can take four forms:
The 24.2.1 Delivery to Users
Any address in the list of addresses to the right of the colon that does
not begin with a
If a user address is prefixed
with a backslash character (
24.2.2 Delivery to Files
When any of the addresses to the right of a colon in the alias
list begins with a
R/$+ $@ $#local $: /$1
Beginning with V8.7
sendmail
, any delivery agent for which the
In the list of addresses to the right of the colon,
sendmail
considers
any local address that begins with the
To deliver to a file,
sendmail
first performs
a
fork
(2) and gives the child the task of delivery. The
fork
is necessary so that
sendmail
can change its
effective
uid
and
gid
, as we will show.
The child then performs a
stat
(3)
on the file. If the file exists, its file permissions are saved
for later use.
If it doesn't exist, the saved permissions are defaulted to 0666.
Under V8.7 the decision to use
stat
(2) versus
lstat
(2)
to obtain the permissions is determined by the
If the saved permissions have any execute bit set, the child
exits with EX_CANTCREAT as defined in
<sysexits.h>
.
If the file has a controlling user
associated with it, any
suid
and
sgid
bits are stripped from
the saved permissions.
If the file was listed in a
~/.forward
file, the controlling
user is the owner of the
~/.forward
file. If it was listed in a
Then the queue
mailfile: Cannot open
Here, the
Next, if the
mailfile: Cannot chroot(
Next, whether the
After this,
sendmail
changes its
uid
, using the same rules that it used
for the
gid
except that the last step uses the
The file (and possibly the path to it) is then checked to see whether it
is safe to write to. This is done by using the internal
safefile
() subroutine.
See the If safe, file is then opened for writing in append mode. If sendmail cannot open the file, it prints the following error message, and the child exits with EX_CANTCREAT:
cannot open: reason for error here If an open fails, it is attempted 10 more times (sleeping progressively longer between each try) [3] on the assumption that on busy systems there may be a temporary lack of resources (such as file descriptors). The open includes file locking with flock (2) or fcntl (2) to prevent simultaneous writes.
Once the file is opened, the header and body of the mail message are
written to it.
Note that translations are controlled by the If any write error occurs, sendmail prints the following error message and continues:
I/O error Finally, the file's permissions are restored to those that were saved above, and the file is closed with fclose (3). If the suid or sgid bits were stripped because there was a controlling user, they are restored here. [4] If the file didn't originally exist, its permissions become 0666.
In general, the file form of an alias is a poor way to save mail messages to a file. Instead, the use of a separate program procmail (8) is recommended (see Section 25.7.5.2, "The procmail program" ). 24.2.3 Delivery via Programs
When any of the addresses to the right of a colon in the alias
list begins with a
R|$+ $@ $#local $: |$1
Beginning with V8.7
sendmail
, any delivery agent for which the
The forms that a program address can legally take in the aliases (5) file (or ~/.forward file; see Section 25.7.4, "Piping Through Programs" ) are as follows:
|prg "|prg args" |"prg args"
Here,
To execute the program,
sendmail
executes the command
in the
/bin/sh -c /bin/smrsh -c
These tell
sendmail
to run
/bin/sh
(the Bourne shell)
or
/bin/smrsh
(the
sendmail
restricted shell) to
execute the program specified by
jim: "|/etc/local/relo jim@otherhost" the Bourne shell would be executed with the following command line:
/bin/sh -c "/etc/local/relo jim@otherhost" The result of all this is that sendmail runs the Bourne shell and then the Bourne shell runs the /etc/local/relo program. Mail is delivered under this scheme by attaching the output of sendmail to the standard input of the shell and attaching the standard output and standard error output of the shell to the input of sendmail . The sendmail program simply prints the mail message to the shell and reads any errors that the shell prints in return. Although this process appears to be fairly straightforward, there are many things that can go wrong. Failure usually results in the mail message being bounced. 24.2.3.1 Possible failures
To communicate with the
openmailer: pipe (to mailer) openmailer: pipe (from mailer)
Next,
sendmail
executes a
fork
(2). The child
later becomes the
openmailer: cannot fork In establishing a communications channel, the sendmail child process creates a copy of its standard input file descriptor. This can fail because the system limit on available file descriptors has been exceeded. When this happens, the following message is printed. Note that not all dup (2) failures produce error messages.
Cannot dup to zero!
Finally, the child transforms itself into the
Cannot exec
Failure can be caused by a wide range of problems. If one occurs
and the delivery
agent is
Programs in the
aliases
file are run with the |
|