Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/main.c @ 5589:271c35971331 HEAD
Print also Dovecot version with dovecot -n.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 11 May 2007 16:29:25 +0300 |
parents | 2704fc574e70 |
children | b02af502bcd6 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "common.h" | |
4 #include "ioloop.h" | |
5 #include "lib-signals.h" | |
6 #include "network.h" | |
697
7814b29d0862
Created env_put() and env_clean() for a bit easier handling of environment
Timo Sirainen <tss@iki.fi>
parents:
635
diff
changeset
|
7 #include "env-util.h" |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
697
diff
changeset
|
8 #include "fd-close-on-exec.h" |
2524 | 9 #include "write-full.h" |
0 | 10 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
11 #include "askpass.h" |
0 | 12 #include "auth-process.h" |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
13 #include "dict-process.h" |
0 | 14 #include "login-process.h" |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
15 #include "mail-process.h" |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
16 #include "syslog-util.h" |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
17 #include "ssl-init.h" |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
18 #include "log.h" |
0 | 19 |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
20 #include <stdio.h> |
0 | 21 #include <stdlib.h> |
22 #include <unistd.h> | |
23 #include <fcntl.h> | |
24 #include <syslog.h> | |
25 #include <sys/stat.h> | |
26 #include <sys/wait.h> | |
5201
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
27 #ifdef HAVE_LIBCAP |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
28 #include <sys/capability.h> |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
29 #endif |
0 | 30 |
31 const char *process_names[PROCESS_TYPE_MAX] = { | |
32 "unknown", | |
33 "auth", | |
3166
e6a487d80288
Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents:
3075
diff
changeset
|
34 "auth-worker", |
0 | 35 "login", |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
36 "imap", |
1358
70b60399c7d3
Separate PROCESS_TYPE_MAIL into IMAP and POP3.
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
37 "pop3", |
3989
e93e39326ae1
Added ssl-build-param binary to build the ssl-parameters.dat. This way
Timo Sirainen <tss@iki.fi>
parents:
3966
diff
changeset
|
38 "ssl-build-param", |
3966
19dcfd289610
Added missing "dict" to process names
Timo Sirainen <tss@iki.fi>
parents:
3919
diff
changeset
|
39 "dict" |
0 | 40 }; |
41 | |
5201
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
42 /* the capabilities that we *need* in order to operate */ |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
43 #ifdef HAVE_LIBCAP |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
44 cap_t caps; |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
45 cap_value_t suidcaps[] = { |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
46 CAP_CHOWN, |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
47 CAP_SYS_CHROOT, |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
48 CAP_SETUID, |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
49 CAP_SETGID, |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
50 CAP_NET_BIND_SERVICE |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
51 }; |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
52 #endif |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
53 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
54 static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf"; |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
55 static const char *env_tz; |
0 | 56 |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
57 struct ioloop *ioloop; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
867
diff
changeset
|
58 struct hash_table *pids; |
5432
2b4fa90860dd
Before unlinking auth sockets at startup, try connecting to them first to
Timo Sirainen <tss@iki.fi>
parents:
5333
diff
changeset
|
59 int null_fd = -1, inetd_login_fd; |
1617
cc3cef25662c
Replaced geteuid() calls with one in the beginning and saving it to
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
60 uid_t master_uid; |
3989
e93e39326ae1
Added ssl-build-param binary to build the ssl-parameters.dat. This way
Timo Sirainen <tss@iki.fi>
parents:
3966
diff
changeset
|
61 char program_path[PATH_MAX]; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
62 char ssl_manual_key_password[100]; |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
63 #ifdef DEBUG |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
64 static bool gdb; |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
65 #endif |
0 | 66 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
67 static void listen_fds_open(bool retry); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
68 static void listen_fds_close(struct server_settings *server); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
69 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
70 bool validate_str(const char *str, size_t max_len) |
0 | 71 { |
810
30f6811f4952
Instead of just trusting randomness of authentication cookies between
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
72 size_t i; |
0 | 73 |
74 for (i = 0; i < max_len; i++) { | |
75 if (str[i] == '\0') | |
76 return TRUE; | |
77 } | |
78 | |
79 return FALSE; | |
80 } | |
81 | |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
82 void child_process_init_env(void) |
0 | 83 { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
84 int facility; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
85 |
0 | 86 /* remove all environment, we don't need them */ |
697
7814b29d0862
Created env_put() and env_clean() for a bit easier handling of environment
Timo Sirainen <tss@iki.fi>
parents:
635
diff
changeset
|
87 env_clean(); |
0 | 88 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
89 /* we'll log through master process */ |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
90 env_put("LOG_TO_MASTER=1"); |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
91 if (env_tz != NULL) |
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
92 env_put(t_strconcat("TZ=", env_tz, NULL)); |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
93 |
4197
c3ded5b815aa
If we have plugins set and imap_capability unset, figure out the IMAP
Timo Sirainen <tss@iki.fi>
parents:
4138
diff
changeset
|
94 if (settings_root == NULL || |
c3ded5b815aa
If we have plugins set and imap_capability unset, figure out the IMAP
Timo Sirainen <tss@iki.fi>
parents:
4138
diff
changeset
|
95 !syslog_facility_find(settings_root->defaults->syslog_facility, |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
96 &facility)) |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
97 facility = LOG_MAIL; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
98 env_put(t_strdup_printf("SYSLOG_FACILITY=%d", facility)); |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
99 |
4553
d1c0514754d5
Require that master's version number matches the child's, unless
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
100 if (settings_root != NULL && !settings_root->defaults->version_ignore) |
d1c0514754d5
Require that master's version number matches the child's, unless
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
101 env_put("DOVECOT_VERSION="PACKAGE_VERSION); |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
102 #ifdef DEBUG |
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
103 if (gdb) env_put("GDB=1"); |
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
104 #endif |
0 | 105 } |
106 | |
2886
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
107 void client_process_exec(const char *cmd, const char *title) |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
108 { |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
109 const char *executable, *p, **argv; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
110 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
111 /* very simple argument splitting. */ |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
112 if (*title == '\0') |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
113 argv = t_strsplit(cmd, " "); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
114 else |
2898 | 115 argv = t_strsplit(t_strconcat(cmd, " ", title, NULL), " "); |
2886
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
116 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
117 executable = argv[0]; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
118 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
119 /* hide the path, it's ugly */ |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
120 p = strrchr(argv[0], '/'); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
121 if (p != NULL) argv[0] = p+1; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
122 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
123 execv(executable, (char **)argv); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
124 } |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
125 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
126 static void set_logfile(struct settings *set) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
127 { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
128 int facility; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
129 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
130 if (*set->log_path == '\0') { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
131 if (!syslog_facility_find(set->syslog_facility, &facility)) |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
132 facility = LOG_MAIL; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
133 |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
134 i_set_failure_syslog("dovecot", LOG_NDELAY, facility); |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
135 } else { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
136 /* log to file or stderr */ |
5333
55260092b094
Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents:
5249
diff
changeset
|
137 i_set_failure_file(set->log_path, "dovecot: "); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
138 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
139 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
140 if (*set->info_log_path != '\0') |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
141 i_set_info_file(set->info_log_path); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
142 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
143 i_set_failure_timestamp_format(set->log_timestamp); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
144 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
145 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
146 static void settings_reload(void) |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
147 { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
148 struct server_settings *old_set = settings_root; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
149 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
150 i_warning("SIGHUP received - reloading configuration"); |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
151 |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
152 /* restart auth and login processes */ |
4670 | 153 login_processes_destroy_all(); |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
154 auth_processes_destroy_all(); |
4393
9928ebb54719
Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
155 dict_process_kill(); |
1223
52e0830ade13
Added setting mail_drop_priv_before_exec.
Timo Sirainen <tss@iki.fi>
parents:
1124
diff
changeset
|
156 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
157 if (!master_settings_read(configfile, FALSE, FALSE)) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
158 i_warning("Invalid configuration, keeping old one"); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
159 else { |
4355
3af32babd71b
If running from inetd, don't try to open/close listener sockets when
Timo Sirainen <tss@iki.fi>
parents:
4326
diff
changeset
|
160 if (!IS_INETD()) { |
3af32babd71b
If running from inetd, don't try to open/close listener sockets when
Timo Sirainen <tss@iki.fi>
parents:
4326
diff
changeset
|
161 listen_fds_close(old_set); |
3af32babd71b
If running from inetd, don't try to open/close listener sockets when
Timo Sirainen <tss@iki.fi>
parents:
4326
diff
changeset
|
162 listen_fds_open(TRUE); |
3af32babd71b
If running from inetd, don't try to open/close listener sockets when
Timo Sirainen <tss@iki.fi>
parents:
4326
diff
changeset
|
163 } |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
164 set_logfile(settings_root->defaults); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
165 } |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
166 } |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
167 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
168 static void sig_die(int signo, void *context __attr_unused__) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
169 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
170 /* warn about being killed because of some signal, except SIGINT (^C) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
171 which is too common at least while testing :) */ |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
172 if (signo != SIGINT) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
173 i_warning("Killed with signal %d", signo); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
174 io_loop_stop(ioloop); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
175 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
176 |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
177 static void sig_reload_settings(int signo __attr_unused__, |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
178 void *context __attr_unused__) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
179 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
180 settings_reload(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
181 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
182 |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
183 static void sig_reopen_logs(int signo __attr_unused__, |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
184 void *context __attr_unused__) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
185 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
186 set_logfile(settings_root->defaults); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
187 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
188 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
867
diff
changeset
|
189 static const char *get_exit_status_message(enum fatal_exit_status status) |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
190 { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
191 switch (status) { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
192 case FATAL_LOGOPEN: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
193 return "Can't open log file"; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
194 case FATAL_LOGWRITE: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
195 return "Can't write to log file"; |
867
e1656057b9a5
Forgot to handle FATAL_LOGERROR.
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
196 case FATAL_LOGERROR: |
e1656057b9a5
Forgot to handle FATAL_LOGERROR.
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
197 return "Internal logging error"; |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
198 case FATAL_OUTOFMEM: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
199 return "Out of memory"; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
200 case FATAL_EXEC: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
201 return "exec() failed"; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
202 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
203 case FATAL_DEFAULT: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
204 return NULL; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
205 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
206 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
207 return NULL; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
208 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
209 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
210 static void sigchld_handler(int signo __attr_unused__, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
211 void *context __attr_unused__) |
0 | 212 { |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
213 const char *process_type_name, *msg; |
0 | 214 pid_t pid; |
215 int status, process_type; | |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
216 bool abnormal_exit; |
0 | 217 |
218 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { | |
219 /* get the type and remove from hash */ | |
220 process_type = PID_GET_PROCESS_TYPE(pid); | |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
221 if (process_type != PROCESS_TYPE_UNKNOWN) |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
222 PID_REMOVE_PROCESS_TYPE(pid); |
0 | 223 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
224 abnormal_exit = TRUE; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
225 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
226 /* write errors to syslog */ |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
227 process_type_name = process_names[process_type]; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
228 if (WIFEXITED(status)) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
229 status = WEXITSTATUS(status); |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
230 if (status == 0) { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
231 abnormal_exit = FALSE; |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
232 if (process_type == PROCESS_TYPE_UNKNOWN) { |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
233 i_error("unknown child %s exited " |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
234 "successfully", dec2str(pid)); |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
235 } |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
236 } else { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
237 msg = get_exit_status_message(status); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
238 msg = msg == NULL ? "" : |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
239 t_strconcat(" (", msg, ")", NULL); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
240 i_error("child %s (%s) returned error %d%s", |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
241 dec2str(pid), process_type_name, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
242 status, msg); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
243 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
244 } else if (WIFSIGNALED(status)) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
245 i_error("child %s (%s) killed with signal %d", |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
246 dec2str(pid), process_type_name, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
247 WTERMSIG(status)); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
248 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
249 |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
250 switch (process_type) { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
251 case PROCESS_TYPE_LOGIN: |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
252 login_process_destroyed(pid, abnormal_exit); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
253 break; |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
254 case PROCESS_TYPE_IMAP: |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
255 case PROCESS_TYPE_POP3: |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
256 mail_process_destroyed(pid); |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
257 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
258 case PROCESS_TYPE_SSL_PARAM: |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
259 ssl_parameter_process_destroyed(pid); |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
260 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
261 case PROCESS_TYPE_DICT: |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
262 dict_process_restart(); |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
263 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
264 } |
0 | 265 } |
266 | |
267 if (pid == -1 && errno != EINTR && errno != ECHILD) | |
268 i_warning("waitpid() failed: %m"); | |
269 } | |
270 | |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
271 static void resolve_ip(const char *set_name, const char *name, |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
272 struct ip_addr *ip, unsigned int *port) |
0 | 273 { |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
274 struct ip_addr *ip_list; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
275 const char *p; |
4745
7ee0bb1b2d97
Changed ips_count to unsigned int in net_gethostbyname(). Also removed
Timo Sirainen <tss@iki.fi>
parents:
4670
diff
changeset
|
276 unsigned int ips_count; |
7ee0bb1b2d97
Changed ips_count to unsigned int in net_gethostbyname(). Also removed
Timo Sirainen <tss@iki.fi>
parents:
4670
diff
changeset
|
277 int ret; |
0 | 278 |
4326
e228a9efd35d
If ssl_listen setting was empty in config file, startup failed with "Can't
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
279 if (*name == '\0') { |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
280 /* defaults to "*" or "[::]" */ |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
281 ip->family = 0; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
282 return; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
283 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
284 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
285 if (name[0] == '[') { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
286 /* IPv6 address */ |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
287 p = strchr(name, ']'); |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
288 if (p == NULL) { |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
289 i_fatal("%s: Missing ']' in address %s", |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
290 set_name, name); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
291 } |
1100
95d2f3e60b82
[ipv6 address] didn't work in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1058
diff
changeset
|
292 name = t_strdup_until(name+1, p); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
293 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
294 p++; |
1228
4e438a5c00d3
[ipv6 address] was still buggy in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1223
diff
changeset
|
295 if (*p == '\0') |
4e438a5c00d3
[ipv6 address] was still buggy in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1223
diff
changeset
|
296 p = NULL; |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
297 else if (*p != ':') { |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
298 i_fatal("%s: Invalid data after ']' in address %s", |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
299 set_name, name); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
300 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
301 } else { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
302 p = strrchr(name, ':'); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
303 if (p != NULL) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
304 name = t_strdup_until(name, p); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
305 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
306 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
307 if (p != NULL) { |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
308 if (!is_numeric(p+1, '\0')) { |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
309 i_fatal("%s: Invalid port in address %s", |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
310 set_name, name); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
311 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
312 *port = atoi(p+1); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
313 } |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
314 |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
315 if (strcmp(name, "*") == 0) { |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
316 /* IPv4 any */ |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
317 net_get_ip_any4(ip); |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
318 return; |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
319 } |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
320 |
1261
5373999355ed
[::] address wasn't treated exactly as "ipv6 any", but looks like
Timo Sirainen <tss@iki.fi>
parents:
1260
diff
changeset
|
321 if (strcmp(name, "::") == 0) { |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
322 /* IPv6 any */ |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
323 net_get_ip_any6(ip); |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
324 return; |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
325 } |
0 | 326 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
327 /* Return the first IP if there happens to be multiple. */ |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
328 ret = net_gethostbyname(name, &ip_list, &ips_count); |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
329 if (ret != 0) { |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
330 i_fatal("%s: Can't resolve address %s: %s", |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
331 set_name, name, net_gethosterror(ret)); |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
332 } |
0 | 333 |
334 if (ips_count < 1) | |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
335 i_fatal("%s: No IPs for address: %s", set_name, name); |
0 | 336 |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
337 *ip = ip_list[0]; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
338 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
339 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
340 static void |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
341 check_conflicts_set(const struct settings *set, const struct ip_addr *ip, |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
342 unsigned int port, const char *name1, const char *name2) |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
343 { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
344 if (set->listen_port == port && net_ip_compare(ip, &set->listen_ip) && |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
345 set->listen_fd > 0) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
346 i_fatal("Protocols %s and %s are listening in same ip/port", |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
347 name1, name2); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
348 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
349 if (set->ssl_listen_port == port && |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
350 net_ip_compare(ip, &set->ssl_listen_ip) && set->ssl_listen_fd > 0) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
351 i_fatal("Protocols %ss and %s are listening in same ip/port", |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
352 name1, name2); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
353 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
354 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
355 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
356 static void check_conflicts(const struct ip_addr *ip, unsigned int port, |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
357 const char *proto) |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
358 { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
359 struct server_settings *server; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
360 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
361 for (server = settings_root; server != NULL; server = server->next) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
362 if (server->imap != NULL) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
363 check_conflicts_set(server->imap, ip, port, |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
364 "imap", proto); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
365 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
366 if (server->pop3 != NULL) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
367 check_conflicts_set(server->pop3, ip, port, |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
368 "pop3", proto); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
369 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
370 } |
0 | 371 } |
372 | |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
373 static void listen_protocols(struct settings *set, bool retry) |
0 | 374 { |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
375 struct ip_addr *ip; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
376 const char *const *proto; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
377 unsigned int port; |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
378 int *fd, i; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
379 |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
380 set->listen_port = set->protocol == MAIL_PROTOCOL_IMAP ? 143 : 110; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
381 #ifdef HAVE_SSL |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
382 set->ssl_listen_port = set->protocol == MAIL_PROTOCOL_IMAP ? 993 : 995; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
383 #else |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
384 set->ssl_listen_port = 0; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
385 #endif |
0 | 386 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
387 /* resolve */ |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
388 resolve_ip("listen", set->listen, &set->listen_ip, &set->listen_port); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
389 if (!set->ssl_disable) { |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
390 resolve_ip("ssl_listen", set->ssl_listen, &set->ssl_listen_ip, |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
391 &set->ssl_listen_port); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
392 } |
0 | 393 |
4375
4fa4d1d299d3
We broke if ssl_listen wasn't explicitly set in config file. Patch by
Timo Sirainen <tss@iki.fi>
parents:
4355
diff
changeset
|
394 /* if ssl_listen wasn't explicitly set in the config file, |
4fa4d1d299d3
We broke if ssl_listen wasn't explicitly set in config file. Patch by
Timo Sirainen <tss@iki.fi>
parents:
4355
diff
changeset
|
395 use the non-ssl IP settings for the ssl listener, too. */ |
4fa4d1d299d3
We broke if ssl_listen wasn't explicitly set in config file. Patch by
Timo Sirainen <tss@iki.fi>
parents:
4355
diff
changeset
|
396 if (set->ssl_listen_ip.family == 0 && *set->ssl_listen == '\0') |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
397 set->ssl_listen_ip = set->listen_ip; |
0 | 398 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
399 /* register wanted protocols */ |
1820 | 400 proto = t_strsplit_spaces(set->protocols, " "); |
401 for (; *proto != NULL; proto++) { | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
402 fd = NULL; ip = NULL; port = 0; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
403 if (strcasecmp(*proto, "imap") == 0) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
404 if (set->protocol == MAIL_PROTOCOL_IMAP) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
405 fd = &set->listen_fd; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
406 port = set->listen_port; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
407 ip = &set->listen_ip; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
408 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
409 } else if (strcasecmp(*proto, "imaps") == 0) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
410 if (set->protocol == MAIL_PROTOCOL_IMAP && |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
411 !set->ssl_disable) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
412 fd = &set->ssl_listen_fd; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
413 port = set->ssl_listen_port; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
414 ip = &set->ssl_listen_ip; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
415 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
416 } else if (strcasecmp(*proto, "pop3") == 0) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
417 if (set->protocol == MAIL_PROTOCOL_POP3) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
418 fd = &set->listen_fd; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
419 port = set->listen_port; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
420 ip = &set->listen_ip; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
421 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
422 } else if (strcasecmp(*proto, "pop3s") == 0) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
423 if (set->protocol == MAIL_PROTOCOL_POP3 && |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
424 !set->ssl_disable) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
425 fd = &set->ssl_listen_fd; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
426 port = set->ssl_listen_port; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
427 ip = &set->ssl_listen_ip; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
428 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
429 } else { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
430 i_fatal("Unknown protocol %s", *proto); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
431 } |
0 | 432 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
433 if (fd == NULL) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
434 continue; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
435 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
436 if (*fd != -1) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
437 i_fatal("Protocol %s given more than once", *proto); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
438 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
439 if (port == 0) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
440 *fd = null_fd; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
441 else { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
442 for (i = 0; i < 10; i++) { |
3075
9cb91ed5a110
Added backlog parameter for net_listen*().
Timo Sirainen <tss@iki.fi>
parents:
2898
diff
changeset
|
443 *fd = net_listen(ip, &port, 8); |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
444 if (*fd != -1) |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
445 break; |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
446 if (errno == EADDRINUSE) { |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
447 /* retry */ |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
448 } else if (errno == EINTR && |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
449 io_loop_is_running(ioloop)) { |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
450 /* SIGHUPing sometimes gets us here. |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
451 we don't want to die. */ |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
452 } else { |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
453 /* error */ |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
454 break; |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
455 } |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
456 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
457 check_conflicts(ip, port, *proto); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
458 if (!retry) |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
459 break; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
460 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
461 /* wait a while and try again. we're SIGHUPing |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
462 so we most likely just closed it ourself.. */ |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
463 sleep(1); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
464 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
465 |
1423
3e73d02e5f71
Don't try to set /dev/null fd nonblocking, all systems don't like that.
Timo Sirainen <tss@iki.fi>
parents:
1367
diff
changeset
|
466 if (*fd == -1) |
3e73d02e5f71
Don't try to set /dev/null fd nonblocking, all systems don't like that.
Timo Sirainen <tss@iki.fi>
parents:
1367
diff
changeset
|
467 i_fatal("listen(%d) failed: %m", port); |
3e73d02e5f71
Don't try to set /dev/null fd nonblocking, all systems don't like that.
Timo Sirainen <tss@iki.fi>
parents:
1367
diff
changeset
|
468 net_set_nonblock(*fd, TRUE); |
4578
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
469 fd_close_on_exec(*fd, TRUE); |
1423
3e73d02e5f71
Don't try to set /dev/null fd nonblocking, all systems don't like that.
Timo Sirainen <tss@iki.fi>
parents:
1367
diff
changeset
|
470 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
471 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
472 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
473 if (set->listen_fd == -1) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
474 set->listen_fd = null_fd; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
475 if (set->ssl_listen_fd == -1) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
476 set->ssl_listen_fd = null_fd; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
477 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
478 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
479 static void listen_fds_open(bool retry) |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
480 { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
481 struct server_settings *server; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
482 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
483 for (server = settings_root; server != NULL; server = server->next) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
484 if (server->imap != NULL) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
485 listen_protocols(server->imap, retry); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
486 if (server->pop3 != NULL) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
487 listen_protocols(server->pop3, retry); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
488 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
489 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
490 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
491 static void listen_fds_close(struct server_settings *server) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
492 { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
493 for (; server != NULL; server = server->next) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
494 if (server->imap != NULL) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
495 if (server->imap->listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
496 close(server->imap->listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
497 i_error("close(imap.listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
498 if (server->imap->ssl_listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
499 close(server->imap->ssl_listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
500 i_error("close(imap.ssl_listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
501 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
502 if (server->pop3 != NULL) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
503 if (server->pop3->listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
504 close(server->pop3->listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
505 i_error("close(pop3.listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
506 if (server->pop3->ssl_listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
507 close(server->pop3->ssl_listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
508 i_error("close(pop3.ssl_listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
509 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
510 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
511 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
512 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
513 static bool have_stderr_set(struct settings *set) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
514 { |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
515 if (*set->log_path != '\0' && |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
516 strcmp(set->log_path, "/dev/stderr") == 0) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
517 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
518 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
519 if (*set->info_log_path != '\0' && |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
520 strcmp(set->info_log_path, "/dev/stderr") == 0) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
521 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
522 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
523 return FALSE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
524 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
525 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
526 static bool have_stderr(struct server_settings *server) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
527 { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
528 while (server != NULL) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
529 if (server->imap != NULL && have_stderr_set(server->imap)) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
530 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
531 if (server->pop3 != NULL && have_stderr_set(server->pop3)) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
532 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
533 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
534 server = server->next; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
535 } |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
536 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
537 return FALSE; |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
538 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
539 |
5437 | 540 static void open_null_fd(void) |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
541 { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
542 null_fd = open("/dev/null", O_RDONLY); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
543 if (null_fd == -1) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
544 i_fatal("Can't open /dev/null: %m"); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
545 fd_close_on_exec(null_fd, TRUE); |
5437 | 546 } |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
547 |
5437 | 548 static void open_fds(void) |
549 { | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
550 /* make sure all fds between 0..3 are used. */ |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
551 while (null_fd < 4) { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
552 null_fd = dup(null_fd); |
4578
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
553 if (null_fd == -1) |
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
554 i_fatal("dup(null_fd) failed: %m"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
555 fd_close_on_exec(null_fd, TRUE); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
556 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
557 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
558 if (!IS_INETD()) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
559 listen_fds_open(FALSE); |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
560 |
4477
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
561 /* close stdin and stdout. */ |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
562 if (dup2(null_fd, 0) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
563 i_fatal("dup2(0) failed: %m"); |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
564 if (dup2(null_fd, 1) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
565 i_fatal("dup2(1) failed: %m"); |
0 | 566 } |
567 | |
2524 | 568 static void create_pid_file(const char *path) |
569 { | |
570 const char *pid; | |
571 int fd; | |
572 | |
2534 | 573 pid = t_strconcat(dec2str(getpid()), "\n", NULL); |
2524 | 574 |
575 fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644); | |
576 if (fd == -1) | |
577 i_fatal("open(%s) failed: %m", path); | |
578 if (write_full(fd, pid, strlen(pid)) < 0) | |
579 i_fatal("write() failed in %s: %m", path); | |
580 (void)close(fd); | |
581 } | |
582 | |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
583 static void main_init(bool log_error) |
0 | 584 { |
585 /* deny file access from everyone else except owner */ | |
586 (void)umask(0077); | |
587 | |
4477
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
588 /* close stderr unless we're logging into /dev/stderr. keep as little |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
589 distance between closing it and opening the actual log file so that |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
590 we don't lose anything. */ |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
591 if (!have_stderr(settings_root)) { |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
592 if (dup2(null_fd, 2) < 0) |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
593 i_fatal("dup2(2) failed: %m"); |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
594 } |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
595 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
596 set_logfile(settings_root->defaults); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
597 i_info("Dovecot v"VERSION" starting up"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
598 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
599 log_init(); |
0 | 600 |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
601 if (log_error) |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
602 i_fatal("This is Dovecot's error log"); |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
603 |
5201
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
604 #ifdef HAVE_LIBCAP |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
605 /* drop capabilities that we don't need, be very restrictive. */ |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
606 caps = cap_init(); |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
607 cap_clear(caps); |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
608 cap_set_flag(caps, CAP_PERMITTED, |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
609 sizeof(suidcaps) / sizeof(cap_value_t), suidcaps, CAP_SET); |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
610 cap_set_flag(caps, CAP_EFFECTIVE, |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
611 sizeof(suidcaps) / sizeof(cap_value_t), suidcaps, CAP_SET); |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
612 cap_set_proc(caps); |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
613 cap_free(caps); |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
614 #endif |
8920e744dac4
Drop privileges if libcap is found. Patch by David (lists edeca.net).
Timo Sirainen <tss@iki.fi>
parents:
5090
diff
changeset
|
615 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
616 lib_signals_init(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
617 lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
618 lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL); |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4745
diff
changeset
|
619 lib_signals_ignore(SIGPIPE, TRUE); |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4745
diff
changeset
|
620 lib_signals_ignore(SIGALRM, FALSE); |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
621 lib_signals_set_handler(SIGHUP, TRUE, sig_reload_settings, NULL); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
622 lib_signals_set_handler(SIGUSR1, TRUE, sig_reopen_logs, NULL); |
0 | 623 |
945
501f076f2e74
Rewrote hash table code, works with less memory now. Also some memory
Timo Sirainen <tss@iki.fi>
parents:
926
diff
changeset
|
624 pids = hash_create(default_pool, default_pool, 128, NULL, NULL); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
625 lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, NULL); |
0 | 626 |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
627 ssl_init(); |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
628 dict_process_init(); |
0 | 629 auth_processes_init(); |
630 login_processes_init(); | |
2524 | 631 |
632 create_pid_file(t_strconcat(settings_root->defaults->base_dir, | |
633 "/master.pid", NULL)); | |
0 | 634 } |
635 | |
636 static void main_deinit(void) | |
637 { | |
2524 | 638 (void)unlink(t_strconcat(settings_root->defaults->base_dir, |
639 "/master.pid", NULL)); | |
640 | |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
641 /* make sure we log if child processes died unexpectedly */ |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
642 sigchld_handler(SIGCHLD, NULL); |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
643 |
0 | 644 login_processes_deinit(); |
645 auth_processes_deinit(); | |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
646 dict_process_deinit(); |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
647 ssl_deinit(); |
0 | 648 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
649 lib_signals_unset_handler(SIGCHLD, sigchld_handler, NULL); |
0 | 650 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
651 if (close(null_fd) < 0) |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
652 i_error("close(null_fd) failed: %m"); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
653 |
0 | 654 hash_destroy(pids); |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
655 lib_signals_deinit(); |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
656 log_deinit(); |
0 | 657 closelog(); |
658 } | |
659 | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
660 static void daemonize(struct settings *set) |
0 | 661 { |
662 pid_t pid; | |
663 | |
664 pid = fork(); | |
665 if (pid < 0) | |
666 i_fatal("fork() failed: %m"); | |
667 | |
668 if (pid != 0) | |
669 _exit(0); | |
610 | 670 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
671 if (setsid() < 0) |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
672 i_fatal("setsid() failed: %m"); |
1367
533bb936e674
chdir() to base_dir at startup. chdir() mail processes to home dir if it's
Timo Sirainen <tss@iki.fi>
parents:
1358
diff
changeset
|
673 |
533bb936e674
chdir() to base_dir at startup. chdir() mail processes to home dir if it's
Timo Sirainen <tss@iki.fi>
parents:
1358
diff
changeset
|
674 if (chdir(set->base_dir) < 0) |
533bb936e674
chdir() to base_dir at startup. chdir() mail processes to home dir if it's
Timo Sirainen <tss@iki.fi>
parents:
1358
diff
changeset
|
675 i_fatal("chdir(%s) failed: %m", set->base_dir); |
0 | 676 } |
677 | |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
678 static void print_help(void) |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
679 { |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
680 printf( |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
681 "Usage: dovecot [-F] [-c <config file>] [-p] [-n] [-a]\n" |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
682 " [--exec-mail <protocol>] [--version] [--build-options]\n"); |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
683 } |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
684 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
685 static void print_build_options(void) |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
686 { |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
687 printf("Build options:" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
688 #ifdef IOLOOP_EPOLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
689 " ioloop=epoll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
690 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
691 #ifdef IOLOOP_KQUEUE |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
692 " ioloop=kqueue" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
693 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
694 #ifdef IOLOOP_POLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
695 " ioloop=poll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
696 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
697 #ifdef IOLOOP_SELECT |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
698 " ioloop=select" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
699 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
700 #ifdef IOLOOP_NOTIFY_DNOTIFY |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
701 " notify=dnotify" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
702 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
703 #ifdef IOLOOP_NOTIFY_INOTIFY |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
704 " notify=inotify" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
705 #endif |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
706 #ifdef IOLOOP_NOTIFY_KQUEUE |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
707 " notify=kqueue" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
708 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
709 #ifdef HAVE_IPV6 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
710 " ipv6" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
711 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
712 #ifdef HAVE_GNUTLS |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
713 " gnutls" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
714 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
715 #ifdef HAVE_OPENSSL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
716 " openssl" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
717 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
718 "\nSQL drivers:" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
719 #ifdef BUILD_MYSQL |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
720 " mysql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
721 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
722 #ifdef BUILD_PGSQL |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
723 " postgresql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
724 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
725 #ifdef BUILD_SQLITE |
3919
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
726 " sqlite" |
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
727 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
728 "\nPassdb:" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
729 #ifdef PASSDB_BSDAUTH |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
730 " bsdauth" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
731 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
732 #ifdef PASSDB_CHECKPASSWORD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
733 " checkpassword" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
734 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
735 #ifdef PASSDB_LDAP |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
736 " ldap" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
737 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
738 #ifdef PASSDB_PAM |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
739 " pam" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
740 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
741 #ifdef PASSDB_PASSWD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
742 " passwd" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
743 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
744 #ifdef PASSDB_PASSWD_FILE |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
745 " passwd-file" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
746 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
747 #ifdef PASSDB_SHADOW |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
748 " shadow" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
749 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
750 #ifdef PASSDB_SQL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
751 " sql" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
752 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
753 #ifdef PASSDB_VPOPMAIL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
754 " vpopmail" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
755 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
756 "\nUserdb:" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
757 #ifdef USERDB_CHECKPASSWORD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
758 " checkpassword" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
759 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
760 #ifdef USERDB_LDAP |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
761 " ldap" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
762 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
763 #ifdef USERDB_PASSWD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
764 " passwd" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
765 #endif |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
766 #ifdef USERDB_PREFETCH |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
767 " prefetch" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
768 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
769 #ifdef USERDB_PASSWD_FILE |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
770 " passwd-file" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
771 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
772 #ifdef USERDB_SQL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
773 " sql" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
774 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
775 #ifdef USERDB_STATIC |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
776 " static" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
777 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
778 #ifdef USERDB_VPOPMAIL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
779 " vpopmail" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
780 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
781 "\n"); |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
782 } |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
783 |
0 | 784 int main(int argc, char *argv[]) |
785 { | |
786 /* parse arguments */ | |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
787 const char *exec_protocol = NULL, *exec_section = NULL, *user, *home; |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
788 bool foreground = FALSE, ask_key_pass = FALSE, log_error = FALSE; |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
789 bool dump_config = FALSE, dump_config_nondefaults = FALSE; |
0 | 790 int i; |
791 | |
2311
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
792 #ifdef DEBUG |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
793 gdb = getenv("GDB") != NULL; |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
794 #endif |
0 | 795 lib_init(); |
796 | |
1617
cc3cef25662c
Replaced geteuid() calls with one in the beginning and saving it to
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
797 master_uid = geteuid(); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
798 inetd_login_fd = -1; |
0 | 799 for (i = 1; i < argc; i++) { |
800 if (strcmp(argv[i], "-F") == 0) { | |
801 /* foreground */ | |
802 foreground = TRUE; | |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
803 } else if (strcmp(argv[i], "-a") == 0) { |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
804 dump_config = TRUE; |
0 | 805 } else if (strcmp(argv[i], "-c") == 0) { |
806 /* config file */ | |
807 i++; | |
808 if (i == argc) i_fatal("Missing config file argument"); | |
809 configfile = argv[i]; | |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
810 } else if (strcmp(argv[i], "-n") == 0) { |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
811 dump_config_nondefaults = dump_config = TRUE; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
812 } else if (strcmp(argv[i], "-p") == 0) { |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
813 /* Ask SSL private key password */ |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
814 ask_key_pass = TRUE; |
2311
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
815 } else if (strcmp(argv[i], "--exec-mail") == 0) { |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
816 /* <protocol> [<server section>] |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
817 read configuration and execute mail process */ |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
818 i++; |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
819 if (i == argc) i_fatal("Missing protocol argument"); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
820 exec_protocol = argv[i]; |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
821 if (i+1 != argc) |
2312
cc753e275197
And section fix for --exec-mail..
Timo Sirainen <tss@iki.fi>
parents:
2311
diff
changeset
|
822 exec_section = argv[++i]; |
1260 | 823 } else if (strcmp(argv[i], "--version") == 0) { |
824 printf("%s\n", VERSION); | |
825 return 0; | |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
826 } else if (strcmp(argv[i], "--build-options") == 0) { |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
827 print_build_options(); |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
828 return 0; |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
829 } else if (strcmp(argv[i], "--log-error") == 0) { |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
830 log_error = TRUE; |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
831 foreground = TRUE; |
0 | 832 } else { |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
833 print_help(); |
0 | 834 i_fatal("Unknown argument: %s", argv[1]); |
835 } | |
836 } | |
837 | |
5437 | 838 /* need to have this open before reading settings */ |
839 open_null_fd(); | |
840 | |
2311
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
841 if (getenv("DOVECOT_INETD") != NULL) { |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
842 /* starting through inetd. */ |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
843 inetd_login_fd = dup(0); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
844 if (inetd_login_fd == -1) |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
845 i_fatal("dup(0) failed: %m"); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
846 fd_close_on_exec(inetd_login_fd, TRUE); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
847 foreground = TRUE; |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
848 } |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
849 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
850 if (dump_config) { |
4485
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
851 /* print the config file path before parsing it, so in case |
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
852 of errors it's still shown */ |
5589
271c35971331
Print also Dovecot version with dovecot -n.
Timo Sirainen <tss@iki.fi>
parents:
5437
diff
changeset
|
853 printf("# "VERSION": %s\n", configfile); |
4485
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
854 } |
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
855 |
0 | 856 /* read and verify settings before forking */ |
3901
0ae5f5b468b7
Put ssl-parameters file into login directory so it still can be accessed
Timo Sirainen <tss@iki.fi>
parents:
3897
diff
changeset
|
857 t_push(); |
1058
3b8fb7bf7ecc
Moved settings parsing to lib-settings.
Timo Sirainen <tss@iki.fi>
parents:
1055
diff
changeset
|
858 master_settings_init(); |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
859 if (!master_settings_read(configfile, exec_protocol != NULL, |
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
860 dump_config)) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
861 exit(FATAL_DEFAULT); |
3901
0ae5f5b468b7
Put ssl-parameters file into login directory so it still can be accessed
Timo Sirainen <tss@iki.fi>
parents:
3897
diff
changeset
|
862 t_pop(); |
0 | 863 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
864 if (dump_config) { |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
865 master_settings_dump(settings_root, dump_config_nondefaults); |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
866 return 0; |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
867 } |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
868 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
869 if (ask_key_pass) { |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
870 const char *prompt; |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
871 |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
872 t_push(); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
873 prompt = t_strdup_printf("Give the password for SSL key file " |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
874 "%s: ", |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
875 settings_root->defaults->ssl_key_file); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
876 askpass(prompt, ssl_manual_key_password, |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
877 sizeof(ssl_manual_key_password)); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
878 t_pop(); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
879 } |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
880 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
881 /* save TZ environment. AIX depends on it to get the timezone |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
882 correctly. */ |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
883 env_tz = getenv("TZ"); |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
884 user = getenv("USER"); |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
885 home = getenv("HOME"); |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
886 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
887 /* clean up the environment of everything */ |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
888 env_clean(); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
889 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
890 /* put back the TZ */ |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
891 if (env_tz != NULL) |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
892 env_put(t_strconcat("TZ=", env_tz, NULL)); |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
893 |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
894 if (exec_protocol != NULL) { |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
895 /* Put back user and home */ |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
896 env_put(t_strconcat("USER=", user, NULL)); |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
897 env_put(t_strconcat("HOME=", home, NULL)); |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
898 mail_process_exec(exec_protocol, exec_section); |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
899 } |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
900 |
2311
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
901 open_fds(); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
902 |
0 | 903 if (!foreground) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
904 daemonize(settings_root->defaults); |
0 | 905 |
5249
784dc7224718
Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents:
5201
diff
changeset
|
906 ioloop = io_loop_create(); |
0 | 907 |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
908 main_init(log_error); |
0 | 909 io_loop_run(ioloop); |
910 main_deinit(); | |
911 | |
1058
3b8fb7bf7ecc
Moved settings parsing to lib-settings.
Timo Sirainen <tss@iki.fi>
parents:
1055
diff
changeset
|
912 master_settings_deinit(); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
913 io_loop_destroy(&ioloop); |
0 | 914 lib_deinit(); |
915 | |
916 return 0; | |
917 } |