Mercurial > dovecot > core-2.2
annotate src/lda/main.c @ 12629:02370eda76f8
lib-storage: Mailbox virtual names are now in UTF-8 format, not IMAP mUTF-7.
Plugins that use mailbox names in configuration now take them also as UTF-8
rather than mUTF-7.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 01 Feb 2011 20:41:54 +0200 |
parents | b748c622e896 |
children | f02d429ff6bd |
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 "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
|
21 #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
|
22 #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
|
23 #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
|
24 #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
|
25 #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
|
26 #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
|
27 #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
|
28 #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
|
29 #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
|
30 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 #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
|
32 #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
|
33 #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
|
34 #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
|
35 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 #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
|
37 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 /* 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
|
39 where to read the mail. */ |
10209
b470c03b7164
lda: Removed accidentally committed debug change.
Timo Sirainen <tss@iki.fi>
parents:
10205
diff
changeset
|
40 #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
|
41 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 static const char *wanted_headers[] = { |
9117 | 43 "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
|
44 NULL |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 }; |
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 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
|
48 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 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
|
50 |
10058
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
51 /* 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
|
52 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
|
53 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
|
54 if (!IS_ATEXT(*p) && *p != '.') |
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
55 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
|
56 } |
10058
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
57 if (*p != '\0' || *local_part == '.' || |
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
58 (p != local_part && p[-1] == '.')) |
b81f4a4076de
lda: Escape local-part if it begins/ends with '.'.
Timo Sirainen <tss@iki.fi>
parents:
10036
diff
changeset
|
59 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
|
60 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
|
61 } |
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 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
|
64 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 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
|
74 *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
|
75 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
|
76 else { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 else |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 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
|
82 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 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
|
84 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
|
85 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 |
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
|
87 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
|
88 { |
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 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
|
90 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
|
91 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
|
92 |
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 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 } |
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 /* 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
|
102 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
|
103 /* 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
|
104 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
|
105 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
|
106 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
|
107 } |
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 *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
|
110 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
|
111 } |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 *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
|
124 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
|
125 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 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
|
127 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
|
128 /* 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
|
129 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
|
130 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
|
131 /* 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
|
132 i_stream_skip(input, 5); |
11039 | 133 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
|
134 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
|
135 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
|
136 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 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
|
139 (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
|
140 &sender); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 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
|
142 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 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
|
145 } |
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 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
|
149 /* 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
|
150 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
|
151 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
|
152 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 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
|
154 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 } else { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 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
|
160 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 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
|
162 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 } |
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 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
|
171 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 /* 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 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
|
182 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
|
183 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 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
|
188 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 default: |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 return; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 *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
|
193 } |
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 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
|
196 { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 printf( |
9103 | 198 "Usage: dovecot-lda [-c <config file>] [-a <address>] [-d <username>] [-p <path>]\n" |
199 " [-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
|
200 } |
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 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
|
203 { |
9106
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9103
diff
changeset
|
204 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
|
205 &lda_setting_parser_info, |
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9103
diff
changeset
|
206 NULL |
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9103
diff
changeset
|
207 }; |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 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
|
209 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
|
210 const char *user, *errstr, *path; |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 if (getuid() != geteuid() && geteuid() == 0) { |
9103 | 232 /* 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
|
233 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
|
234 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
|
235 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 return EX_TEMPFAIL; |
10205
13b3a3ce892c
lda: Fixed binary setuid-checking.
Timo Sirainen <tss@iki.fi>
parents:
10156
diff
changeset
|
240 } 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
|
241 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
|
242 "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
|
243 "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
|
244 argv[0]); |
9948
8342893350b2
deliver: Changed all EX_CONFIGs to EX_TEMPFAILs to avoid bounces.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
245 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
|
246 } |
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 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
|
250 |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9263
diff
changeset
|
251 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
|
252 MASTER_SERVICE_FLAG_STANDALONE | |
ad0b052aef5e
lda: Log to specified log file, not to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9370
diff
changeset
|
253 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
|
254 &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
|
255 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 user = getenv("USER"); |
10119
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
262 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
|
263 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
|
264 case 'a': |
12110
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
265 /* 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
|
266 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
|
267 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 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
|
269 /* 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
|
270 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
|
271 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
|
272 break; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 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
|
274 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
|
275 break; |
10125
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
276 case 'f': |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
277 /* envelope sender address */ |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
278 ctx.src_envelope_sender = |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
279 p_strdup(ctx.pool, address_sanitize(optarg)); |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
280 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
|
281 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
|
282 /* 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
|
283 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
|
284 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
|
285 if (*optarg != '\0') T_BEGIN { |
12253
c4f91b9acb01
lda: -m parameter's UTF-8 validity wasn't checked correctly.
Timo Sirainen <tss@iki.fi>
parents:
12197
diff
changeset
|
286 if (!uni_utf8_str_is_valid(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
|
287 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
|
288 optarg); |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 } |
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
|
290 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
|
291 } 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
|
292 break; |
10125
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
293 case 'p': |
e248c1e53e00
lda: Cleaned up parameter handling.
Timo Sirainen <tss@iki.fi>
parents:
10120
diff
changeset
|
294 /* input path */ |
10501
28a14e2fe5d6
Use t_abspath() instead of duplicating code.
Timo Sirainen <tss@iki.fi>
parents:
10308
diff
changeset
|
295 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
|
296 break; |
12110
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
297 case 'r': |
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
298 /* final recipient address */ |
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
299 ctx.final_dest_addr = optarg; |
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
300 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
|
301 default: |
10119
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
302 print_help(); |
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
303 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
|
304 } |
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 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
|
307 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
|
308 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
|
309 } |
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 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
|
312 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
|
313 ; |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 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
|
315 /* 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
|
316 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
|
317 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
|
318 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 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
|
320 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
|
321 /* 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
|
322 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
|
323 } 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 } 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
|
329 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
|
330 "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
|
331 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
|
332 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 } else { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 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
|
335 "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
|
336 } |
10101
4fe8c4382712
Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents:
10058
diff
changeset
|
337 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
|
338 |
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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 |
12197
002a702cf06a
lda: If doveconf fails, make it exit with EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents:
12140
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 &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
|
350 &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
|
351 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
|
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 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
|
354 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
|
355 } |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
356 |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9147
diff
changeset
|
357 #ifdef SIGXFSZ |
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9147
diff
changeset
|
358 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
|
359 #endif |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
360 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
|
361 |
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
|
362 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
|
363 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
|
364 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
|
365 } |
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 |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 /* 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 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
|
375 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
|
376 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 i_stream_set_name(input, "stdin"); |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 i_fatal("Can't open delivery mail as raw: %s", |
12585
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12566
diff
changeset
|
389 mailbox_get_last_error(box, &error)); |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
390 } |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 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
|
392 } else { |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 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
|
394 box = mailbox_alloc(raw_ns->list, path, |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
395 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
|
396 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
|
397 i_fatal("Can't open delivery mail as raw: %s", |
12585
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12566
diff
changeset
|
398 mailbox_get_last_error(box, &error)); |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
399 } |
9092
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 } |
10509
50364f04cf13
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Timo Sirainen <tss@iki.fi>
parents:
10501
diff
changeset
|
401 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
|
402 i_fatal("Can't sync delivery mail: %s", |
12585
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12566
diff
changeset
|
403 mailbox_get_last_error(box, &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
|
404 } |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 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
|
409 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 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
|
411 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
|
412 ctx.src_mail = mail_alloc(t, 0, headers_ctx); |
9117 | 413 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
|
414 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
|
415 |
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
|
416 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
|
417 *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
|
418 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
|
419 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
|
420 } |
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 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
|
422 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
|
423 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
|
424 } |
12110
d56a28e83f32
lda: Added -r parameter to specify final recipient address.
Timo Sirainen <tss@iki.fi>
parents:
12098
diff
changeset
|
425 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
|
426 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
|
427 |
9117 | 428 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
|
429 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
|
430 /* This shouldn't happen */ |
9117 | 431 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
|
432 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
|
433 } |
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 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
|
436 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 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
|
438 /* 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
|
439 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
|
440 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
|
441 } |
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 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
|
444 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
|
445 /* 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
|
446 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
|
447 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
|
448 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
|
449 } |
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 /* 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
|
452 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
|
453 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
|
454 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 /* 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
|
461 } |
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 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
|
464 mailbox_transaction_rollback(&t); |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
465 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
|
466 |
e4832f128738
Renamed deliver to dovecot-lda and moved most of its code to lib-lda.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 |
10130
d1384c2b08e5
Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents:
10125
diff
changeset
|
471 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
|
472 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
|
473 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
|
474 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
|
475 } |