Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / error / error.c
blob352faf806486e53f7c191e1abd3a571f0c3da451
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* error 8
6 /* SUMMARY
7 /* Postfix error/retry mail delivery agent
8 /* SYNOPSIS
9 /* \fBerror\fR [generic Postfix daemon options]
10 /* DESCRIPTION
11 /* The Postfix \fBerror\fR(8) delivery agent processes delivery
12 /* requests from
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
19 /* manager.
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.
29 /* SECURITY
30 /* .ad
31 /* .fi
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.
34 /* STANDARDS
35 /* RFC 3463 (Enhanced Status Codes)
36 /* DIAGNOSTICS
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
42 /* .ad
43 /* .fi
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
52 /* the sender.
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".
91 /* SEE ALSO
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
99 /* LICENSE
100 /* .ad
101 /* .fi
102 /* The Secure Mailer license must be distributed with this software.
103 /* AUTHOR(S)
104 /* Wietse Venema
105 /* IBM T.J. Watson Research
106 /* P.O. Box 704
107 /* Yorktown Heights, NY 10598, USA
108 /*--*/
110 /* System library. */
112 #include <sys_defs.h>
113 #include <unistd.h>
114 #include <stdlib.h>
116 /* Utility library. */
118 #include <msg.h>
119 #include <vstream.h>
121 /* Global library. */
123 #include <deliver_request.h>
124 #include <mail_queue.h>
125 #include <bounce.h>
126 #include <defer.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";
145 VSTREAM *src;
146 int result = 0;
147 int status;
148 RECIPIENT *rcpt;
149 int nrcpt;
150 DSN_SPLIT dp;
151 DSN dsn;
153 if (msg_verbose)
154 msg_info("deliver_message: from %s", request->sender);
157 * Sanity checks.
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,
171 O_RDWR, 0);
172 if (src == 0)
173 msg_fatal("%s: open %s %s: %m", myname,
174 request->queue_name, request->queue_id);
175 if (msg_verbose)
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);
189 if (status == 0)
190 deliver_completed(src, rcpt->offset);
191 result |= status;
195 * Clean up.
197 if (vstream_fclose(src))
198 msg_warn("close %s %s: %m", request->queue_name, request->queue_id);
200 return (result);
203 /* error_service - perform service for client */
205 static void error_service(VSTREAM *client_stream, char *service, char **argv)
207 DELIVER_REQUEST *request;
208 int status;
211 * Sanity check. This service takes no command-line arguments.
213 if (argv[0])
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);
229 else
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)
239 flush_init();
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,