Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/main.c @ 3204:c8fffa286b6a HEAD
Renamed oe6-fetch-no-newmail workaround to delay-newmail and changed it to
work more like the name says: only newmail notifications are skipped and
not only for FETCH command.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 14 Mar 2005 23:17:58 +0200 |
parents | de1b904c4df2 |
children | 923ff19873d4 |
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" |
1041 | 14 #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
|
15 #include "commands.h" |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
16 #include "namespace.h" |
0 | 17 |
2873
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
18 #include <stdio.h> |
0 | 19 #include <stdlib.h> |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
20 #include <unistd.h> |
0 | 21 #include <syslog.h> |
22 | |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
23 #define IS_STANDALONE() \ |
1316 | 24 (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
|
25 |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 }; |
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 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
|
32 { "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
|
33 { "outlook-idle", WORKAROUND_OUTLOOK_IDLE }, |
2448 | 34 { "netscape-eoh", WORKAROUND_NETSCAPE_EOH }, |
2792
7cc03b8278a8
Added tb-negative-fetch workaround.
Timo Sirainen <tss@iki.fi>
parents:
2595
diff
changeset
|
35 { "tb-negative-fetch", WORKAROUND_TB_NEGATIVE_FETCH }, |
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 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
39 struct ioloop *ioloop; |
2595
b49d2ed4951a
Removed mailbox_check_interval completely. It wasn't currently implemented,
Timo Sirainen <tss@iki.fi>
parents:
2467
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
44 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
|
45 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
|
46 static pool_t namespace_pool; |
0 | 47 |
1643 | 48 void (*hook_mail_storage_created)(struct mail_storage **storage) = NULL; |
49 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
|
50 |
1586
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
51 string_t *capability_string; |
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
52 |
0 | 53 static void sig_quit(int signo __attr_unused__) |
54 { | |
55 io_loop_stop(ioloop); | |
56 } | |
57 | |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
58 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
|
59 { |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
60 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
|
61 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
|
62 |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
63 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
|
64 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
|
65 return; |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
66 |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
67 for (str = t_strsplit_spaces(env, " "); *str != NULL; str++) { |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 break; |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
73 } |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
74 } |
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 (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
|
76 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
|
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 } |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
79 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
80 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
|
81 { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
82 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
|
83 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1967
diff
changeset
|
84 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
|
85 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
|
86 return; |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1967
diff
changeset
|
87 } |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1967
diff
changeset
|
88 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
89 user = getenv("USER"); |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
90 if (user == NULL) { |
1194 | 91 if (IS_STANDALONE()) |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
92 user = getlogin(); |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
93 if (user == NULL) |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
94 user = "??"; |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
95 } |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
96 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
|
97 /* 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
|
98 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
|
99 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
|
100 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
101 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
|
102 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
103 if (getenv("USE_SYSLOG") != NULL) |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
104 i_set_failure_syslog(log_prefix, LOG_NDELAY, LOG_MAIL); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
105 else { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
106 /* 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
|
107 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
|
108 } |
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
|
109 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
110 if (getenv("INFOLOGFILE") != NULL) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
111 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
|
112 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
113 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
|
114 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
115 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
116 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
|
117 { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
118 /* 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
|
119 open_logfile(); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
120 |
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
|
121 /* 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
|
122 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
|
123 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
|
124 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
125 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
|
126 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
127 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
128 static void main_init(void) |
0 | 129 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
130 struct client *client; |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
131 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
|
132 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
133 lib_init_signals(sig_quit); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
134 |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
135 user = getenv("USER"); |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
136 if (user == NULL) { |
1194 | 137 if (IS_STANDALONE()) |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
138 user = getlogin(); |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
139 if (user == NULL) |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
140 i_fatal("USER environment missing"); |
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
141 } |
748
474319868e82
Sanity check to make sure USER environment exists.
Timo Sirainen <tss@iki.fi>
parents:
746
diff
changeset
|
142 |
3034
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
143 if (getenv("DEBUG") != NULL) { |
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
144 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
|
145 dec2str(geteuid()), dec2str(getegid())); |
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
146 } |
de1b904c4df2
Print effective uid/gid when mail_debug is enabled.
Timo Sirainen <tss@iki.fi>
parents:
2873
diff
changeset
|
147 |
1586
898a95426118
Keep capability in string_t so plugins can modify it.
Timo Sirainen <tss@iki.fi>
parents:
1498
diff
changeset
|
148 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
|
149 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
|
150 |
1138
340dea0150bf
Added client_workarounds setting, with currently one workaround for OE6.
Timo Sirainen <tss@iki.fi>
parents:
1087
diff
changeset
|
151 mail_storage_init(); |
0 | 152 mail_storage_register_all(); |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
153 clients_init(); |
1464
bd489d13479e
Added command_register() and related functions so we can dynamically
Timo Sirainen <tss@iki.fi>
parents:
1351
diff
changeset
|
154 commands_init(); |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
155 |
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
156 modules = getenv("MODULE_DIR") == NULL ? NULL : |
2084
9ba79ebae6ab
Added support for password scheme plugins. auth module dir defaults under
Timo Sirainen <tss@iki.fi>
parents:
2002
diff
changeset
|
157 module_dir_load(getenv("MODULE_DIR"), TRUE); |
0 | 158 |
1591
6eca99b727a0
IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents:
1586
diff
changeset
|
159 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
|
160 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
|
161 (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
|
162 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
|
163 |
1959
50e24ce4f9c3
and a few more custom flag -> keyword changes
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
164 str = getenv("MAIL_MAX_KEYWORD_LENGTH"); |
1958 | 165 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
|
166 (unsigned int)strtoul(str, NULL, 10) : |
1958 | 167 DEFAULT_MAX_KEYWORD_LENGTH; |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1138
diff
changeset
|
168 |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
169 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
|
170 |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
171 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
|
172 client = client_create(0, 1, namespace_init(namespace_pool, user)); |
0 | 173 |
1498 | 174 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
|
175 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
|
176 client_send_line(client, t_strconcat( |
621 | 177 "* PREAUTH [CAPABILITY "CAPABILITY_STRING"] " |
1193
206190c8c66f
Use getlogin() alternatively if USER environment isn't found.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
178 "Logged in as ", user, NULL)); |
1316 | 179 } else if (getenv("IMAPLOGINTAG") != NULL) { |
180 /* Support for mailfront */ | |
181 client_send_line(client, t_strconcat(getenv("IMAPLOGINTAG"), | |
182 " OK Logged in.", NULL)); | |
0 | 183 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
184 o_stream_uncork(client->output); |
0 | 185 } |
186 | |
187 static void main_deinit(void) | |
188 { | |
189 /* warn about being killed because of some signal, except SIGINT (^C) | |
190 which is too common at least while testing :) */ | |
191 if (lib_signal_kill != 0 && lib_signal_kill != 2) | |
192 i_warning("Killed with signal %d", lib_signal_kill); | |
193 | |
1465
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
194 module_dir_unload(modules); |
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
195 |
03dd87873a81
Added support for dynamically loadable imap/pop3 modules.
Timo Sirainen <tss@iki.fi>
parents:
1464
diff
changeset
|
196 commands_deinit(); |
0 | 197 clients_deinit(); |
1351
6709d9330885
minor memory leak/cleanup fixes
Timo Sirainen <tss@iki.fi>
parents:
1316
diff
changeset
|
198 mail_storage_deinit(); |
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
|
199 random_deinit(); |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1652
diff
changeset
|
200 pool_unref(namespace_pool); |
0 | 201 |
1967 | 202 str_free(capability_string); |
203 | |
0 | 204 closelog(); |
205 } | |
206 | |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
207 int main(int argc __attr_unused__, char *argv[], char *envp[]) |
0 | 208 { |
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
|
209 #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
|
210 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
|
211 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
|
212 #endif |
2873
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 "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
|
217 return 1; |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
218 } |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
219 |
0 | 220 /* NOTE: we start rooted, so keep the code minimal until |
221 restrict_access_by_env() is called */ | |
222 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
|
223 drop_privileges(); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
224 |
746
ad4292a30b1d
Set process title for rawlog process.
Timo Sirainen <tss@iki.fi>
parents:
738
diff
changeset
|
225 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
|
226 ioloop = io_loop_create(system_pool); |
0 | 227 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
228 main_init(); |
0 | 229 io_loop_run(ioloop); |
230 main_deinit(); | |
231 | |
232 io_loop_destroy(ioloop); | |
233 lib_deinit(); | |
234 | |
235 return 0; | |
236 } |