Mercurial > dovecot > core-2.2
annotate src/pop3/main.c @ 9147:bf448752f6c4 HEAD
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 20 Apr 2009 19:07:24 -0400 |
parents | fce3926fe910 |
children | 6324a79d3ee1 |
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" |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
5 #include "istream.h" |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
6 #include "buffer.h" |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
7 #include "base64.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
|
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" |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "process-title.h" |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
11 #include "master-service.h" |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
12 #include "var-expand.h" |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
13 #include "mail-storage-service.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
|
14 |
2873
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
15 #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
|
16 #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
|
17 #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
|
18 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #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
|
20 (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
|
21 |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
22 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
|
23 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
|
24 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
|
25 }; |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
26 |
8027
62cf70991cf2
extern/static fixes (from a sparse check by Diego Liziero)
Timo Sirainen <tss@iki.fi>
parents:
7992
diff
changeset
|
27 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
|
28 { "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS }, |
2952 | 29 { "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
|
30 { 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
|
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 |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
33 struct master_service *service; |
1646 | 34 void (*hook_client_created)(struct client **client) = NULL; |
35 | |
4149
b10fa8ba01ca
When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents:
4074
diff
changeset
|
36 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
|
37 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6019
diff
changeset
|
38 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
|
39 { |
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
|
40 /* 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
|
41 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
|
42 |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
43 master_service_stop(service); |
4149
b10fa8ba01ca
When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents:
4074
diff
changeset
|
44 } |
b10fa8ba01ca
When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents:
4074
diff
changeset
|
45 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
46 static enum client_workarounds |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
47 parse_workarounds(const struct pop3_settings *set) |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
48 { |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
49 enum client_workarounds client_workarounds = 0; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
50 struct client_workaround_list *list; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
51 const char *const *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
|
52 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
53 str = t_strsplit_spaces(set->pop3_client_workarounds, " ,"); |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
54 for (; *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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 break; |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
60 } |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
61 } |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
62 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
|
63 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
|
64 } |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
65 return client_workarounds; |
2316
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 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
68 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
|
69 { |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
70 enum uidl_keys mask = 0; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
71 |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
72 for (; *format != '\0'; format++) { |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
73 if (format[0] == '%' && format[1] != '\0') { |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
74 switch (var_get_key(++format)) { |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
75 case 'v': |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
76 mask |= UIDL_UIDVALIDITY; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
77 break; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
78 case 'u': |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
79 mask |= UIDL_UID; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
80 break; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
81 case 'm': |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
82 mask |= UIDL_MD5; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
83 break; |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
84 case 'f': |
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
85 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
|
86 break; |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
87 } |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
88 } |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
89 } |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
90 return mask; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
91 } |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
92 |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
93 static bool main_init(const struct pop3_settings *set, struct mail_user *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
|
94 { |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
95 struct client *client; |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
96 const char *str; |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
97 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
|
98 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
99 if (set->shutdown_clients) { |
4149
b10fa8ba01ca
When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents:
4074
diff
changeset
|
100 /* 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
|
101 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
|
102 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
|
103 } |
b10fa8ba01ca
When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents:
4074
diff
changeset
|
104 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 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
|
106 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
107 client = client_create(0, 1, user, set); |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
108 if (client == NULL) |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
109 return FALSE; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
110 client->workarounds = parse_workarounds(set); |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
111 client->uidl_keymask = parse_uidl_keymask(set->pop3_uidl_format); |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
112 if (client->uidl_keymask == 0) { |
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
|
113 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
|
114 "%% variables."); |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
115 } |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
116 |
7928
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
117 if (!IS_STANDALONE()) |
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
118 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
|
119 |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 buf->used)) |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
126 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
|
127 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
|
128 } |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
129 } T_END; |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
130 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
|
131 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 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
|
134 { |
4149
b10fa8ba01ca
When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents:
4074
diff
changeset
|
135 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
|
136 io_remove(&log_io); |
4183
32b5045f8d80
Destroy client connection at deinit before unloading modules.
Timo Sirainen <tss@iki.fi>
parents:
4165
diff
changeset
|
137 clients_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
|
138 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
140 int main(int argc, 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
|
141 { |
9106
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9080
diff
changeset
|
142 const struct setting_parser_info *set_roots[] = { |
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9080
diff
changeset
|
143 &pop3_setting_parser_info, |
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9080
diff
changeset
|
144 NULL |
fce3926fe910
mail_storage_service_init*() can now take multiple set_roots.
Timo Sirainen <tss@iki.fi>
parents:
9080
diff
changeset
|
145 }; |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
146 enum master_service_flags service_flags = 0; |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
147 enum mail_storage_service_flags storage_service_flags = |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
148 MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT; |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
149 struct mail_storage_service_input input; |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
150 struct mail_user *mail_user; |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
151 const struct pop3_settings *set; |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
152 const char *value; |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
153 int c; |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
154 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 #ifdef DEBUG |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
156 if (!IS_STANDALONE() && 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
|
157 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
|
158 #endif |
2873
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 "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
|
163 return 1; |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
164 } |
72f28a4b964d
Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
165 |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
166 if (IS_STANDALONE()) |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
167 service_flags |= MASTER_SERVICE_FLAG_STANDALONE; |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
168 else |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
169 service_flags |= MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT; |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
170 |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
171 service = master_service_init("pop3", service_flags, argc, argv); |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
172 while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) { |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
173 if (!master_service_parse_option(service, c, optarg)) |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
174 i_fatal("Unknown argument: %c", c); |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
175 } |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
176 |
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
177 memset(&input, 0, sizeof(input)); |
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
178 input.username = getenv("USER"); |
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
179 if (input.username == NULL) { |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
180 if (IS_STANDALONE()) |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
181 input.username = getlogin(); |
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
182 if (input.username == NULL) |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
183 i_fatal("USER environment missing"); |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
184 } |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
185 if ((value = getenv("IP")) != NULL) |
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
186 net_addr2ip(value, &input.remote_ip); |
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
187 if ((value = getenv("LOCAL_IP")) != NULL) |
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
188 net_addr2ip(value, &input.local_ip); |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
189 |
9147
bf448752f6c4
Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents:
9106
diff
changeset
|
190 mail_user = mail_storage_service_init_user(service, &input, set_roots, |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
191 storage_service_flags); |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
192 set = mail_storage_service_get_settings(service); |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
193 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
|
194 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 process_title_init(argv, envp); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
197 /* fake that we're running, so we know if client was destroyed |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
198 while initializing */ |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
199 io_loop_set_running(current_ioloop); |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
200 |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
201 if (main_init(set, mail_user)) |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
202 master_service_run(service); |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
203 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 main_deinit(); |
9080
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
205 mail_storage_service_deinit_user(); |
e560b92ed763
imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents:
9059
diff
changeset
|
206 master_service_deinit(&service); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 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
|
208 } |