Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/main.c @ 4074:dadc6e2cccb8 HEAD
Replaced mail_use_modules and mail_modules settings with mail_plugins and
mail_plugin_dir. Now instead of loading all plugins from the directory,
you'll have to give a list of plugins to load. If the plugin couldn't be
loaded, the process exits instead of just ignoring the problem (this is
important with ACL plugin).
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 26 Feb 2006 14:15:34 +0200 |
parents | 4aeb58dc4f18 |
children | b10fa8ba01ca |
rev | line source |
---|---|
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
1 /* Copyright (C) 2002-2003 Timo Sirainen */ |
0 | 2 |
3 #include "common.h" | |
4 #include "ioloop.h" | |
2873
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
5 #include "network.h" |
1498 | 6 #include "ostream.h" |
1586
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
7 #include "str.h" |
0 | 8 #include "lib-signals.h" |
9 #include "restrict-access.h" | |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
621
diff
changeset
|
10 #include "fd-close-on-exec.h" |
746
ad4292a30b1d
Set process title for rawlog process.
Timo Sirainen <tss@iki.fi>
parents:
738
diff
changeset
|
11 #include "process-title.h" |
1597
9f503b7851ab
Moved all dotlocking code to lib/. Also we now use temp file + link() rather
Timo Sirainen <tss@iki.fi>
parents:
1591
diff
changeset
|
12 #include "randgen.h" |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
13 #include "module-dir.h" |
3789
0120998fb2d9
Register proxy dictionary support and link libdict. Currently it's used only
Timo Sirainen <tss@iki.fi>
parents:
3788
diff
changeset
|
14 #include "dict-client.h" |
1041 | 15 #include "mail-storage.h" |
1464
bd489d13479e
Added command_register() and related functions so we can dynamically
Timo Sirainen <tss@iki.fi>
parents:
1351
diff
changeset
|
16 #include "commands.h" |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
17 #include "namespace.h" |
0 | 18 |
2873
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
19 #include <stdio.h> |
0 | 20 #include <stdlib.h> |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
21 #include <unistd.h> |
0 | 22 #include <syslog.h> |
23 | |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
24 #define IS_STANDALONE() \ |
1316 | 25 (getenv("LOGGED_IN") == NULL && getenv("IMAPLOGINTAG") == NULL) |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
26 |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 }; |
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 struct client_workaround_list client_workaround_list[] = { |
3204
c8fffa286b6a
Renamed oe6-fetch-no-newmail workaround to delay-newmail and changed it to
Timo Sirainen <tss@iki.fi>
parents:
3034
diff
changeset
|
33 { "delay-newmail", WORKAROUND_DELAY_NEWMAIL }, |
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-idle", WORKAROUND_OUTLOOK_IDLE }, |
2448 | 35 { "netscape-eoh", WORKAROUND_NETSCAPE_EOH }, |
3505
0e05687892dc
Added tb-extra-mailbox-sep IMAP workaround.
Timo Sirainen <tss@iki.fi>
parents:
3259
diff
changeset
|
36 { "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP }, |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
37 { 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
|
38 }; |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
39 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
40 struct ioloop *ioloop; |
2595
b49d2ed4951a
Removed mailbox_check_interval completely. It wasn't currently implemented,
Timo Sirainen <tss@iki.fi>
parents:
2467
diff
changeset
|
41 unsigned int max_keyword_length; |
1591
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1586
diff
changeset
|
42 unsigned int imap_max_line_length; |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
43 enum client_workarounds client_workarounds = 0; |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1138
diff
changeset
|
44 |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
45 static struct module *modules; |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
46 static char log_prefix[128]; /* syslog() needs this to be permanent */ |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
47 static pool_t namespace_pool; |
0 | 48 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3204
diff
changeset
|
49 void (*hook_mail_storage_created)(struct mail_storage *storage) = NULL; |
1643 | 50 void (*hook_client_created)(struct client **client) = NULL; |
1641
6498f3cb9d2c
Added hook_client_created and hook_mail_storage_created for modules.
Timo Sirainen <tss@iki.fi>
parents:
1622
diff
changeset
|
51 |
1586
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
52 string_t *capability_string; |
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
53 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3505
diff
changeset
|
54 static void sig_die(int signo, void *context __attr_unused__) |
0 | 55 { |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3505
diff
changeset
|
56 /* 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:
3505
diff
changeset
|
57 which is too common at least while testing :) */ |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3505
diff
changeset
|
58 if (signo != SIGINT) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3505
diff
changeset
|
59 i_warning("Killed with signal %d", signo); |
0 | 60 io_loop_stop(ioloop); |
61 } | |
62 | |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
63 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
|
64 { |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
65 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
|
66 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
|
67 |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
68 env = getenv("IMAP_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
|
69 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
|
70 return; |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
71 |
3788
b412da0eb27c
Clarify that workaround lists are space separated. But allow commas as
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 break; |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
78 } |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
79 } |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
80 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
|
81 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
|
82 } |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
83 } |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
84 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
85 static void open_logfile(void) |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
86 { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
87 const char *user; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
88 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1967
diff
changeset
|
89 if (getenv("LOG_TO_MASTER") != NULL) { |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1967
diff
changeset
|
90 i_set_failure_internal(); |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1967
diff
changeset
|
91 return; |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1967
diff
changeset
|
92 } |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1967
diff
changeset
|
93 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
94 user = getenv("USER"); |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
95 if (user == NULL) { |
1194 | 96 if (IS_STANDALONE()) |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
97 user = getlogin(); |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
98 if (user == NULL) |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
99 user = "??"; |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
100 } |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
101 if (strlen(user) >= sizeof(log_prefix)-6) { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
102 /* quite a long user name, cut it */ |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
103 user = t_strndup(user, sizeof(log_prefix)-6-2); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
104 user = t_strconcat(user, "..", NULL); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
105 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
106 i_snprintf(log_prefix, sizeof(log_prefix), "imap(%s)", user); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
107 |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3689
diff
changeset
|
108 if (getenv("USE_SYSLOG") != NULL) { |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3689
diff
changeset
|
109 const char *env = getenv("SYSLOG_FACILITY"); |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3689
diff
changeset
|
110 i_set_failure_syslog(log_prefix, LOG_NDELAY, |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3689
diff
changeset
|
111 env == NULL ? LOG_MAIL : atoi(env)); |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3689
diff
changeset
|
112 } else { |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
113 /* log to file or stderr */ |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
114 i_set_failure_file(getenv("LOGFILE"), log_prefix); |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
115 } |
811
664de3231e33
Added info_log_file setting and i_info() function to write to it. Default is
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
116 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
117 if (getenv("INFOLOGFILE") != NULL) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
118 i_set_info_file(getenv("INFOLOGFILE")); |
811
664de3231e33
Added info_log_file setting and i_info() function to write to it. Default is
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
119 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
120 i_set_failure_timestamp_format(getenv("LOGSTAMP")); |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
121 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
122 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
123 static void drop_privileges(void) |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
124 { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
125 /* Log file or syslog opening probably requires roots */ |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
126 open_logfile(); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
127 |
1597
9f503b7851ab
Moved all dotlocking code to lib/. Also we now use temp file + link() rather
Timo Sirainen <tss@iki.fi>
parents:
1591
diff
changeset
|
128 /* Most likely needed. Have to open /dev/urandom before possible |
9f503b7851ab
Moved all dotlocking code to lib/. Also we now use temp file + link() rather
Timo Sirainen <tss@iki.fi>
parents:
1591
diff
changeset
|
129 chrooting. */ |
9f503b7851ab
Moved all dotlocking code to lib/. Also we now use temp file + link() rather
Timo Sirainen <tss@iki.fi>
parents:
1591
diff
changeset
|
130 random_init(); |
9f503b7851ab
Moved all dotlocking code to lib/. Also we now use temp file + link() rather
Timo Sirainen <tss@iki.fi>
parents:
1591
diff
changeset
|
131 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
132 restrict_access_by_env(!IS_STANDALONE()); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
133 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
134 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
135 static void main_init(void) |
0 | 136 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
137 struct client *client; |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
138 const char *user, *str; |
550
3a83b05a0be3
--with-rawlog: Build support for logging traffic of user sessions. If
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
139 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3505
diff
changeset
|
140 lib_signals_init(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3505
diff
changeset
|
141 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:
3505
diff
changeset
|
142 lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3505
diff
changeset
|
143 lib_signals_set_handler(SIGPIPE, FALSE, NULL, NULL); |
3689
8b68997d6e34
Ignore SIGALRM signal. We don't want to crash when it happens.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
144 lib_signals_set_handler(SIGALRM, FALSE, NULL, NULL); |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
145 |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
146 user = getenv("USER"); |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
147 if (user == NULL) { |
1194 | 148 if (IS_STANDALONE()) |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
149 user = getlogin(); |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
150 if (user == NULL) |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
151 i_fatal("USER environment missing"); |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
152 } |
748
474319868e82
Sanity check to make sure USER environment exists.
Timo Sirainen <tss@iki.fi>
parents:
746
diff
changeset
|
153 |
3034
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
154 if (getenv("DEBUG") != NULL) { |
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
155 i_info("Effective uid=%s, gid=%s", |
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
156 dec2str(geteuid()), dec2str(getegid())); |
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
157 } |
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
158 |
1586
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
159 capability_string = str_new(default_pool, sizeof(CAPABILITY_STRING)+32); |
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
160 str_append(capability_string, CAPABILITY_STRING); |
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
161 |
3789
0120998fb2d9
Register proxy dictionary support and link libdict. Currently it's used only
Timo Sirainen <tss@iki.fi>
parents:
3788
diff
changeset
|
162 dict_client_register(); |
1138
340dea0150bf
Added client_workarounds setting, with currently one workaround for OE6.
Timo Sirainen <tss@iki.fi>
parents:
1087
diff
changeset
|
163 mail_storage_init(); |
0 | 164 mail_storage_register_all(); |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
165 clients_init(); |
1464
bd489d13479e
Added command_register() and related functions so we can dynamically
Timo Sirainen <tss@iki.fi>
parents:
1351
diff
changeset
|
166 commands_init(); |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
167 |
4074
dadc6e2cccb8
Replaced mail_use_modules and mail_modules settings with mail_plugins and
Timo Sirainen <tss@iki.fi>
parents:
4015
diff
changeset
|
168 if (getenv("MODULE_LIST") == NULL) |
dadc6e2cccb8
Replaced mail_use_modules and mail_modules settings with mail_plugins and
Timo Sirainen <tss@iki.fi>
parents:
4015
diff
changeset
|
169 modules = NULL; |
dadc6e2cccb8
Replaced mail_use_modules and mail_modules settings with mail_plugins and
Timo Sirainen <tss@iki.fi>
parents:
4015
diff
changeset
|
170 else { |
dadc6e2cccb8
Replaced mail_use_modules and mail_modules settings with mail_plugins and
Timo Sirainen <tss@iki.fi>
parents:
4015
diff
changeset
|
171 if (getenv("MODULE_DIR") == NULL) |
dadc6e2cccb8
Replaced mail_use_modules and mail_modules settings with mail_plugins and
Timo Sirainen <tss@iki.fi>
parents:
4015
diff
changeset
|
172 i_fatal("MODULE_LIST given but MODULE_DIR was not"); |
dadc6e2cccb8
Replaced mail_use_modules and mail_modules settings with mail_plugins and
Timo Sirainen <tss@iki.fi>
parents:
4015
diff
changeset
|
173 modules = module_dir_load(getenv("MODULE_DIR"), |
dadc6e2cccb8
Replaced mail_use_modules and mail_modules settings with mail_plugins and
Timo Sirainen <tss@iki.fi>
parents:
4015
diff
changeset
|
174 getenv("MODULE_LIST"), TRUE); |
dadc6e2cccb8
Replaced mail_use_modules and mail_modules settings with mail_plugins and
Timo Sirainen <tss@iki.fi>
parents:
4015
diff
changeset
|
175 } |
0 | 176 |
1591
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1586
diff
changeset
|
177 str = getenv("IMAP_MAX_LINE_LENGTH"); |
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1586
diff
changeset
|
178 imap_max_line_length = str != NULL ? |
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1586
diff
changeset
|
179 (unsigned int)strtoul(str, NULL, 10) : |
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1586
diff
changeset
|
180 DEFAULT_IMAP_MAX_LINE_LENGTH; |
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1586
diff
changeset
|
181 |
1959
50e24ce4f9c3
and a few more custom flag -> keyword changes
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
182 str = getenv("MAIL_MAX_KEYWORD_LENGTH"); |
1958 | 183 max_keyword_length = str != NULL ? |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1138
diff
changeset
|
184 (unsigned int)strtoul(str, NULL, 10) : |
1958 | 185 DEFAULT_MAX_KEYWORD_LENGTH; |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1138
diff
changeset
|
186 |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
187 parse_workarounds(); |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
188 |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
189 namespace_pool = pool_alloconly_create("namespaces", 1024); |
1694
0fae24674a9a
Separated rawlog into it's own binary.
Timo Sirainen <tss@iki.fi>
parents:
1654
diff
changeset
|
190 client = client_create(0, 1, namespace_init(namespace_pool, user)); |
0 | 191 |
1498 | 192 o_stream_cork(client->output); |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
193 if (IS_STANDALONE()) { |
620
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
194 client_send_line(client, t_strconcat( |
4015
4aeb58dc4f18
PREAUTH banner should show the capability from capability_string in case
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
195 "* PREAUTH [CAPABILITY ", |
4aeb58dc4f18
PREAUTH banner should show the capability from capability_string in case
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
196 str_c(capability_string), "] " |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
197 "Logged in as ", user, NULL)); |
1316 | 198 } else if (getenv("IMAPLOGINTAG") != NULL) { |
199 /* Support for mailfront */ | |
200 client_send_line(client, t_strconcat(getenv("IMAPLOGINTAG"), | |
201 " OK Logged in.", NULL)); | |
0 | 202 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
203 o_stream_uncork(client->output); |
0 | 204 } |
205 | |
206 static void main_deinit(void) | |
207 { | |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3789
diff
changeset
|
208 module_dir_unload(&modules); |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
209 |
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
210 commands_deinit(); |
0 | 211 clients_deinit(); |
1351
6709d9330885
minor memory leak/cleanup fixes
Timo Sirainen <tss@iki.fi>
parents:
1316
diff
changeset
|
212 mail_storage_deinit(); |
3789
0120998fb2d9
Register proxy dictionary support and link libdict. Currently it's used only
Timo Sirainen <tss@iki.fi>
parents:
3788
diff
changeset
|
213 dict_client_unregister(); |
1597
9f503b7851ab
Moved all dotlocking code to lib/. Also we now use temp file + link() rather
Timo Sirainen <tss@iki.fi>
parents:
1591
diff
changeset
|
214 random_deinit(); |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
215 pool_unref(namespace_pool); |
0 | 216 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3789
diff
changeset
|
217 str_free(&capability_string); |
1967 | 218 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3505
diff
changeset
|
219 lib_signals_deinit(); |
0 | 220 closelog(); |
221 } | |
222 | |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
223 int main(int argc __attr_unused__, char *argv[], char *envp[]) |
0 | 224 { |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
621
diff
changeset
|
225 #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
|
226 if (getenv("LOGGED_IN") != NULL && getenv("GDB") == NULL) |
738
1b0205fc4153
DEBUG: We shouldn't verify the fds when running in pre-auth mode (breaks
Timo Sirainen <tss@iki.fi>
parents:
727
diff
changeset
|
227 fd_debug_verify_leaks(3, 1024); |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
621
diff
changeset
|
228 #endif |
2873
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
229 if (IS_STANDALONE() && getuid() == 0 && |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
230 net_getpeername(1, NULL, NULL) == 0) { |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
231 printf("* BAD [ALERT] imap binary must not be started from " |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
232 "inetd, use imap-login instead.\n"); |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
233 return 1; |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
234 } |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
235 |
0 | 236 /* NOTE: we start rooted, so keep the code minimal until |
237 restrict_access_by_env() is called */ | |
238 lib_init(); | |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
239 drop_privileges(); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
240 |
746
ad4292a30b1d
Set process title for rawlog process.
Timo Sirainen <tss@iki.fi>
parents:
738
diff
changeset
|
241 process_title_init(argv, envp); |
389
60040a9d243f
ioloop_create() takes now pool-parameter. io_buffer_create_mmaped() takes
Timo Sirainen <tss@iki.fi>
parents:
35
diff
changeset
|
242 ioloop = io_loop_create(system_pool); |
0 | 243 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
244 main_init(); |
0 | 245 io_loop_run(ioloop); |
246 main_deinit(); | |
247 | |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3789
diff
changeset
|
248 io_loop_destroy(&ioloop); |
0 | 249 lib_deinit(); |
250 | |
251 return 0; | |
252 } |