annotate src/lmtp/main.c @ 10582:615eef3139c2 HEAD

Updated copyright notices to include year 2010.
author Timo Sirainen <tss@iki.fi>
date Mon, 25 Jan 2010 01:19:08 +0200
parents 569206178c09
children cc3f6adc1e0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10582
615eef3139c2 Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents: 10498
diff changeset
1 /* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
9121
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"
10257
597f969a9870 lmtp: Improved logging.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
6 #include "hostpid.h"
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #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
8 #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
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
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10127
diff changeset
26 struct mail_storage_service_ctx *storage_service;
9121
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 {
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
30 (void)client_create(conn->fd, conn->fd, conn);
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 }
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 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
34 {
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
35 struct master_service_connection conn;
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
36
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
37 if (IS_STANDALONE()) {
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
38 memset(&conn, 0, sizeof(conn));
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
39 (void)client_create(STDIN_FILENO, STDOUT_FILENO, &conn);
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
40 }
9121
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
10120
b584904d3bc7 Moved process title init to lib-master. With Linux-hack enabled it now preserves command args.
Timo Sirainen <tss@iki.fi>
parents: 10119
diff changeset
48 int main(int argc, char *argv[])
9121
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,
10039
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
52 &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
53 NULL
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 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
56 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
57 MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT |
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
58 MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP |
10257
597f969a9870 lmtp: Improved logging.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
59 MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP |
10498
569206178c09 mail storage service: Some flag enums were missing FLAG_ in the middle.
Timo Sirainen <tss@iki.fi>
parents: 10497
diff changeset
60 MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT |
10497
3907cc4ecc4b Idle-disconnecting auth master connections is now optional. LMTP no longer does it.
Timo Sirainen <tss@iki.fi>
parents: 10364
diff changeset
61 MAIL_STORAGE_SERVICE_FLAG_NO_IDLE_TIMEOUT;
10364
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
62 int c;
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63
9159
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9121
diff changeset
64 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
65 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
66 MASTER_SERVICE_FLAG_STD_CLIENT;
10259
e0db66c8b9a9 lmtp: Keep connection to config process open.
Timo Sirainen <tss@iki.fi>
parents: 10257
diff changeset
67 } else {
e0db66c8b9a9 lmtp: Keep connection to config process open.
Timo Sirainen <tss@iki.fi>
parents: 10257
diff changeset
68 service_flags |= MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN;
9159
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9121
diff changeset
69 }
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70
10119
1e63221f5c83 Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents: 10039
diff changeset
71 master_service = master_service_init("lmtp", service_flags,
10364
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
72 &argc, &argv, "D");
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
73 while ((c = master_getopt(master_service)) > 0) {
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
74 switch (c) {
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
75 case 'D':
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
76 storage_service_flags |=
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
77 MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS;
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
78 break;
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
79 default:
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
80 return FATAL_DEFAULT;
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
81 }
4183f16e6f60 lmtp: If -D parameter is given, enable core dumps.
Timo Sirainen <tss@iki.fi>
parents: 10259
diff changeset
82 }
10127
9c640a1eb8b6 lmtp: Fixed crashing caused by recent API changes.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
83 master_service_init_finish(master_service);
10257
597f969a9870 lmtp: Improved logging.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
84 master_service_init_log(master_service,
597f969a9870 lmtp: Improved logging.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
85 t_strdup_printf("lmtp(%s): ", my_pid));
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10127
diff changeset
87 storage_service = mail_storage_service_init(master_service, set_roots,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10127
diff changeset
88 storage_service_flags);
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 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
90
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 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
92 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
93
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 main_deinit();
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10127
diff changeset
95 mail_storage_service_deinit(&storage_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
96 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
97 return 0;
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 }