7 /* Postfix error/retry mail delivery agent
9 /* \fBerror\fR [generic Postfix daemon options]
11 /* The Postfix \fBerror\fR(8) delivery agent processes delivery
13 /* the queue manager. Each request specifies a queue file, a sender
14 /* address, the reason for non-delivery (specified as the
15 /* next-hop destination), and recipient information.
16 /* The reason may be prefixed with an RFC 3463-compatible detail code;
17 /* if none is specified a default 4.0.0 or 5.0.0 code is used instead.
18 /* This program expects to be run from the \fBmaster\fR(8) process
21 /* Depending on the service name in master.cf, \fBerror\fR
22 /* or \fBretry\fR, the server bounces or defers all recipients
23 /* in the delivery request using the "next-hop" information
24 /* as the reason for non-delivery. The \fBretry\fR service name is
25 /* supported as of Postfix 2.4.
27 /* Delivery status reports are sent to the \fBbounce\fR(8),
28 /* \fBdefer\fR(8) or \fBtrace\fR(8) daemon as appropriate.
32 /* The \fBerror\fR(8) mailer is not security-sensitive. It does not talk
33 /* to the network, and can be run chrooted at fixed low privilege.
35 /* RFC 3463 (Enhanced Status Codes)
37 /* Problems and transactions are logged to \fBsyslogd\fR(8).
39 /* Depending on the setting of the \fBnotify_classes\fR parameter,
40 /* the postmaster is notified of bounces and of other trouble.
41 /* CONFIGURATION PARAMETERS
44 /* Changes to \fBmain.cf\fR are picked up automatically as \fBerror\fR(8)
45 /* processes run for only a limited amount of time. Use the command
46 /* "\fBpostfix reload\fR" to speed up a change.
48 /* The text below provides only a parameter summary. See
49 /* \fBpostconf\fR(5) for more details including examples.
50 /* .IP "\fB2bounce_notice_recipient (postmaster)\fR"
51 /* The recipient of undeliverable mail that cannot be returned to
53 /* .IP "\fBbounce_notice_recipient (postmaster)\fR"
54 /* The recipient of postmaster notifications with the message headers
55 /* of mail that Postfix did not deliver and of SMTP conversation
56 /* transcripts of mail that Postfix did not receive.
57 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR"
58 /* The default location of the Postfix main.cf and master.cf
59 /* configuration files.
60 /* .IP "\fBdaemon_timeout (18000s)\fR"
61 /* How much time a Postfix daemon process may take to handle a
62 /* request before it is terminated by a built-in watchdog timer.
63 /* .IP "\fBdelay_logging_resolution_limit (2)\fR"
64 /* The maximal number of digits after the decimal point when logging
65 /* sub-second delay values.
66 /* .IP "\fBdouble_bounce_sender (double-bounce)\fR"
67 /* The sender address of postmaster notifications that are generated
68 /* by the mail system.
69 /* .IP "\fBipc_timeout (3600s)\fR"
70 /* The time limit for sending or receiving information over an internal
71 /* communication channel.
72 /* .IP "\fBmax_idle (100s)\fR"
73 /* The maximum amount of time that an idle Postfix daemon process waits
74 /* for an incoming connection before terminating voluntarily.
75 /* .IP "\fBmax_use (100)\fR"
76 /* The maximal number of incoming connections that a Postfix daemon
77 /* process will service before terminating voluntarily.
78 /* .IP "\fBnotify_classes (resource, software)\fR"
79 /* The list of error classes that are reported to the postmaster.
80 /* .IP "\fBprocess_id (read-only)\fR"
81 /* The process ID of a Postfix command or daemon process.
82 /* .IP "\fBprocess_name (read-only)\fR"
83 /* The process name of a Postfix command or daemon process.
84 /* .IP "\fBqueue_directory (see 'postconf -d' output)\fR"
85 /* The location of the Postfix top-level queue directory.
86 /* .IP "\fBsyslog_facility (mail)\fR"
87 /* The syslog facility of Postfix logging.
88 /* .IP "\fBsyslog_name (see 'postconf -d' output)\fR"
89 /* The mail system name that is prepended to the process name in syslog
90 /* records, so that "smtpd" becomes, for example, "postfix/smtpd".
92 /* qmgr(8), queue manager
93 /* bounce(8), delivery status reports
94 /* discard(8), Postfix discard delivery agent
95 /* postconf(5), configuration parameters
96 /* master(5), generic daemon options
97 /* master(8), process manager
98 /* syslogd(8), system logging
102 /* The Secure Mailer license must be distributed with this software.
105 /* IBM T.J. Watson Research
107 /* Yorktown Heights, NY 10598, USA
110 /* System library. */
112 #include <sys_defs.h>
116 /* Utility library. */
121 /* Global library. */
123 #include <deliver_request.h>
124 #include <mail_queue.h>
127 #include <deliver_completed.h>
128 #include <flush_clnt.h>
129 #include <dsn_util.h>
130 #include <sys_exits.h>
131 #include <mail_proto.h>
132 #include <mail_version.h>
134 /* Single server skeleton. */
136 #include <mail_server.h>
138 /* deliver_message - deliver message with extreme prejudice */
140 static int deliver_message(DELIVER_REQUEST
*request
, const char *def_dsn
,
141 int (*append
) (int, const char *, MSG_STATS
*, RECIPIENT
*,
142 const char *, DSN
*))
144 const char *myname
= "deliver_message";
154 msg_info("deliver_message: from %s", request
->sender
);
159 if (request
->nexthop
[0] == 0)
160 msg_fatal("empty nexthop hostname");
161 if (request
->rcpt_list
.len
<= 0)
162 msg_fatal("recipient count: %d", request
->rcpt_list
.len
);
165 * Open the queue file. Opening the file can fail for a variety of
166 * reasons, such as the system running out of resources. Instead of
167 * throwing away mail, we're raising a fatal error which forces the mail
168 * system to back off, and retry later.
170 src
= mail_queue_open(request
->queue_name
, request
->queue_id
,
173 msg_fatal("%s: open %s %s: %m", myname
,
174 request
->queue_name
, request
->queue_id
);
176 msg_info("%s: file %s", myname
, VSTREAM_PATH(src
));
179 * Bounce/defer/whatever all recipients.
181 #define BOUNCE_FLAGS(request) DEL_REQ_TRACE_FLAGS(request->flags)
183 dsn_split(&dp
, def_dsn
, request
->nexthop
);
184 (void) DSN_SIMPLE(&dsn
, DSN_STATUS(dp
.dsn
), dp
.text
);
185 for (nrcpt
= 0; nrcpt
< request
->rcpt_list
.len
; nrcpt
++) {
186 rcpt
= request
->rcpt_list
.info
+ nrcpt
;
187 status
= append(BOUNCE_FLAGS(request
), request
->queue_id
,
188 &request
->msg_stats
, rcpt
, "none", &dsn
);
190 deliver_completed(src
, rcpt
->offset
);
197 if (vstream_fclose(src
))
198 msg_warn("close %s %s: %m", request
->queue_name
, request
->queue_id
);
203 /* error_service - perform service for client */
205 static void error_service(VSTREAM
*client_stream
, char *service
, char **argv
)
207 DELIVER_REQUEST
*request
;
211 * Sanity check. This service takes no command-line arguments.
214 msg_fatal("unexpected command-line argument: %s", argv
[0]);
217 * This routine runs whenever a client connects to the UNIX-domain socket
218 * dedicated to the error mailer. What we see below is a little protocol
219 * to (1) tell the queue manager that we are ready, (2) read a request
220 * from the queue manager, and (3) report the completion status of that
221 * request. All connection-management stuff is handled by the common code
222 * in single_server.c.
224 if ((request
= deliver_request_read(client_stream
)) != 0) {
225 if (strcmp(service
, MAIL_SERVICE_ERROR
) == 0)
226 status
= deliver_message(request
, "5.0.0", bounce_append
);
227 else if (strcmp(service
, MAIL_SERVICE_RETRY
) == 0)
228 status
= deliver_message(request
, "4.0.0", defer_append
);
230 msg_fatal("bad error service name: %s", service
);
231 deliver_request_done(client_stream
, request
, status
);
235 /* pre_init - pre-jail initialization */
237 static void pre_init(char *unused_name
, char **unused_argv
)
242 MAIL_VERSION_STAMP_DECLARE
;
244 /* main - pass control to the single-threaded skeleton */
246 int main(int argc
, char **argv
)
250 * Fingerprint executables and core dumps.
252 MAIL_VERSION_STAMP_ALLOCATE
;
254 single_server_main(argc
, argv
, error_service
,
255 MAIL_SERVER_PRE_INIT
, pre_init
,