main.c revision 182a8b5b6e495bb590c38303e88b556a90468891
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen/* Copyright (C) 2002-2003 Timo Sirainen */
fa45f3f1ad423381ba07056e415ffc4d6449f089Timo Sirainenstruct client_workaround_list client_workaround_list[] = {
fa45f3f1ad423381ba07056e415ffc4d6449f089Timo Sirainen { "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS },
8f1d14e3ada93a6d6ee64f73c6e6ae2364d8eba1Timo Sirainenvoid (*hook_client_created)(struct client **client) = NULL;
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainenstatic char log_prefix[128]; /* syslog() needs this to be permanent */
fa45f3f1ad423381ba07056e415ffc4d6449f089Timo Sirainenenum client_workarounds client_workarounds = 0;
321221ddc2dedc4ad79839770765adc40d311a0dTimo Sirainenstatic void sig_die(int signo, void *context __attr_unused__)
321221ddc2dedc4ad79839770765adc40d311a0dTimo Sirainen /* warn about being killed because of some signal, except SIGINT (^C)
321221ddc2dedc4ad79839770765adc40d311a0dTimo Sirainen which is too common at least while testing :) */
f9ef36afc131626754716d6f4874a2ad04da0ac4Timo Sirainenstatic void log_error_callback(void *context __attr_unused__)
fa45f3f1ad423381ba07056e415ffc4d6449f089Timo Sirainenstatic void parse_workarounds(void)
8b63896feaef40e8c85fa00acdcc123b508e8d42Timo Sirainen for (str = t_strsplit_spaces(env, " ,"); *str != NULL; str++) {
fa45f3f1ad423381ba07056e415ffc4d6449f089Timo Sirainen i_fatal("Unknown client workaround: %s", *str);
00f5efa3156ab6a0b4f21e8c703d0eb816cf3091Timo Sirainenstatic enum uidl_keys parse_uidl_keymask(const char *format)
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainenstatic void open_logfile(void)
174a54c74848b8668acd72ddf36d9b4745e1ad5eTimo Sirainen strocpy(log_prefix, getenv("LOG_PREFIX"), sizeof(log_prefix));
174a54c74848b8668acd72ddf36d9b4745e1ad5eTimo Sirainen /* quite a long user name, cut it */
174a54c74848b8668acd72ddf36d9b4745e1ad5eTimo Sirainen user = t_strndup(user, sizeof(log_prefix)-6-2);
174a54c74848b8668acd72ddf36d9b4745e1ad5eTimo Sirainen i_snprintf(log_prefix, sizeof(log_prefix), "pop3(%s): ", user);
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen /* log to file or stderr */
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen i_set_failure_file(getenv("LOGFILE"), log_prefix);
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen i_set_failure_timestamp_format(getenv("LOGSTAMP"));
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainenstatic void drop_privileges(void)
41590df9f518459d66a9f7b9be2126f2e31fb221Timo Sirainen if (version != NULL && strcmp(version, PACKAGE_VERSION) != 0) {
41590df9f518459d66a9f7b9be2126f2e31fb221Timo Sirainen "(if you don't care, set version_ignore=yes)", version);
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen /* Log file or syslog opening probably requires roots */
aa78a2506ee69a6bd58cc706210ee79b62ec0954Timo Sirainen /* Most likely needed. Have to open /dev/urandom before possible
aa78a2506ee69a6bd58cc706210ee79b62ec0954Timo Sirainen chrooting. */
4449ad85fcbd4f6fedbaa9a5bdfe58a9ae60f8aeTimo Sirainen /* Load the plugins before chrooting. Their init() is called later. */
4449ad85fcbd4f6fedbaa9a5bdfe58a9ae60f8aeTimo Sirainen const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
4449ad85fcbd4f6fedbaa9a5bdfe58a9ae60f8aeTimo Sirainen modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
67b785ce2485243c490f0a8b0753ac4a5d347265Timo Sirainenstatic int main_init(void)
321221ddc2dedc4ad79839770765adc40d311a0dTimo Sirainen lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
321221ddc2dedc4ad79839770765adc40d311a0dTimo Sirainen lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
b725e5503d72a29a3eb18f93c1cbe597c4c31dcdTimo Sirainen if (getenv("STDERR_CLOSE_SHUTDOWN") != NULL) {
f9ef36afc131626754716d6f4874a2ad04da0ac4Timo Sirainen /* If master dies, the log fd gets closed and we'll quit */
a1fa538bac7e5f18d507446e84be49a163c6697dTimo Sirainen enable_last_command = getenv("POP3_ENABLE_LAST") != NULL;
9beca5d6e1f018a7851a57117c036540d823957fTimo Sirainen no_flag_updates = getenv("POP3_NO_FLAG_UPDATES") != NULL;
63d6d0218e5945ad3a7d3fa02e6dc1be2982e257Timo Sirainen reuse_xuidl = getenv("POP3_REUSE_XUIDL") != NULL;
f99fab9747beba303a64e7db9026e3185425833dTimo Sirainen lock_session = getenv("POP3_LOCK_SESSION") != NULL;
9287a73641f0c4d56eb07c2000fc5293cfc8b4f4Timo Sirainen if (uidl_format == NULL || *uidl_format == '\0')
9dd0fae306efb630d9b0dc1e4517cccbc8447164Timo Sirainen logout_format = "top=%t/%p, retr=%r/%b, del=%d/%m, size=%s";
00f5efa3156ab6a0b4f21e8c703d0eb816cf3091Timo Sirainen uidl_keymask = parse_uidl_keymask(uidl_format);
afccb70aad7b6609144971e9db9ece96a5ed8dc9Timo Sirainen i_fatal("pop3_uidl_format setting doesn't contain any "
afccb70aad7b6609144971e9db9ece96a5ed8dc9Timo Sirainen "%% variables.");
e8490a52a1bc71bc53034e68f464435684ad810fTimo Sirainen namespace_pool = pool_alloconly_create("namespaces", 1024);
e8490a52a1bc71bc53034e68f464435684ad810fTimo Sirainen if (mail_namespaces_init(namespace_pool, getenv("USER"), &ns) < 0)
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainenstatic void main_deinit(void)
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainenint main(int argc __attr_unused__, char *argv[], char *envp[])
b565c76999227da8db3670ec2f4b0c39690d8c40Timo Sirainen if (getenv("LOGGED_IN") != NULL && getenv("GDB") == NULL)
4dbe08e1f7f1271299ada9338ff5015367efd0b7Timo Sirainen printf("-ERR pop3 binary must not be started from "
4dbe08e1f7f1271299ada9338ff5015367efd0b7Timo Sirainen "inetd, use pop3-login instead.\n");
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen /* NOTE: we start rooted, so keep the code minimal until
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen restrict_access_by_env() is called */