Mercurial > dovecot > core-2.2
annotate src/lmtp/main.c @ 10119:1e63221f5c83 HEAD
Moved most of getopt() handling to lib-master.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 20 Oct 2009 20:07:45 -0400 |
parents | ddcc3391adf9 |
children | b584904d3bc7 |
rev | line source |
---|---|
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */ |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "array.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "ioloop.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "restrict-access.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "fd-close-on-exec.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "process-title.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "master-service.h" |
10039
ddcc3391adf9
lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
10 #include "master-service-settings.h" |
9350
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
11 #include "master-interface.h" |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "mail-storage-service.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "lda-settings.h" |
10039
ddcc3391adf9
lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
14 #include "lmtp-settings.h" |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #include "client.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include "main.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #include <stdlib.h> |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #include <unistd.h> |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 #define LMTP_MASTER_FIRST_LISTEN_FD 3 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 #define IS_STANDALONE() \ |
9350
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
24 (getenv(MASTER_UID_ENV) == NULL) |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 struct mail_storage_service_multi_ctx *multi_service; |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
28 static void client_connected(const struct master_service_connection *conn) |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 { |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 struct client *client; |
10039
ddcc3391adf9
lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
31 void **sets; |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 |
9350
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
33 client = client_create(conn->fd, conn->fd); |
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
34 client->remote_ip = conn->remote_ip; |
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
35 client->remote_port = conn->remote_port; |
10039
ddcc3391adf9
lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
36 |
ddcc3391adf9
lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
37 sets = master_service_settings_get_others(master_service); |
ddcc3391adf9
lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
38 client->set = sets[1]; |
ddcc3391adf9
lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
39 client->lmtp_set = sets[2]; |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 |
9350
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
41 (void)net_getsockname(conn->fd, &client->local_ip, &client->local_port); |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 } |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 static void main_init(void) |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 { |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
46 if (IS_STANDALONE()) |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 (void)client_create(STDIN_FILENO, STDOUT_FILENO); |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 } |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 static void main_deinit(void) |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 { |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 clients_destroy(); |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 } |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 int main(int argc, char *argv[], char *envp[]) |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 { |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 const struct setting_parser_info *set_roots[] = { |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 &lda_setting_parser_info, |
10039
ddcc3391adf9
lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
59 &lmtp_setting_parser_info, |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 NULL |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 }; |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 enum master_service_flags service_flags = 0; |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 enum mail_storage_service_flags storage_service_flags = |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT | |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
67 if (IS_STANDALONE()) { |
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
68 service_flags |= MASTER_SERVICE_FLAG_STANDALONE | |
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
69 MASTER_SERVICE_FLAG_STD_CLIENT; |
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
70 } |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 |
10119
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10039
diff
changeset
|
72 master_service = master_service_init("lmtp", service_flags, |
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10039
diff
changeset
|
73 argc, argv, NULL); |
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10039
diff
changeset
|
74 if (master_getopt(master_service) > 0) |
1e63221f5c83
Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
10039
diff
changeset
|
75 return FATAL_DEFAULT; |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
77 multi_service = mail_storage_service_multi_init(master_service, |
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
78 set_roots, |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 storage_service_flags); |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 restrict_access_allow_coredumps(TRUE); |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 process_title_init(argv, envp); |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 main_init(); |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
85 master_service_run(master_service, client_connected); |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 main_deinit(); |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 mail_storage_service_multi_deinit(&multi_service); |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
89 master_service_deinit(&master_service); |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 return 0; |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 } |