annotate src/pop3/main.c @ 9259:ea2eed32d59e HEAD

cache file: If offset isn't 32bit aligned, assume it's corrupted.
author Timo Sirainen <tss@iki.fi>
date Sun, 26 Jul 2009 22:40:02 -0400
parents 7d54410a34b9
children 3eacb6bbd227
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 8467
diff changeset
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "ioloop.h"
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
5 #include "file-lock.h"
2873
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
6 #include "network.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "lib-signals.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "restrict-access.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "fd-close-on-exec.h"
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
10 #include "base64.h"
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
11 #include "buffer.h"
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
12 #include "istream.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include "process-title.h"
1465
03dd87873a81 Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents: 1364
diff changeset
14 #include "module-dir.h"
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
15 #include "var-expand.h"
8300
9d963e3bbe65 Added a simple flat file dict backend.
Timo Sirainen <tss@iki.fi>
parents: 8085
diff changeset
16 #include "dict.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include "mail-storage.h"
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
18 #include "mail-namespace.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
2873
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
20 #include <stdio.h>
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 #include <stdlib.h>
2873
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
22 #include <unistd.h>
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 #include <syslog.h>
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 #define IS_STANDALONE() \
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 (getenv("LOGGED_IN") == NULL)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
2316
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
28 struct client_workaround_list {
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
29 const char *name;
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
30 enum client_workarounds num;
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
31 };
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
32
8027
62cf70991cf2 extern/static fixes (from a sparse check by Diego Liziero)
Timo Sirainen <tss@iki.fi>
parents: 7992
diff changeset
33 static struct client_workaround_list client_workaround_list[] = {
2316
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
34 { "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS },
2952
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2873
diff changeset
35 { "oe-ns-eoh", WORKAROUND_OE_NS_EOH },
2316
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
36 { NULL, 0 }
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
37 };
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
38
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 struct ioloop *ioloop;
1465
03dd87873a81 Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents: 1364
diff changeset
40
1646
a7c742b940e5 Added pop3 hooks
Timo Sirainen <tss@iki.fi>
parents: 1620
diff changeset
41 void (*hook_client_created)(struct client **client) = NULL;
a7c742b940e5 Added pop3 hooks
Timo Sirainen <tss@iki.fi>
parents: 1620
diff changeset
42
5148
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
43 static struct module *modules = NULL;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 static char log_prefix[128]; /* syslog() needs this to be permanent */
4149
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
45 static struct io *log_io = NULL;
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
46
2316
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
47 enum client_workarounds client_workarounds = 0;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3789
diff changeset
48 bool enable_last_command = FALSE;
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3789
diff changeset
49 bool no_flag_updates = FALSE;
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3789
diff changeset
50 bool reuse_xuidl = FALSE;
4153
690c72358cd5 Added pop3_lock_session setting.
Timo Sirainen <tss@iki.fi>
parents: 4149
diff changeset
51 bool lock_session = FALSE;
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3286
diff changeset
52 const char *uidl_format, *logout_format;
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
53 enum uidl_keys uidl_keymask;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54
8882
9f3968f49ceb lib-signals: Changed callback API to return siginfo_t.
Timo Sirainen <tss@iki.fi>
parents: 8798
diff changeset
55 static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 {
3620
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
57 /* warn about being killed because of some signal, except SIGINT (^C)
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
58 which is too common at least while testing :) */
8883
5361cb6afe9e When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents: 8882
diff changeset
59 if (si->si_signo != SIGINT) {
5361cb6afe9e When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents: 8882
diff changeset
60 i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)",
5361cb6afe9e When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents: 8882
diff changeset
61 si->si_signo, dec2str(si->si_pid),
5361cb6afe9e When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents: 8882
diff changeset
62 dec2str(si->si_uid),
5361cb6afe9e When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents: 8882
diff changeset
63 lib_signal_code_to_str(si->si_signo, si->si_code));
5361cb6afe9e When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents: 8882
diff changeset
64 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 io_loop_stop(ioloop);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6019
diff changeset
68 static void log_error_callback(void *context ATTR_UNUSED)
4149
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
69 {
8741
d74fdb84ab8b pop3/imap: When master closes our log fd, don't die when trying to log disconnect reason.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
70 /* the log fd is closed, don't die when trying to log later */
d74fdb84ab8b pop3/imap: When master closes our log fd, don't die when trying to log disconnect reason.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
71 i_set_failure_ignore_errors(TRUE);
d74fdb84ab8b pop3/imap: When master closes our log fd, don't die when trying to log disconnect reason.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
72
4149
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
73 io_loop_stop(ioloop);
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
74 }
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
75
2316
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
76 static void parse_workarounds(void)
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
77 {
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
78 struct client_workaround_list *list;
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
79 const char *env, *const *str;
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
80
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
81 env = getenv("POP3_CLIENT_WORKAROUNDS");
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
82 if (env == NULL)
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
83 return;
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
84
3788
b412da0eb27c Clarify that workaround lists are space separated. But allow commas as
Timo Sirainen <tss@iki.fi>
parents: 3734
diff changeset
85 for (str = t_strsplit_spaces(env, " ,"); *str != NULL; str++) {
2316
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
86 list = client_workaround_list;
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
87 for (; list->name != NULL; list++) {
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
88 if (strcasecmp(*str, list->name) == 0) {
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
89 client_workarounds |= list->num;
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
90 break;
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
91 }
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
92 }
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
93 if (list->name == NULL)
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
94 i_fatal("Unknown client workaround: %s", *str);
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
95 }
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
96 }
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2235
diff changeset
97
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
98 static enum uidl_keys parse_uidl_keymask(const char *format)
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
99 {
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
100 enum uidl_keys mask = 0;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
101
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
102 for (; *format != '\0'; format++) {
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
103 if (format[0] == '%' && format[1] != '\0') {
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
104 switch (var_get_key(++format)) {
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
105 case 'v':
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
106 mask |= UIDL_UIDVALIDITY;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
107 break;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
108 case 'u':
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
109 mask |= UIDL_UID;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
110 break;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
111 case 'm':
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
112 mask |= UIDL_MD5;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
113 break;
2996
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
114 case 'f':
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
115 mask |= UIDL_FILE_NAME;
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
116 break;
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
117 }
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
118 }
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
119 }
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
120 return mask;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
121 }
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
122
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 static void open_logfile(void)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 const char *user;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents: 1652
diff changeset
127 if (getenv("LOG_TO_MASTER") != NULL) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents: 1652
diff changeset
128 i_set_failure_internal();
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents: 1652
diff changeset
129 return;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents: 1652
diff changeset
130 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents: 1652
diff changeset
131
5333
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
132 if (getenv("LOG_PREFIX") != NULL)
6422
18173a52f721 Renamed strocpy() to i_strocpy().
Timo Sirainen <tss@iki.fi>
parents: 6411
diff changeset
133 i_strocpy(log_prefix, getenv("LOG_PREFIX"), sizeof(log_prefix));
5333
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
134 else {
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
135 user = getenv("USER");
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
136 if (user == NULL) user = "??";
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
137 if (strlen(user) >= sizeof(log_prefix)-6) {
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
138 /* quite a long user name, cut it */
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
139 user = t_strndup(user, sizeof(log_prefix)-6-2);
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
140 user = t_strconcat(user, "..", NULL);
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
141 }
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
142 i_snprintf(log_prefix, sizeof(log_prefix), "pop3(%s): ", user);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144
3724
d22c883021da Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents: 3714
diff changeset
145 if (getenv("USE_SYSLOG") != NULL) {
d22c883021da Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents: 3714
diff changeset
146 const char *env = getenv("SYSLOG_FACILITY");
d22c883021da Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents: 3714
diff changeset
147 i_set_failure_syslog(log_prefix, LOG_NDELAY,
d22c883021da Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents: 3714
diff changeset
148 env == NULL ? LOG_MAIL : atoi(env));
d22c883021da Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents: 3714
diff changeset
149 } else {
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 /* log to file or stderr */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 i_set_failure_file(getenv("LOGFILE"), log_prefix);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 if (getenv("INFOLOGFILE") != NULL)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 i_set_info_file(getenv("INFOLOGFILE"));
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 i_set_failure_timestamp_format(getenv("LOGSTAMP"));
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 static void drop_privileges(void)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 {
5186
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
162 const char *version;
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
163
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
164 version = getenv("DOVECOT_VERSION");
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
165 if (version != NULL && strcmp(version, PACKAGE_VERSION) != 0) {
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
166 i_fatal("Dovecot version mismatch: "
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
167 "Master is v%s, pop3 is v"PACKAGE_VERSION" "
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
168 "(if you don't care, set version_ignore=yes)", version);
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
169 }
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
170
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 /* Log file or syslog opening probably requires roots */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 open_logfile();
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173
5148
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
174 /* Load the plugins before chrooting. Their init() is called later. */
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
175 if (getenv("MAIL_PLUGINS") != NULL) {
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
176 const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
177
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
178 if (plugin_dir == NULL)
5354
2cdd0f128825 We defaulted plugin_dir to <moduledir>/imap instead of /pop3.
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
179 plugin_dir = MODULEDIR"/pop3";
5148
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
180 modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
5186
a7627141ec7f Don't compare to PACKAGE_VERSION in lib/ core directly, rather make
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
181 TRUE, version);
5148
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
182 }
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
183
7109
e6823d781317 Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents: 7091
diff changeset
184 restrict_access_by_env(!IS_STANDALONE());
8798
c9381a0fdc5e Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents: 8792
diff changeset
185 restrict_access_allow_coredumps(TRUE);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
188 static bool main_init(void)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 {
8082
db66611fd195 Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents: 8027
diff changeset
190 struct mail_user *user;
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
191 struct client *client;
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
192 const char *str;
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
193 bool ret = TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194
3620
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
195 lib_signals_init();
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
196 lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
197 lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4891
diff changeset
198 lib_signals_ignore(SIGPIPE, TRUE);
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4891
diff changeset
199 lib_signals_ignore(SIGALRM, FALSE);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200
9238
1eb00fd62d1c If login_executable=imap/pop3, give better error message.
Timo Sirainen <tss@iki.fi>
parents: 8883
diff changeset
201 if (getenv("USER") == NULL) {
1eb00fd62d1c If login_executable=imap/pop3, give better error message.
Timo Sirainen <tss@iki.fi>
parents: 8883
diff changeset
202 if (getenv("DOVECOT_MASTER") == NULL)
1eb00fd62d1c If login_executable=imap/pop3, give better error message.
Timo Sirainen <tss@iki.fi>
parents: 8883
diff changeset
203 i_fatal("USER environment missing");
1eb00fd62d1c If login_executable=imap/pop3, give better error message.
Timo Sirainen <tss@iki.fi>
parents: 8883
diff changeset
204 else {
9239
7d54410a34b9 pop3: Fix to previous change: error message should say pop3, not imap.
Timo Sirainen <tss@iki.fi>
parents: 9238
diff changeset
205 i_fatal("login_executable setting must be pop3-login, "
7d54410a34b9 pop3: Fix to previous change: error message should say pop3, not imap.
Timo Sirainen <tss@iki.fi>
parents: 9238
diff changeset
206 "not pop3");
9238
1eb00fd62d1c If login_executable=imap/pop3, give better error message.
Timo Sirainen <tss@iki.fi>
parents: 8883
diff changeset
207 }
1eb00fd62d1c If login_executable=imap/pop3, give better error message.
Timo Sirainen <tss@iki.fi>
parents: 8883
diff changeset
208 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209
3034
de1b904c4df2 Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents: 3033
diff changeset
210 if (getenv("DEBUG") != NULL) {
8792
75aed0ddfcb1 pop3: When mail_debug=yes, log also home directory.
Timo Sirainen <tss@iki.fi>
parents: 8741
diff changeset
211 const char *home;
75aed0ddfcb1 pop3: When mail_debug=yes, log also home directory.
Timo Sirainen <tss@iki.fi>
parents: 8741
diff changeset
212
75aed0ddfcb1 pop3: When mail_debug=yes, log also home directory.
Timo Sirainen <tss@iki.fi>
parents: 8741
diff changeset
213 home = getenv("HOME");
75aed0ddfcb1 pop3: When mail_debug=yes, log also home directory.
Timo Sirainen <tss@iki.fi>
parents: 8741
diff changeset
214 i_info("Effective uid=%s, gid=%s, home=%s",
75aed0ddfcb1 pop3: When mail_debug=yes, log also home directory.
Timo Sirainen <tss@iki.fi>
parents: 8741
diff changeset
215 dec2str(geteuid()), dec2str(getegid()),
75aed0ddfcb1 pop3: When mail_debug=yes, log also home directory.
Timo Sirainen <tss@iki.fi>
parents: 8741
diff changeset
216 home != NULL ? home : "(none)");
3034
de1b904c4df2 Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents: 3033
diff changeset
217 }
de1b904c4df2 Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents: 3033
diff changeset
218
4165
773c4becceae Added shutdown_clients setting to control if existing imap/pop3 processes
Timo Sirainen <tss@iki.fi>
parents: 4153
diff changeset
219 if (getenv("STDERR_CLOSE_SHUTDOWN") != NULL) {
4149
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
220 /* If master dies, the log fd gets closed and we'll quit */
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
221 log_io = io_add(STDERR_FILENO, IO_ERROR,
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
222 log_error_callback, NULL);
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
223 }
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
224
8300
9d963e3bbe65 Added a simple flat file dict backend.
Timo Sirainen <tss@iki.fi>
parents: 8085
diff changeset
225 dict_drivers_register_builtin();
8467
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8300
diff changeset
226 mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL);
3286
def87e4ad3a5 We weren't calling mail_storage_init() at startup so we crashed.
Timo Sirainen <tss@iki.fi>
parents: 3260
diff changeset
227 mail_storage_init();
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228 mail_storage_register_all();
4891
6ab2712f1a93 Only imap binary was actually working.
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
229 mailbox_list_register_all();
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 clients_init();
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231
5148
7f2c39d7a2cc module_dir_load() doesn't call init() functions anymore. Added a new
Timo Sirainen <tss@iki.fi>
parents: 4926
diff changeset
232 module_dir_init(modules);
1465
03dd87873a81 Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents: 1364
diff changeset
233
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2350
diff changeset
234 parse_workarounds();
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2350
diff changeset
235 enable_last_command = getenv("POP3_ENABLE_LAST") != NULL;
2719
f8adc5cb2508 Renamed pop3_mails_keep_recent to pop3_no_flag_updates which includes
Timo Sirainen <tss@iki.fi>
parents: 2621
diff changeset
236 no_flag_updates = getenv("POP3_NO_FLAG_UPDATES") != NULL;
3567
58e3fa234ef4 Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
237 reuse_xuidl = getenv("POP3_REUSE_XUIDL") != NULL;
4153
690c72358cd5 Added pop3_lock_session setting.
Timo Sirainen <tss@iki.fi>
parents: 4149
diff changeset
238 lock_session = getenv("POP3_LOCK_SESSION") != NULL;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
240 uidl_format = getenv("POP3_UIDL_FORMAT");
3664
9bdf25784ac2 Complain about missing pop3_uidl_format also if it's empty
Timo Sirainen <tss@iki.fi>
parents: 3661
diff changeset
241 if (uidl_format == NULL || *uidl_format == '\0')
6019
12f6a19dc846 Set pop3_uidl_format default to %08Xu%08Xv
Timo Sirainen <tss@iki.fi>
parents: 5637
diff changeset
242 uidl_format = "%08Xu%08Xv";
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3286
diff changeset
243 logout_format = getenv("POP3_LOGOUT_FORMAT");
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3286
diff changeset
244 if (logout_format == NULL)
4240
f58c8751cacf Built-in pop3_logout_format default wasn't updated.
Timo Sirainen <tss@iki.fi>
parents: 4230
diff changeset
245 logout_format = "top=%t/%p, retr=%r/%b, del=%d/%m, size=%s";
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
246 uidl_keymask = parse_uidl_keymask(uidl_format);
3734
b1fa09b19b86 Don't allow pop3_uidl_format without at least one valid %var in it.
Timo Sirainen <tss@iki.fi>
parents: 3724
diff changeset
247 if (uidl_keymask == 0)
b1fa09b19b86 Don't allow pop3_uidl_format without at least one valid %var in it.
Timo Sirainen <tss@iki.fi>
parents: 3724
diff changeset
248 i_fatal("pop3_uidl_format setting doesn't contain any "
b1fa09b19b86 Don't allow pop3_uidl_format without at least one valid %var in it.
Timo Sirainen <tss@iki.fi>
parents: 3724
diff changeset
249 "%% variables.");
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
250
8467
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8300
diff changeset
251 user = mail_user_init(getenv("USER"));
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8300
diff changeset
252 mail_user_set_home(user, getenv("HOME"));
8085
bf83aa9c3f4a Removed pool parameter from mail_namespaces_init*(). Use mail_user's pool intead.
Timo Sirainen <tss@iki.fi>
parents: 8082
diff changeset
253 if (mail_namespaces_init(user) < 0)
6540
12a779e08a73 If namespace initialization fails, die with a fatal error message instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
254 i_fatal("Namespace initialization failed");
8082
db66611fd195 Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents: 8027
diff changeset
255
db66611fd195 Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents: 8027
diff changeset
256 client = client_create(0, 1, user);
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
257 if (client == NULL)
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
258 return FALSE;
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
259
7928
9e226056a208 Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents: 7927
diff changeset
260 if (!IS_STANDALONE())
9e226056a208 Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents: 7927
diff changeset
261 client_send_line(client, "+OK Logged in.");
9e226056a208 Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents: 7927
diff changeset
262
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
263 str = getenv("CLIENT_INPUT");
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
264 if (str != NULL) T_BEGIN {
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
265 buffer_t *buf = t_base64_decode_str(str);
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
266 if (buf->used > 0) {
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
267 if (!i_stream_add_data(client->input, buf->data,
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
268 buf->used))
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
269 i_panic("Couldn't add client input to stream");
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
270 ret = client_handle_input(client);
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
271 }
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
272 } T_END;
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
273 return ret;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 static void main_deinit(void)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 {
4149
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
278 if (log_io != NULL)
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
279 io_remove(&log_io);
4183
32b5045f8d80 Destroy client connection at deinit before unloading modules.
Timo Sirainen <tss@iki.fi>
parents: 4165
diff changeset
280 clients_deinit();
1465
03dd87873a81 Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents: 1364
diff changeset
281
4183
32b5045f8d80 Destroy client connection at deinit before unloading modules.
Timo Sirainen <tss@iki.fi>
parents: 4165
diff changeset
282 module_dir_unload(&modules);
32b5045f8d80 Destroy client connection at deinit before unloading modules.
Timo Sirainen <tss@iki.fi>
parents: 4165
diff changeset
283 mail_storage_deinit();
8467
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8300
diff changeset
284 mail_users_deinit();
8300
9d963e3bbe65 Added a simple flat file dict backend.
Timo Sirainen <tss@iki.fi>
parents: 8085
diff changeset
285 dict_drivers_unregister_builtin();
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286
3620
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
287 lib_signals_deinit();
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 closelog();
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6019
diff changeset
291 int main(int argc ATTR_UNUSED, char *argv[], char *envp[])
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293 #ifdef DEBUG
2235
dcff4c088f1a DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents: 2084
diff changeset
294 if (getenv("LOGGED_IN") != NULL && getenv("GDB") == NULL)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 fd_debug_verify_leaks(3, 1024);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 #endif
2873
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
297 if (IS_STANDALONE() && getuid() == 0 &&
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
298 net_getpeername(1, NULL, NULL) == 0) {
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
299 printf("-ERR pop3 binary must not be started from "
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
300 "inetd, use pop3-login instead.\n");
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
301 return 1;
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
302 }
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
303
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304 /* NOTE: we start rooted, so keep the code minimal until
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305 restrict_access_by_env() is called */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306 lib_init();
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
307 drop_privileges();
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
308
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 process_title_init(argv, envp);
5249
784dc7224718 Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
310 ioloop = io_loop_create();
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311
1363
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1351
diff changeset
312 if (main_init())
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1351
diff changeset
313 io_loop_run(ioloop);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 main_deinit();
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
316 io_loop_destroy(&ioloop);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 lib_deinit();
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 return 0;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320 }