~ubuntu-branches/ubuntu/dapper/postfix/dapper-security

« back to all changes in this revision

Viewing changes to src/error/error.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      error 8
 
4
/* SUMMARY
 
5
/*      Postfix error mail delivery agent
 
6
/* SYNOPSIS
 
7
/*      \fBerror\fR [generic Postfix daemon options]
 
8
/* DESCRIPTION
 
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
 
14
/*      manager.
 
15
/*
 
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.
 
21
/*
 
22
/*      Delivery status reports are sent to the \fBbounce\fR(8),
 
23
/*      \fBdefer\fR(8) or \fBtrace\fR(8) daemon as appropriate.
 
24
/* SECURITY
 
25
/* .ad
 
26
/* .fi
 
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.
 
29
/* STANDARDS
 
30
/*      None.
 
31
/* DIAGNOSTICS
 
32
/*      Problems and transactions are logged to \fBsyslogd\fR(8).
 
33
/*
 
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
 
37
/* .ad
 
38
/* .fi
 
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.
 
42
/*
 
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
 
47
/*      the sender.
 
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".
 
83
/* SEE ALSO
 
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
 
89
/* LICENSE
 
90
/* .ad
 
91
/* .fi
 
92
/*      The Secure Mailer license must be distributed with this software.
 
93
/* AUTHOR(S)
 
94
/*      Wietse Venema
 
95
/*      IBM T.J. Watson Research
 
96
/*      P.O. Box 704
 
97
/*      Yorktown Heights, NY 10598, USA
 
98
/*--*/
 
99
 
 
100
/* System library. */
 
101
 
 
102
#include <sys_defs.h>
 
103
#include <unistd.h>
 
104
#include <stdlib.h>
 
105
 
 
106
/* Utility library. */
 
107
 
 
108
#include <msg.h>
 
109
#include <vstream.h>
 
110
 
 
111
/* Global library. */
 
112
 
 
113
#include <deliver_request.h>
 
114
#include <mail_queue.h>
 
115
#include <bounce.h>
 
116
#include <deliver_completed.h>
 
117
#include <flush_clnt.h>
 
118
 
 
119
/* Single server skeleton. */
 
120
 
 
121
#include <mail_server.h>
 
122
 
 
123
/* deliver_message - deliver message with extreme prejudice */
 
124
 
 
125
static int deliver_message(DELIVER_REQUEST *request)
 
126
{
 
127
    char   *myname = "deliver_message";
 
128
    VSTREAM *src;
 
129
    int     result = 0;
 
130
    int     status;
 
131
    RECIPIENT *rcpt;
 
132
    int     nrcpt;
 
133
 
 
134
    if (msg_verbose)
 
135
        msg_info("deliver_message: from %s", request->sender);
 
136
 
 
137
    /*
 
138
     * Sanity checks.
 
139
     */
 
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);
 
144
 
 
145
    /*
 
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.
 
150
     */
 
151
    src = mail_queue_open(request->queue_name, request->queue_id,
 
152
                          O_RDWR, 0);
 
153
    if (src == 0)
 
154
        msg_fatal("%s: open %s %s: %m", myname,
 
155
                  request->queue_name, request->queue_id);
 
156
    if (msg_verbose)
 
157
        msg_info("%s: file %s", myname, VSTREAM_PATH(src));
 
158
 
 
159
    /*
 
160
     * Bounce all recipients.
 
161
     */
 
162
#define BOUNCE_FLAGS(request) DEL_REQ_TRACE_FLAGS(request->flags)
 
163
 
 
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);
 
171
            if (status == 0)
 
172
                deliver_completed(src, rcpt->offset);
 
173
            result |= status;
 
174
        }
 
175
    }
 
176
 
 
177
    /*
 
178
     * Clean up.
 
179
     */
 
180
    if (vstream_fclose(src))
 
181
        msg_warn("close %s %s: %m", request->queue_name, request->queue_id);
 
182
 
 
183
    return (result);
 
184
}
 
185
 
 
186
/* error_service - perform service for client */
 
187
 
 
188
static void error_service(VSTREAM *client_stream, char *unused_service, char **argv)
 
189
{
 
190
    DELIVER_REQUEST *request;
 
191
    int     status;
 
192
 
 
193
    /*
 
194
     * Sanity check. This service takes no command-line arguments.
 
195
     */
 
196
    if (argv[0])
 
197
        msg_fatal("unexpected command-line argument: %s", argv[0]);
 
198
 
 
199
    /*
 
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.
 
206
     */
 
207
    if ((request = deliver_request_read(client_stream)) != 0) {
 
208
        status = deliver_message(request);
 
209
        deliver_request_done(client_stream, request, status);
 
210
    }
 
211
}
 
212
 
 
213
/* pre_init - pre-jail initialization */
 
214
 
 
215
static void pre_init(char *unused_name, char **unused_argv)
 
216
{
 
217
    flush_init();
 
218
}
 
219
 
 
220
/* main - pass control to the single-threaded skeleton */
 
221
 
 
222
int     main(int argc, char **argv)
 
223
{
 
224
    single_server_main(argc, argv, error_service,
 
225
                       MAIL_SERVER_PRE_INIT, pre_init,
 
226
                       0);
 
227
}