Mercurial > dovecot > core-2.2
annotate src/lmtp/main.c @ 9350:7df8fddbc7a5 HEAD
Fixed LMTP server to actualy work.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 22 May 2009 17:40:49 -0400 |
parents | 0c587f108916 |
children | 3a16bec9c961 |
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" |
9350
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
10 #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
|
11 #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
|
12 #include "lda-settings.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 "client.h" |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #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
|
15 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #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
|
17 #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
|
18 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #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
|
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 IS_STANDALONE() \ |
9350
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
22 (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
|
23 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 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
|
25 |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
26 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
|
27 { |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 struct client *client; |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
9350
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
30 client = client_create(conn->fd, conn->fd); |
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
31 client->remote_ip = conn->remote_ip; |
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
32 client->remote_port = conn->remote_port; |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
9350
7df8fddbc7a5
Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents:
9348
diff
changeset
|
34 (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
|
35 } |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 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
|
38 { |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
39 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
|
40 (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
|
41 } |
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 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
|
44 { |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 clients_destroy(); |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 } |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 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
|
49 { |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 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
|
51 &lda_setting_parser_info, |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 NULL |
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 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
|
55 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
|
56 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
|
57 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
|
58 int c; |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 } |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
65 master_service = master_service_init("lmtp", service_flags, argc, argv); |
9121
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) { |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
67 if (!master_service_parse_option(master_service, c, optarg)) |
9159
6324a79d3ee1
Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents:
9121
diff
changeset
|
68 exit(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
|
69 } |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 |
9348
0c587f108916
lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents:
9159
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 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
|
77 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 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
|
79 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
|
80 |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 main_deinit(); |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 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
|
83 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
|
84 return 0; |
a957a6be4af5
Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 } |