Mercurial > dovecot > core-2.2
annotate src/lda/main.c @ 12197:002a702cf06a
lda: If doveconf fails, make it exit with EX_TEMPFAIL.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 28 Sep 2010 19:07:33 +0100 |
parents | 942bb9258e49 |
children | c4f91b9acb01 |
rev | line source |
---|---|
10582
615eef3139c2
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
10509
diff
changeset
|
1 /* Copyright (c) 2005-2010 Dovecot authors, see the included COPYING file */ |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "lib-signals.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "env-util.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "fd-set-nonblock.h" |
9370
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
7 #include "close-keep-errno.h" |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "istream.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "istream-seekable.h" |
10501
28a14e2fe5d6
Use t_abspath() instead of duplicating code.
Timo Sirainen <tss@iki.fi>
parents:
10308
diff
changeset
|
10 #include "abspath.h" |
9370
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
11 #include "safe-mkstemp.h" |
9372
b1c584654a0e
lda: If temp file can't be created because home dir doesn't exist, create it.
timo@timo-desktop
parents:
9371
diff
changeset
|
12 #include "eacces-error.h" |
b1c584654a0e
lda: If temp file can't be created because home dir doesn't exist, create it.
timo@timo-desktop
parents:
9371
diff
changeset
|
13 #include "mkdir-parents.h" |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "str.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #include "str-sanitize.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include "strescape.h" |
10308
05d94015d0ef
mail_deliver_save() now takes mailbox name as UTF-8 and internally converts to mUTF-7.
Timo Sirainen <tss@iki.fi>
parents:
10209
diff
changeset
|
17 #include "unichar.h" |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #include "rfc822-parser.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #include "message-address.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 #include "imap-utf7.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 #include "settings-parser.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 #include "master-service.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 #include "master-service-settings.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 #include "mail-storage-service.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 #include "mail-namespace.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 #include "raw-storage.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 #include "mail-deliver.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 #include "mail-send.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 #include "mbox-from.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 #include "lda-settings.h" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 #include <stdio.h> |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 #include <stdlib.h> |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 #include <pwd.h> |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 #include <sysexits.h> |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 #define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON" |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 /* After buffer grows larger than this, create a temporary file to /tmp |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 where to read the mail. */ |
10209
b470c03b7164
lda: Removed accidentally committed debug change.
Timo Sirainen <tss@iki.fi>
parents:
10205
diff
changeset
|
41 #define MAIL_MAX_MEMORY_BUFFER (1024*128) |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 static const char *wanted_headers[] = { |
9117 | 44 "From", "To", "Message-ID", "Subject", "Return-Path", |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 NULL |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 }; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 static const char *escape_local_part(const char *local_part) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 const char *p; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 |
10058
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
52 /* if local_part isn't dot-atom-text, we need to return quoted-string |
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
53 dot-atom-text = 1*atext *("." 1*atext) */ |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 for (p = local_part; *p != '\0'; p++) { |
10058
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
55 if (!IS_ATEXT(*p) && *p != '.') |
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
56 break; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 } |
10058
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
58 if (*p != '\0' || *local_part == '.' || |
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
59 (p != local_part && p[-1] == '.')) |
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
60 local_part = t_strdup_printf("\"%s\"", str_escape(local_part)); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 return local_part; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 static const char *address_sanitize(const char *address) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 struct message_address *addr; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 const char *ret, *mailbox; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 pool_t pool; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 pool = pool_alloconly_create("address sanitizer", 256); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 addr = message_address_parse(pool, (const unsigned char *)address, |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 strlen(address), 1, FALSE); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 if (addr == NULL || addr->mailbox == NULL || addr->domain == NULL || |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 *addr->mailbox == '\0') |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 ret = DEFAULT_ENVELOPE_SENDER; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 else { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 mailbox = escape_local_part(addr->mailbox); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 if (*addr->domain == '\0') |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 ret = t_strdup(mailbox); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 else |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 ret = t_strdup_printf("%s@%s", mailbox, addr->domain); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 pool_unref(&pool); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 return ret; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 |
9370
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
88 static int seekable_fd_callback(const char **path_r, void *context) |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
89 { |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
90 struct mail_deliver_context *ctx = context; |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
91 string_t *path; |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
92 int fd; |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
93 |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
94 path = t_str_new(128); |
11822
7a6cf8dae9bf
Added mail_temp_dir setting, used by deliver and lmtp for creating temp mail files.
Timo Sirainen <tss@iki.fi>
parents:
11773
diff
changeset
|
95 mail_user_set_get_temp_prefix(path, ctx->dest_user->set); |
9370
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
96 fd = safe_mkstemp(path, 0600, (uid_t)-1, (gid_t)-1); |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
97 if (fd == -1) { |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
98 i_error("safe_mkstemp(%s) failed: %m", str_c(path)); |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
99 return -1; |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
100 } |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
101 |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
102 /* we just want the fd, unlink it */ |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
103 if (unlink(str_c(path)) < 0) { |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
104 /* shouldn't happen.. */ |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
105 i_error("unlink(%s) failed: %m", str_c(path)); |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
106 close_keep_errno(fd); |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
107 return -1; |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
108 } |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
109 |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
110 *path_r = str_c(path); |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
111 return fd; |
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
112 } |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 static struct istream * |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 create_raw_stream(struct mail_deliver_context *ctx, |
9370
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
116 int fd, time_t *mtime_r) |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 struct istream *input, *input2, *input_list[2]; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 const unsigned char *data; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 char *sender = NULL; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 size_t i, size; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 int ret, tz; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 *mtime_r = (time_t)-1; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 fd_set_nonblock(fd, FALSE); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 input = i_stream_create_fd(fd, 4096, FALSE); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 input->blocking = TRUE; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 /* If input begins with a From-line, drop it */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 ret = i_stream_read_data(input, &data, &size, 5); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 if (ret > 0 && size >= 5 && memcmp(data, "From ", 5) == 0) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 /* skip until the first LF */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 i_stream_skip(input, 5); |
11039 | 134 while (i_stream_read_data(input, &data, &size, 0) > 0) { |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 for (i = 0; i < size; i++) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 if (data[i] == '\n') |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 if (i != size) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 (void)mbox_from_parse(data, i, mtime_r, &tz, |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 &sender); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 i_stream_skip(input, i + 1); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 i_stream_skip(input, size); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 if (sender != NULL && ctx->src_envelope_sender == NULL) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 /* use the envelope sender from From_-line, but only if it |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 hasn't been specified with -f already. */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 ctx->src_envelope_sender = p_strdup(ctx->pool, sender); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 i_free(sender); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 if (input->v_offset == 0) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 input2 = input; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 i_stream_ref(input2); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 } else { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 input2 = i_stream_create_limit(input, (uoff_t)-1); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 i_stream_unref(&input); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 input_list[0] = input2; input_list[1] = NULL; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 input = i_stream_create_seekable(input_list, MAIL_MAX_MEMORY_BUFFER, |
9370
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
166 seekable_fd_callback, ctx); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 i_stream_unref(&input2); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 return input; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 static void failure_exit_callback(int *status) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 /* we want all our exit codes to be sysexits.h compatible. |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 if we failed because of a logging related error, we most likely |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 aren't writing to stderr, so try writing there to give some kind of |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 a clue what's wrong. FATAL_LOGOPEN failure already wrote to |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 stderr, so don't duplicate it. */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 switch (*status) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 case FATAL_LOGWRITE: |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 fputs("Failed to write to log file", stderr); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 case FATAL_LOGERROR: |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 fputs("Internal logging error", stderr); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 case FATAL_LOGOPEN: |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 case FATAL_OUTOFMEM: |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 case FATAL_EXEC: |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 case FATAL_DEFAULT: |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 default: |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 return; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 *status = EX_TEMPFAIL; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 static void print_help(void) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 printf( |
9103 | 199 "Usage: dovecot-lda [-c <config file>] [-a <address>] [-d <username>] [-p <path>]\n" |
200 " [-f <envelope sender>] [-m <mailbox>] [-e] [-k]\n"); | |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 int main(int argc, char *argv[]) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 { |
9106
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9103
diff
changeset
|
205 const struct setting_parser_info *set_roots[] = { |
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9103
diff
changeset
|
206 &lda_setting_parser_info, |
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9103
diff
changeset
|
207 NULL |
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9103
diff
changeset
|
208 }; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 struct mail_deliver_context ctx; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 enum mail_storage_service_flags service_flags = 0; |
10119
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
211 const char *user, *errstr, *path; |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
212 struct mail_storage_service_ctx *storage_service; |
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
213 struct mail_storage_service_user *service_user; |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9117
diff
changeset
|
214 struct mail_storage_service_input service_input; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 struct mail_user *raw_mail_user; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 struct mail_namespace *raw_ns; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 struct mail_namespace_settings raw_ns_set; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 struct mail_storage *storage; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 struct mailbox *box; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 struct raw_mailbox *raw_box; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 struct istream *input; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 struct mailbox_transaction_context *t; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 struct mailbox_header_lookup_ctx *headers_ctx; |
12140
942bb9258e49
lda: If mail_debug=yes and no -d parameter is given, log where username is taken from.
Timo Sirainen <tss@iki.fi>
parents:
12111
diff
changeset
|
224 const char *user_source = ""; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 void **sets; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 uid_t process_euid; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 bool stderr_rejection = FALSE; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 time_t mtime; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 int ret, c; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 enum mail_error error; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 if (getuid() != geteuid() && geteuid() == 0) { |
9103 | 233 /* running setuid - don't allow this if the binary is |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 executable by anyone */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 struct stat st; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 if (stat(argv[0], &st) < 0) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 fprintf(stderr, "stat(%s) failed: %s\n", |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 argv[0], strerror(errno)); |
9948
8342893350b2
deliver: Changed all EX_CONFIGs to EX_TEMPFAILs to avoid bounces.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
240 return EX_TEMPFAIL; |
10205
13b3a3ce892c
lda: Fixed binary setuid-checking.
Timo Sirainen <tss@iki.fi>
parents:
10156
diff
changeset
|
241 } else if ((st.st_mode & 1) != 0 && (st.st_mode & 04000) != 0) { |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 fprintf(stderr, "%s must not be both world-executable " |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 "and setuid-root. This allows root exploits. " |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 "See http://wiki.dovecot.org/LDA#multipleuids\n", |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 argv[0]); |
9948
8342893350b2
deliver: Changed all EX_CONFIGs to EX_TEMPFAILs to avoid bounces.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
246 return EX_TEMPFAIL; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 i_set_failure_exit_callback(failure_exit_callback); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9263
diff
changeset
|
252 master_service = master_service_init("lda", |
9371
ad0b052aef5e
lda: Log to specified log file, not to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9370
diff
changeset
|
253 MASTER_SERVICE_FLAG_STANDALONE | |
ad0b052aef5e
lda: Log to specified log file, not to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9370
diff
changeset
|
254 MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR, |
12110
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
255 &argc, &argv, "a:d:ef:km:p:r:"); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 memset(&ctx, 0, sizeof(ctx)); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 ctx.pool = pool_alloconly_create("mail deliver context", 256); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 ctx.dest_mailbox_name = "INBOX"; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 path = NULL; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 user = getenv("USER"); |
10119
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
263 while ((c = master_getopt(master_service)) > 0) { |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 switch (c) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 case 'a': |
12110
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
266 /* original recipient address */ |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 ctx.dest_addr = optarg; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 case 'd': |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 /* destination user */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 user = optarg; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 case 'e': |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 stderr_rejection = TRUE; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 break; |
10125
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
277 case 'f': |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
278 /* envelope sender address */ |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
279 ctx.src_envelope_sender = |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
280 p_strdup(ctx.pool, address_sanitize(optarg)); |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
281 break; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 case 'm': |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 /* destination mailbox. |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 Ignore -m "". This allows doing -m ${extension} |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 in Postfix to handle user+mailbox */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 if (*optarg != '\0') T_BEGIN { |
10308
05d94015d0ef
mail_deliver_save() now takes mailbox name as UTF-8 and internally converts to mUTF-7.
Timo Sirainen <tss@iki.fi>
parents:
10209
diff
changeset
|
287 if (uni_utf8_str_is_valid(optarg) < 0) { |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 i_fatal("Mailbox name not UTF-8: %s", |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 optarg); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 } |
10308
05d94015d0ef
mail_deliver_save() now takes mailbox name as UTF-8 and internally converts to mUTF-7.
Timo Sirainen <tss@iki.fi>
parents:
10209
diff
changeset
|
291 ctx.dest_mailbox_name = optarg; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 } T_END; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 break; |
10125
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
294 case 'p': |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
295 /* input path */ |
10501
28a14e2fe5d6
Use t_abspath() instead of duplicating code.
Timo Sirainen <tss@iki.fi>
parents:
10308
diff
changeset
|
296 path = t_abspath(optarg); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 break; |
12110
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
298 case 'r': |
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
299 /* final recipient address */ |
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
300 ctx.final_dest_addr = optarg; |
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
301 break; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 default: |
10119
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
303 print_help(); |
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
304 return EX_USAGE; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 if (optind != argc) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 print_help(); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 i_fatal_status(EX_USAGE, "Unknown argument: %s", argv[optind]); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 process_euid = geteuid(); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 if ((service_flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 ; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 else if (process_euid != 0) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 /* we're non-root. get our username and possibly our home. */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 struct passwd *pw; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 const char *home; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 home = getenv("HOME"); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 if (user != NULL && home != NULL) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 /* no need for a pw lookup */ |
12140
942bb9258e49
lda: If mail_debug=yes and no -d parameter is given, log where username is taken from.
Timo Sirainen <tss@iki.fi>
parents:
12111
diff
changeset
|
323 user_source = "USER environment"; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 } else if ((pw = getpwuid(process_euid)) != NULL) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 user = t_strdup(pw->pw_name); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 if (home == NULL) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 env_put(t_strconcat("HOME=", pw->pw_dir, NULL)); |
12140
942bb9258e49
lda: If mail_debug=yes and no -d parameter is given, log where username is taken from.
Timo Sirainen <tss@iki.fi>
parents:
12111
diff
changeset
|
328 user_source = "passwd lookup for process euid"; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 } else if (user == NULL) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 i_fatal_status(EX_USAGE, |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 "Couldn't lookup our username (uid=%s)", |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 dec2str(process_euid)); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 } else { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 i_fatal_status(EX_USAGE, |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 "destination user parameter (-d user) not given"); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
337 } |
10101
4fe8c4382712
Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents:
10058
diff
changeset
|
338 master_service_init_finish(master_service); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9117
diff
changeset
|
340 memset(&service_input, 0, sizeof(service_input)); |
9263
5d0a69504867
config handling fixes and improvements. Separated module/service lookups. Added support for per-lip/rip settings.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
341 service_input.module = "lda"; |
5d0a69504867
config handling fixes and improvements. Separated module/service lookups. Added support for per-lip/rip settings.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
342 service_input.service = "lda"; |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9117
diff
changeset
|
343 service_input.username = user; |
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9117
diff
changeset
|
344 |
12197
002a702cf06a
lda: If doveconf fails, make it exit with EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
12140
diff
changeset
|
345 service_flags |= MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT | |
002a702cf06a
lda: If doveconf fails, make it exit with EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
12140
diff
changeset
|
346 MAIL_STORAGE_SERVICE_FLAG_USE_SYSEXITS; |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
347 storage_service = mail_storage_service_init(master_service, set_roots, |
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
348 service_flags); |
12098
69a3dfe6dba3
lda: If destination user isn't found, exit with EX_NOUSER, not EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
11822
diff
changeset
|
349 ret = mail_storage_service_lookup_next(storage_service, &service_input, |
69a3dfe6dba3
lda: If destination user isn't found, exit with EX_NOUSER, not EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
11822
diff
changeset
|
350 &service_user, &ctx.dest_user, |
69a3dfe6dba3
lda: If destination user isn't found, exit with EX_NOUSER, not EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
11822
diff
changeset
|
351 &errstr); |
69a3dfe6dba3
lda: If destination user isn't found, exit with EX_NOUSER, not EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
11822
diff
changeset
|
352 if (ret <= 0) { |
69a3dfe6dba3
lda: If destination user isn't found, exit with EX_NOUSER, not EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
11822
diff
changeset
|
353 if (ret < 0) |
69a3dfe6dba3
lda: If destination user isn't found, exit with EX_NOUSER, not EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
11822
diff
changeset
|
354 i_fatal("%s", errstr); |
69a3dfe6dba3
lda: If destination user isn't found, exit with EX_NOUSER, not EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
11822
diff
changeset
|
355 return EX_NOUSER; |
69a3dfe6dba3
lda: If destination user isn't found, exit with EX_NOUSER, not EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
11822
diff
changeset
|
356 } |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
357 |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9147
diff
changeset
|
358 #ifdef SIGXFSZ |
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9147
diff
changeset
|
359 lib_signals_ignore(SIGXFSZ, TRUE); |
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9147
diff
changeset
|
360 #endif |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
361 ctx.set = mail_storage_service_user_get_set(service_user)[1]; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
362 |
12140
942bb9258e49
lda: If mail_debug=yes and no -d parameter is given, log where username is taken from.
Timo Sirainen <tss@iki.fi>
parents:
12111
diff
changeset
|
363 if (ctx.dest_user->mail_debug && *user_source != '\0') { |
942bb9258e49
lda: If mail_debug=yes and no -d parameter is given, log where username is taken from.
Timo Sirainen <tss@iki.fi>
parents:
12111
diff
changeset
|
364 i_debug("userdb lookup skipped, username taken from %s", |
942bb9258e49
lda: If mail_debug=yes and no -d parameter is given, log where username is taken from.
Timo Sirainen <tss@iki.fi>
parents:
12111
diff
changeset
|
365 user_source); |
942bb9258e49
lda: If mail_debug=yes and no -d parameter is given, log where username is taken from.
Timo Sirainen <tss@iki.fi>
parents:
12111
diff
changeset
|
366 } |
942bb9258e49
lda: If mail_debug=yes and no -d parameter is given, log where username is taken from.
Timo Sirainen <tss@iki.fi>
parents:
12111
diff
changeset
|
367 |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 /* create a separate mail user for the internal namespace */ |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9263
diff
changeset
|
369 sets = master_service_settings_get_others(master_service); |
10134
545bdb7670d2
lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents:
10130
diff
changeset
|
370 raw_mail_user = mail_user_alloc(user, ctx.dest_user->set_info, sets[0]); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 mail_user_set_home(raw_mail_user, "/"); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 if (mail_user_init(raw_mail_user, &errstr) < 0) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 i_fatal("Raw user initialization failed: %s", errstr); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 memset(&raw_ns_set, 0, sizeof(raw_ns_set)); |
11061
9c94f073d014
lda, lmtp: Use layout=none for the raw mail storage.
Timo Sirainen <tss@iki.fi>
parents:
11039
diff
changeset
|
376 raw_ns_set.location = ":LAYOUT=none"; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 raw_ns = mail_namespaces_init_empty(raw_mail_user); |
9374
e4429faabf59
Split NAMESPACE_FLAG_INTERNAL into distinct _NOQUOTA and _NOACL flags.
Timo Sirainen <tss@iki.fi>
parents:
9372
diff
changeset
|
379 raw_ns->flags |= NAMESPACE_FLAG_NOQUOTA | NAMESPACE_FLAG_NOACL; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 raw_ns->set = &raw_ns_set; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 if (mail_storage_create(raw_ns, "raw", 0, &errstr) < 0) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 i_fatal("Couldn't create internal raw storage: %s", errstr); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 if (path == NULL) { |
9370
8fa79cdb2ef3
istream-seekable: Changed API to use a callback function to create the temp file.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
384 input = create_raw_stream(&ctx, 0, &mtime); |
10849
638c4ea4a9ce
Set input stream names for mail file streams.
Timo Sirainen <tss@iki.fi>
parents:
10690
diff
changeset
|
385 i_stream_set_name(input, "stdin"); |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
386 box = mailbox_alloc(raw_ns->list, "Dovecot Delivery Mail", |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
387 MAILBOX_FLAG_NO_INDEX_FILES); |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
388 if (mailbox_open_stream(box, input) < 0) { |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
389 i_fatal("Can't open delivery mail as raw: %s", |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
390 mail_storage_get_last_error(box->storage, &error)); |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
391 } |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 i_stream_unref(&input); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 } else { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 mtime = (time_t)-1; |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
395 box = mailbox_alloc(raw_ns->list, path, |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
396 MAILBOX_FLAG_NO_INDEX_FILES); |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
397 if (mailbox_open(box) < 0) { |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
398 i_fatal("Can't open delivery mail as raw: %s", |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
399 mail_storage_get_last_error(box->storage, &error)); |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
400 } |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
401 } |
10509
50364f04cf13
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Timo Sirainen <tss@iki.fi>
parents:
10501
diff
changeset
|
402 if (mailbox_sync(box, 0) < 0) { |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 i_fatal("Can't sync delivery mail: %s", |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9374
diff
changeset
|
404 mail_storage_get_last_error(box->storage, &error)); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
406 raw_box = (struct raw_mailbox *)box; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
407 raw_box->envelope_sender = ctx.src_envelope_sender != NULL ? |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
408 ctx.src_envelope_sender : DEFAULT_ENVELOPE_SENDER; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 raw_box->mtime = mtime; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 t = mailbox_transaction_begin(box, 0); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 headers_ctx = mailbox_header_lookup_init(box, wanted_headers); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 ctx.src_mail = mail_alloc(t, 0, headers_ctx); |
9117 | 414 mailbox_header_lookup_unref(&headers_ctx); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 mail_set_seq(ctx.src_mail, 1); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 |
12111
8bd2bd410c73
Added lda_original_recipient_header setting. Removed non-standard use of Envelope-To: header.
Timo Sirainen <tss@iki.fi>
parents:
12110
diff
changeset
|
417 if (ctx.dest_addr == NULL && |
8bd2bd410c73
Added lda_original_recipient_header setting. Removed non-standard use of Envelope-To: header.
Timo Sirainen <tss@iki.fi>
parents:
12110
diff
changeset
|
418 *ctx.set->lda_original_recipient_header != '\0') { |
11187
82d5351b5d39
lib-lda: Added mail_deliver_get_log_var_expand_table().
Timo Sirainen <tss@iki.fi>
parents:
11061
diff
changeset
|
419 ctx.dest_addr = mail_deliver_get_address(ctx.src_mail, |
12111
8bd2bd410c73
Added lda_original_recipient_header setting. Removed non-standard use of Envelope-To: header.
Timo Sirainen <tss@iki.fi>
parents:
12110
diff
changeset
|
420 ctx.set->lda_original_recipient_header); |
8bd2bd410c73
Added lda_original_recipient_header setting. Removed non-standard use of Envelope-To: header.
Timo Sirainen <tss@iki.fi>
parents:
12110
diff
changeset
|
421 } |
8bd2bd410c73
Added lda_original_recipient_header setting. Removed non-standard use of Envelope-To: header.
Timo Sirainen <tss@iki.fi>
parents:
12110
diff
changeset
|
422 if (ctx.dest_addr == NULL) { |
8bd2bd410c73
Added lda_original_recipient_header setting. Removed non-standard use of Envelope-To: header.
Timo Sirainen <tss@iki.fi>
parents:
12110
diff
changeset
|
423 ctx.dest_addr = strchr(user, '@') != NULL ? user : |
8bd2bd410c73
Added lda_original_recipient_header setting. Removed non-standard use of Envelope-To: header.
Timo Sirainen <tss@iki.fi>
parents:
12110
diff
changeset
|
424 t_strconcat(user, "@", ctx.set->hostname, NULL); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
425 } |
12110
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
426 if (ctx.final_dest_addr == NULL) |
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
427 ctx.final_dest_addr = ctx.dest_addr; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
428 |
9117 | 429 if (mail_deliver(&ctx, &storage) < 0) { |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 if (storage == NULL) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 /* This shouldn't happen */ |
9117 | 432 i_error("BUG: Saving failed to unknown storage"); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 return EX_TEMPFAIL; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
435 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
436 errstr = mail_storage_get_last_error(storage, &error); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 if (stderr_rejection) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 /* write to stderr also for tempfails so that MTA |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 can log the reason if it wants to. */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 fprintf(stderr, "%s\n", errstr); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 if (error != MAIL_ERROR_NOSPACE || |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 ctx.set->quota_full_tempfail) { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
446 /* Saving to INBOX should always work unless |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 we're over quota. If it didn't, it's probably a |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 configuration problem. */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 return EX_TEMPFAIL; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 /* we'll have to reply with permanent failure */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 mail_deliver_log(&ctx, "rejected: %s", |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 str_sanitize(errstr, 512)); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 if (stderr_rejection) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
457 return EX_NOPERM; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
458 ret = mail_send_rejection(&ctx, user, errstr); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
459 if (ret != 0) |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
460 return ret < 0 ? EX_TEMPFAIL : ret; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
461 /* ok, rejection sent */ |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 mail_free(&ctx.src_mail); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 mailbox_transaction_rollback(&t); |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
466 mailbox_free(&box); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 mail_user_unref(&ctx.dest_user); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 mail_user_unref(&raw_mail_user); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 pool_unref(&ctx.pool); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
472 mail_storage_service_user_free(&service_user); |
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
473 mail_storage_service_deinit(&storage_service); |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9263
diff
changeset
|
474 master_service_deinit(&master_service); |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 return EX_OK; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 } |