5
/* Postfix error mail delivery agent
7
/* \fBerror\fR [generic Postfix daemon options]
9
/* The Postfix error delivery agent processes delivery requests from
10
/* the queue manager. Each request specifies a queue file, a sender
11
/* address, a domain or host name that is treated as the reason for
12
/* non-delivery, and recipient information.
13
/* This program expects to be run from the \fBmaster\fR(8) process
16
/* The error delivery agent bounces all recipients in the delivery
17
/* request using the "next-hop"
18
/* domain or host information as the reason for non-delivery, updates
19
/* the queue file and marks recipients as finished or informs the
20
/* queue manager that delivery should be tried again at a later time.
22
/* Delivery status reports are sent to the \fBbounce\fR(8),
23
/* \fBdefer\fR(8) or \fBtrace\fR(8) daemon as appropriate.
27
/* The error mailer is not security-sensitive. It does not talk
28
/* to the network, and can be run chrooted at fixed low privilege.
32
/* Problems and transactions are logged to \fBsyslogd\fR(8).
34
/* Depending on the setting of the \fBnotify_classes\fR parameter,
35
/* the postmaster is notified of bounces and of other trouble.
36
/* CONFIGURATION PARAMETERS
39
/* Changes to \fBmain.cf\fR are picked up automatically as error(8)
40
/* processes run for only a limited amount of time. Use the command
41
/* "\fBpostfix reload\fR" to speed up a change.
43
/* The text below provides only a parameter summary. See
44
/* postconf(5) for more details including examples.
45
/* .IP "\fB2bounce_notice_recipient (postmaster)\fR"
46
/* The recipient of undeliverable mail that cannot be returned to
48
/* .IP "\fBbounce_notice_recipient (postmaster)\fR"
49
/* The recipient of postmaster notifications with the message headers
50
/* of mail that Postfix did not deliver and of SMTP conversation
51
/* transcripts of mail that Postfix did not receive.
52
/* .IP "\fBconfig_directory (see 'postconf -d' output)\fR"
53
/* The default location of the Postfix main.cf and master.cf
54
/* configuration files.
55
/* .IP "\fBdaemon_timeout (18000s)\fR"
56
/* How much time a Postfix daemon process may take to handle a
57
/* request before it is terminated by a built-in watchdog timer.
58
/* .IP "\fBdouble_bounce_sender (double-bounce)\fR"
59
/* The sender address of postmaster notifications that are generated
60
/* by the mail system.
61
/* .IP "\fBipc_timeout (3600s)\fR"
62
/* The time limit for sending or receiving information over an internal
63
/* communication channel.
64
/* .IP "\fBmax_idle (100s)\fR"
65
/* The maximum amount of time that an idle Postfix daemon process
66
/* waits for the next service request before exiting.
67
/* .IP "\fBmax_use (100)\fR"
68
/* The maximal number of connection requests before a Postfix daemon
69
/* process terminates.
70
/* .IP "\fBnotify_classes (resource, software)\fR"
71
/* The list of error classes that are reported to the postmaster.
72
/* .IP "\fBprocess_id (read-only)\fR"
73
/* The process ID of a Postfix command or daemon process.
74
/* .IP "\fBprocess_name (read-only)\fR"
75
/* The process name of a Postfix command or daemon process.
76
/* .IP "\fBqueue_directory (see 'postconf -d' output)\fR"
77
/* The location of the Postfix top-level queue directory.
78
/* .IP "\fBsyslog_facility (mail)\fR"
79
/* The syslog facility of Postfix logging.
80
/* .IP "\fBsyslog_name (postfix)\fR"
81
/* The mail system name that is prepended to the process name in syslog
82
/* records, so that "smtpd" becomes, for example, "postfix/smtpd".
84
/* qmgr(8), queue manager
85
/* bounce(8), delivery status reports
86
/* postconf(5), configuration parameters
87
/* master(8), process manager
88
/* syslogd(8), system logging
92
/* The Secure Mailer license must be distributed with this software.
95
/* IBM T.J. Watson Research
97
/* Yorktown Heights, NY 10598, USA
100
/* System library. */
102
#include <sys_defs.h>
106
/* Utility library. */
111
/* Global library. */
113
#include <deliver_request.h>
114
#include <mail_queue.h>
116
#include <deliver_completed.h>
117
#include <flush_clnt.h>
119
/* Single server skeleton. */
121
#include <mail_server.h>
123
/* deliver_message - deliver message with extreme prejudice */
125
static int deliver_message(DELIVER_REQUEST *request)
127
char *myname = "deliver_message";
135
msg_info("deliver_message: from %s", request->sender);
140
if (request->nexthop[0] == 0)
141
msg_fatal("empty nexthop hostname");
142
if (request->rcpt_list.len <= 0)
143
msg_fatal("recipient count: %d", request->rcpt_list.len);
146
* Open the queue file. Opening the file can fail for a variety of
147
* reasons, such as the system running out of resources. Instead of
148
* throwing away mail, we're raising a fatal error which forces the mail
149
* system to back off, and retry later.
151
src = mail_queue_open(request->queue_name, request->queue_id,
154
msg_fatal("%s: open %s %s: %m", myname,
155
request->queue_name, request->queue_id);
157
msg_info("%s: file %s", myname, VSTREAM_PATH(src));
160
* Bounce all recipients.
162
#define BOUNCE_FLAGS(request) DEL_REQ_TRACE_FLAGS(request->flags)
164
for (nrcpt = 0; nrcpt < request->rcpt_list.len; nrcpt++) {
165
rcpt = request->rcpt_list.info + nrcpt;
166
if (rcpt->offset >= 0) {
167
status = bounce_append(BOUNCE_FLAGS(request), request->queue_id,
168
rcpt->orig_addr, rcpt->address,
169
rcpt->offset, "none", request->arrival_time,
170
"%s", request->nexthop);
172
deliver_completed(src, rcpt->offset);
180
if (vstream_fclose(src))
181
msg_warn("close %s %s: %m", request->queue_name, request->queue_id);
186
/* error_service - perform service for client */
188
static void error_service(VSTREAM *client_stream, char *unused_service, char **argv)
190
DELIVER_REQUEST *request;
194
* Sanity check. This service takes no command-line arguments.
197
msg_fatal("unexpected command-line argument: %s", argv[0]);
200
* This routine runs whenever a client connects to the UNIX-domain socket
201
* dedicated to the error mailer. What we see below is a little protocol
202
* to (1) tell the queue manager that we are ready, (2) read a request
203
* from the queue manager, and (3) report the completion status of that
204
* request. All connection-management stuff is handled by the common code
205
* in single_server.c.
207
if ((request = deliver_request_read(client_stream)) != 0) {
208
status = deliver_message(request);
209
deliver_request_done(client_stream, request, status);
213
/* pre_init - pre-jail initialization */
215
static void pre_init(char *unused_name, char **unused_argv)
220
/* main - pass control to the single-threaded skeleton */
222
int main(int argc, char **argv)
224
single_server_main(argc, argv, error_service,
225
MAIL_SERVER_PRE_INIT, pre_init,