Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/main.c @ 3919:b967ffb7e3a6 HEAD
SQLite support. Patch by Jakob Hirsch.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 22 Jan 2006 14:09:11 +0200 |
parents | ae292bd41926 |
children | 19dcfd289610 |
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> | |
27 | |
28 const char *process_names[PROCESS_TYPE_MAX] = { | |
29 "unknown", | |
30 "auth", | |
3166
e6a487d80288
Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents:
3075
diff
changeset
|
31 "auth-worker", |
0 | 32 "login", |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
33 "imap", |
1358
70b60399c7d3
Separate PROCESS_TYPE_MAIL into IMAP and POP3.
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
34 "pop3", |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
35 "ssl-param" |
0 | 36 }; |
37 | |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
38 static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf"; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
867
diff
changeset
|
39 static struct timeout *to; |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
40 static const char *env_tz; |
0 | 41 |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
42 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
|
43 struct hash_table *pids; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
44 int null_fd, 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
|
45 uid_t master_uid; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
46 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
|
47 #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
|
48 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
|
49 #endif |
0 | 50 |
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
|
51 static void listen_fds_open(bool retry); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
52 static void listen_fds_close(struct server_settings *server); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
53 |
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
|
54 bool validate_str(const char *str, size_t max_len) |
0 | 55 { |
810
30f6811f4952
Instead of just trusting randomness of authentication cookies between
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
56 size_t i; |
0 | 57 |
58 for (i = 0; i < max_len; i++) { | |
59 if (str[i] == '\0') | |
60 return TRUE; | |
61 } | |
62 | |
63 return FALSE; | |
64 } | |
65 | |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
66 void child_process_init_env(void) |
0 | 67 { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
68 int facility; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
69 |
0 | 70 /* 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
|
71 env_clean(); |
0 | 72 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
73 /* 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
|
74 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
|
75 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
|
76 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
|
77 |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
78 if (!syslog_facility_find(settings_root->defaults->syslog_facility, |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
79 &facility)) |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
80 facility = LOG_MAIL; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
81 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
|
82 |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
83 #ifdef DEBUG |
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
84 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
|
85 #endif |
0 | 86 } |
87 | |
2886
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
88 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
|
89 { |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
90 const char *executable, *p, **argv; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
91 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
92 /* very simple argument splitting. */ |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
93 if (*title == '\0') |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
94 argv = t_strsplit(cmd, " "); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
95 else |
2898 | 96 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
|
97 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
98 executable = argv[0]; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
99 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
100 /* hide the path, it's ugly */ |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
101 p = strrchr(argv[0], '/'); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
102 if (p != NULL) argv[0] = p+1; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
103 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
104 execv(executable, (char **)argv); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
105 } |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
106 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
107 static void set_logfile(struct settings *set) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
108 { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
109 int facility; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
110 |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
111 if (set->log_path == NULL) { |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
112 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
|
113 facility = LOG_MAIL; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
114 |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
115 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
|
116 } else { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
117 /* log to file or stderr */ |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
118 i_set_failure_file(set->log_path, "dovecot"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
119 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
120 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
121 if (set->info_log_path != NULL) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
122 i_set_info_file(set->info_log_path); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
123 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
124 i_set_failure_timestamp_format(set->log_timestamp); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
125 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
126 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
127 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
|
128 { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
129 struct server_settings *old_set = settings_root; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
130 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
131 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
|
132 |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
133 /* restart auth and login processes */ |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
134 login_processes_destroy_all(); |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
135 auth_processes_destroy_all(); |
1223
52e0830ade13
Added setting mail_drop_priv_before_exec.
Timo Sirainen <tss@iki.fi>
parents:
1124
diff
changeset
|
136 |
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
|
137 if (!master_settings_read(configfile, FALSE)) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
138 i_warning("Invalid configuration, keeping old one"); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
139 else { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
140 listen_fds_close(old_set); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
141 listen_fds_open(TRUE); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
142 set_logfile(settings_root->defaults); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
143 } |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
144 } |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
145 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
146 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
|
147 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
148 /* 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
|
149 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
|
150 if (signo != SIGINT) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
151 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
|
152 io_loop_stop(ioloop); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
153 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
154 |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
155 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
|
156 void *context __attr_unused__) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
157 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
158 settings_reload(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
159 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
160 |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
161 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
|
162 void *context __attr_unused__) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
163 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
164 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
|
165 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
166 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
867
diff
changeset
|
167 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
|
168 { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
169 switch (status) { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 return "Can't write to log file"; |
867
e1656057b9a5
Forgot to handle FATAL_LOGERROR.
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
174 case FATAL_LOGERROR: |
e1656057b9a5
Forgot to handle FATAL_LOGERROR.
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
181 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
|
182 return NULL; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
183 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
184 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
185 return NULL; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
186 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
187 |
1036
f782b3319553
Removed useless parameters from io_callback_t and timeout_callback_t.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
188 static void timeout_handler(void *context __attr_unused__) |
0 | 189 { |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
190 const char *process_type_name, *msg; |
0 | 191 pid_t pid; |
192 int status, process_type; | |
193 | |
194 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { | |
195 /* get the type and remove from hash */ | |
196 process_type = PID_GET_PROCESS_TYPE(pid); | |
197 PID_REMOVE_PROCESS_TYPE(pid); | |
198 | |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
199 switch (process_type) { |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
204 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
|
205 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
|
206 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
207 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
|
208 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
|
209 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
210 } |
0 | 211 |
212 /* write errors to syslog */ | |
213 process_type_name = process_names[process_type]; | |
214 if (WIFEXITED(status)) { | |
215 status = WEXITSTATUS(status); | |
216 if (status != 0) { | |
911
7f92d2100795
Call login_process_abormal_exit() only if it was login processes that died..
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
217 if (process_type == PROCESS_TYPE_LOGIN) |
7f92d2100795
Call login_process_abormal_exit() only if it was login processes that died..
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
218 login_process_abormal_exit(pid); |
7f92d2100795
Call login_process_abormal_exit() only if it was login processes that died..
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
219 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
220 msg = get_exit_status_message(status); |
810
30f6811f4952
Instead of just trusting randomness of authentication cookies between
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
221 msg = msg == NULL ? "" : |
30f6811f4952
Instead of just trusting randomness of authentication cookies between
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
222 t_strconcat(" (", msg, ")", NULL); |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
223 i_error("child %s (%s) returned error %d%s", |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
224 dec2str(pid), process_type_name, |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
225 status, msg); |
0 | 226 } |
227 } else if (WIFSIGNALED(status)) { | |
911
7f92d2100795
Call login_process_abormal_exit() only if it was login processes that died..
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
228 if (process_type == PROCESS_TYPE_LOGIN) |
7f92d2100795
Call login_process_abormal_exit() only if it was login processes that died..
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
229 login_process_abormal_exit(pid); |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
230 i_error("child %s (%s) killed with signal %d", |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
231 dec2str(pid), process_type_name, |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
232 WTERMSIG(status)); |
0 | 233 } |
234 } | |
235 | |
236 if (pid == -1 && errno != EINTR && errno != ECHILD) | |
237 i_warning("waitpid() failed: %m"); | |
238 } | |
239 | |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
240 static void resolve_ip(const char *name, struct ip_addr *ip, unsigned int *port) |
0 | 241 { |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
242 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
|
243 const char *p; |
0 | 244 int ret, ips_count; |
245 | |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
246 if (name == NULL) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
247 /* defaults to "*" or "[::]" */ |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
248 ip->family = 0; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
249 return; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
250 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
251 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
252 if (name[0] == '[') { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
253 /* IPv6 address */ |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
254 p = strchr(name, ']'); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
255 if (p == NULL) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
256 i_fatal("Missing ']' in address %s", name); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
257 |
1100
95d2f3e60b82
[ipv6 address] didn't work in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1058
diff
changeset
|
258 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
|
259 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
260 p++; |
1228
4e438a5c00d3
[ipv6 address] was still buggy in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1223
diff
changeset
|
261 if (*p == '\0') |
4e438a5c00d3
[ipv6 address] was still buggy in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1223
diff
changeset
|
262 p = NULL; |
4e438a5c00d3
[ipv6 address] was still buggy in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1223
diff
changeset
|
263 else if (*p != ':') |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
264 i_fatal("Invalid data after ']' in address %s", name); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
265 } else { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
266 p = strrchr(name, ':'); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
267 if (p != NULL) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
268 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
|
269 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
270 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
271 if (p != NULL) { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
272 if (!is_numeric(p+1, '\0')) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
273 i_fatal("Invalid port in address %s", name); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
274 *port = atoi(p+1); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
275 } |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
276 |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
277 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
|
278 /* IPv4 any */ |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
279 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
|
280 return; |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
281 } |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
282 |
1261
5373999355ed
[::] address wasn't treated exactly as "ipv6 any", but looks like
Timo Sirainen <tss@iki.fi>
parents:
1260
diff
changeset
|
283 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
|
284 /* IPv6 any */ |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
285 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
|
286 return; |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
287 } |
0 | 288 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
289 /* 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
|
290 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
|
291 if (ret != 0) { |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
292 i_fatal("Can't resolve address %s: %s", |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
293 name, net_gethosterror(ret)); |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
294 } |
0 | 295 |
296 if (ips_count < 1) | |
36 | 297 i_fatal("No IPs for address: %s", name); |
0 | 298 |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
299 *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
|
300 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
301 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
302 static void |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
303 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
|
304 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
|
305 { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 name1, name2); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
310 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
311 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
|
312 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
|
313 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
|
314 name1, name2); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
315 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
316 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
317 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
318 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
|
319 const char *proto) |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
320 { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
321 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
|
322 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 "imap", proto); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
327 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
328 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
|
329 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
|
330 "pop3", proto); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
331 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
332 } |
0 | 333 } |
334 | |
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
|
335 static void listen_protocols(struct settings *set, bool retry) |
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 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
|
338 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
|
339 unsigned int port; |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
340 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
|
341 |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
342 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
|
343 #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
|
344 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
|
345 #else |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
346 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
|
347 #endif |
0 | 348 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
349 /* resolve */ |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
350 resolve_ip(set->listen, &set->listen_ip, &set->listen_port); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
351 resolve_ip(set->ssl_listen, &set->ssl_listen_ip, &set->ssl_listen_port); |
0 | 352 |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
353 if (set->ssl_listen_ip.family == 0 && set->ssl_listen == NULL) |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
354 set->ssl_listen_ip = set->listen_ip; |
0 | 355 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
356 /* register wanted protocols */ |
1820 | 357 proto = t_strsplit_spaces(set->protocols, " "); |
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
366 } 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
|
367 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
|
368 !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
|
369 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
|
370 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
|
371 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
|
372 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
373 } 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
|
374 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
|
375 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
|
376 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
|
377 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
|
378 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
379 } 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
|
380 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
|
381 !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
|
382 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
|
383 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
|
384 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
|
385 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
386 } else { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
387 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
|
388 } |
0 | 389 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
390 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
|
391 continue; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
392 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
393 if (*fd != -1) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
394 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
|
395 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
396 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
|
397 *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
|
398 else { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
399 for (i = 0; i < 10; i++) { |
3075
9cb91ed5a110
Added backlog parameter for net_listen*().
Timo Sirainen <tss@iki.fi>
parents:
2898
diff
changeset
|
400 *fd = net_listen(ip, &port, 8); |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
401 if (*fd != -1 || errno != EADDRINUSE) |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
402 break; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
403 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
404 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
|
405 if (!retry) |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
406 break; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
407 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
408 /* wait a while and try again. we're SIGHUPing |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
409 so we most likely just closed it ourself.. */ |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
410 sleep(1); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
411 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
412 |
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
|
413 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
|
414 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
|
415 net_set_nonblock(*fd, TRUE); |
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
|
416 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
417 fd_close_on_exec(*fd, TRUE); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
418 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
419 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
420 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
|
421 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
|
422 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
|
423 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
|
424 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
425 |
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
|
426 static void listen_fds_open(bool retry) |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
427 { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
428 struct server_settings *server; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
429 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
430 for (server = settings_root; server != NULL; server = server->next) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
431 if (server->imap != NULL) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
432 listen_protocols(server->imap, retry); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
433 if (server->pop3 != NULL) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
434 listen_protocols(server->pop3, retry); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
435 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
436 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
437 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
438 static void listen_fds_close(struct server_settings *server) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
439 { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
440 for (; server != NULL; server = server->next) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
441 if (server->imap != NULL) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
442 if (server->imap->listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
443 close(server->imap->listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
444 i_error("close(imap.listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
445 if (server->imap->ssl_listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
446 close(server->imap->ssl_listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
447 i_error("close(imap.ssl_listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
448 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
449 if (server->pop3 != NULL) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
450 if (server->pop3->listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
451 close(server->pop3->listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
452 i_error("close(pop3.listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
453 if (server->pop3->ssl_listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
454 close(server->pop3->ssl_listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
455 i_error("close(pop3.ssl_listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
456 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
457 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
458 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
459 |
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
|
460 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
|
461 { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
462 if (set->log_path != NULL && |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
463 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
|
464 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
465 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
466 if (set->info_log_path != NULL && |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
467 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
|
468 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
469 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
470 return FALSE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
471 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
472 |
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
|
473 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
|
474 { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
475 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
|
476 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
|
477 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
478 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
|
479 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
480 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
481 server = server->next; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
482 } |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
483 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
484 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
|
485 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
486 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
487 static void open_fds(void) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
488 { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
489 /* initialize fds. */ |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
490 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
|
491 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
|
492 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
|
493 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
|
494 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
495 /* 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
|
496 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
|
497 null_fd = dup(null_fd); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
498 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
|
499 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
500 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
501 if (!IS_INETD()) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
502 listen_fds_open(FALSE); |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
503 |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
504 /* close stdin and stdout. close stderr unless we're logging |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
505 into /dev/stderr. */ |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
506 if (dup2(null_fd, 0) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
507 i_fatal("dup2(0) failed: %m"); |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
508 if (dup2(null_fd, 1) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
509 i_fatal("dup2(1) failed: %m"); |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
510 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
511 if (!have_stderr(settings_root)) { |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
512 if (dup2(null_fd, 2) < 0) |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
513 i_fatal("dup2(2) failed: %m"); |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
514 } |
0 | 515 } |
516 | |
2524 | 517 static void create_pid_file(const char *path) |
518 { | |
519 const char *pid; | |
520 int fd; | |
521 | |
2534 | 522 pid = t_strconcat(dec2str(getpid()), "\n", NULL); |
2524 | 523 |
524 fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644); | |
525 if (fd == -1) | |
526 i_fatal("open(%s) failed: %m", path); | |
527 if (write_full(fd, pid, strlen(pid)) < 0) | |
528 i_fatal("write() failed in %s: %m", path); | |
529 (void)close(fd); | |
530 } | |
531 | |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
37
diff
changeset
|
532 static void main_init(void) |
0 | 533 { |
534 /* deny file access from everyone else except owner */ | |
535 (void)umask(0077); | |
536 | |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
537 set_logfile(settings_root->defaults); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
538 i_info("Dovecot v"VERSION" starting up"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
539 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
540 log_init(); |
0 | 541 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
542 lib_signals_init(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
543 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
|
544 lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
545 lib_signals_set_handler(SIGPIPE, FALSE, NULL, NULL); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
546 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
|
547 lib_signals_set_handler(SIGUSR1, TRUE, sig_reopen_logs, NULL); |
0 | 548 |
945
501f076f2e74
Rewrote hash table code, works with less memory now. Also some memory
Timo Sirainen <tss@iki.fi>
parents:
926
diff
changeset
|
549 pids = hash_create(default_pool, default_pool, 128, NULL, NULL); |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
550 to = timeout_add(100, timeout_handler, NULL); |
0 | 551 |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
552 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
|
553 dict_process_init(); |
0 | 554 auth_processes_init(); |
555 login_processes_init(); | |
2524 | 556 |
557 create_pid_file(t_strconcat(settings_root->defaults->base_dir, | |
558 "/master.pid", NULL)); | |
0 | 559 } |
560 | |
561 static void main_deinit(void) | |
562 { | |
2524 | 563 (void)unlink(t_strconcat(settings_root->defaults->base_dir, |
564 "/master.pid", NULL)); | |
565 | |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
566 /* make sure we log if child processes died unexpectedly */ |
1036
f782b3319553
Removed useless parameters from io_callback_t and timeout_callback_t.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
567 timeout_handler(NULL); |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
568 |
0 | 569 login_processes_deinit(); |
570 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
|
571 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
|
572 ssl_deinit(); |
0 | 573 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
574 timeout_remove(&to); |
0 | 575 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
576 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
|
577 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
|
578 |
0 | 579 hash_destroy(pids); |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
580 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
|
581 log_deinit(); |
0 | 582 closelog(); |
583 } | |
584 | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
585 static void daemonize(struct settings *set) |
0 | 586 { |
587 pid_t pid; | |
588 | |
589 pid = fork(); | |
590 if (pid < 0) | |
591 i_fatal("fork() failed: %m"); | |
592 | |
593 if (pid != 0) | |
594 _exit(0); | |
610 | 595 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
596 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
|
597 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
|
598 |
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
|
599 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
|
600 i_fatal("chdir(%s) failed: %m", set->base_dir); |
0 | 601 } |
602 | |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
603 static void print_help(void) |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
604 { |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
605 printf( |
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
606 "Usage: dovecot [-F] [-c <config file>] [-p] [--build-ssl-parameters]\n" |
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
607 " [--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
|
608 } |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
609 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
610 static void print_build_options(void) |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
611 { |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
612 printf("Build options:" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
613 #ifdef IOLOOP_EPOLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
614 " ioloop=epoll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
615 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
616 #ifdef IOLOOP_POLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
617 " ioloop=poll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
618 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
619 #ifdef IOLOOP_SELECT |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
620 " ioloop=select" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
621 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
622 #ifdef IOLOOP_NOTIFY_DNOTIFY |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
623 " dnotify" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
624 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
625 #ifdef IOLOOP_NOTIFY_INOTIFY |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
626 " inotify" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
627 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
628 #ifdef HAVE_IPV6 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
629 " ipv6" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
630 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
631 #ifdef HAVE_GNUTLS |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
632 " gnutls" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
633 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
634 #ifdef HAVE_OPENSSL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
635 " openssl" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
636 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
637 #ifdef HAVE_MYSQL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
638 " mysql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
639 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
640 #ifdef HAVE_PGSQL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
641 " postgresql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
642 #endif |
3919
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
643 #ifdef HAVE_SQLITE |
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
644 " sqlite" |
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
645 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
646 "\nPassdb: " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
647 #ifdef PASSDB_BSDAUTH |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
648 "bsdauth " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
649 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
650 #ifdef PASSDB_CHECKPASSWORD |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
651 "checkpassword " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
652 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
653 #ifdef PASSDB_LDAP |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
654 "ldap " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
655 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
656 #ifdef PASSDB_PAM |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
657 "pam " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
658 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
659 #ifdef PASSDB_PASSWD |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
660 "passwd " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
661 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
662 #ifdef PASSDB_PASSWD_FILE |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
663 "passwd-file " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
664 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
665 #ifdef PASSDB_SHADOW |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
666 "shadow " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
667 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
668 #ifdef PASSDB_SQL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
669 "sql " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
670 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
671 #ifdef PASSDB_VPOPMAIL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
672 "vpopmail " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
673 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
674 "\nUserdb: " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
675 #ifdef USERDB_CHECKPASSWORD |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
676 "checkpassword " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
677 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
678 #ifdef USERDB_LDAP |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
679 "ldap " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
680 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
681 #ifdef USERDB_PASSDB |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
682 "passdb " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
683 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
684 #ifdef USERDB_PASSWD |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
685 "passwd " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
686 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
687 #ifdef USERDB_PASSWD_FILE |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
688 "passwd-file " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
689 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
690 #ifdef USERDB_SQL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
691 "sql " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
692 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
693 #ifdef USERDB_STATIC |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
694 "static " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
695 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
696 #ifdef USERDB_VPOPMAIL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
697 "vpopmail " |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
698 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
699 "\n"); |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
700 } |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
701 |
0 | 702 int main(int argc, char *argv[]) |
703 { | |
704 /* 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
|
705 const char *exec_protocol = NULL, *exec_section = NULL, *user, *home; |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
706 bool foreground = FALSE, ask_key_pass = FALSE, build_parameters = FALSE; |
0 | 707 int i; |
708 | |
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
|
709 #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
|
710 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
|
711 #endif |
0 | 712 lib_init(); |
713 | |
1617
cc3cef25662c
Replaced geteuid() calls with one in the beginning and saving it to
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
714 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
|
715 inetd_login_fd = -1; |
0 | 716 for (i = 1; i < argc; i++) { |
717 if (strcmp(argv[i], "-F") == 0) { | |
718 /* foreground */ | |
719 foreground = TRUE; | |
720 } else if (strcmp(argv[i], "-c") == 0) { | |
721 /* config file */ | |
722 i++; | |
723 if (i == argc) i_fatal("Missing config file argument"); | |
724 configfile = argv[i]; | |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
725 } 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
|
726 /* 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
|
727 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
|
728 } 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
|
729 /* <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
|
730 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
|
731 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
|
732 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
|
733 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
|
734 if (i+1 != argc) |
2312
cc753e275197
And section fix for --exec-mail..
Timo Sirainen <tss@iki.fi>
parents:
2311
diff
changeset
|
735 exec_section = argv[++i]; |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
736 } else if (strcmp(argv[i], "--build-ssl-parameters") == 0) { |
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
737 build_parameters = TRUE; |
1260 | 738 } else if (strcmp(argv[i], "--version") == 0) { |
739 printf("%s\n", VERSION); | |
740 return 0; | |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
741 } 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
|
742 print_build_options(); |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
743 return 0; |
0 | 744 } else { |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
745 print_help(); |
0 | 746 i_fatal("Unknown argument: %s", argv[1]); |
747 } | |
748 } | |
749 | |
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
|
750 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
|
751 /* 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
|
752 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
|
753 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
|
754 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
|
755 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
|
756 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
|
757 } |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
758 |
0 | 759 /* 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
|
760 t_push(); |
1058
3b8fb7bf7ecc
Moved settings parsing to lib-settings.
Timo Sirainen <tss@iki.fi>
parents:
1055
diff
changeset
|
761 master_settings_init(); |
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
|
762 if (!master_settings_read(configfile, exec_protocol != NULL)) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
763 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
|
764 t_pop(); |
0 | 765 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
766 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
|
767 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
|
768 |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
769 t_push(); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
770 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
|
771 "%s: ", |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
772 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
|
773 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
|
774 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
|
775 t_pop(); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
776 } |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
777 if (build_parameters) { |
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
778 ssl_check_parameters_file(TRUE); |
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
779 exit(0); |
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
780 } |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
781 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
782 /* 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
|
783 correctly. */ |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
784 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
|
785 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
|
786 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
|
787 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
788 /* 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
|
789 env_clean(); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
790 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
791 /* put back the TZ */ |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
792 if (env_tz != NULL) |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
793 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
|
794 |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
795 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
|
796 /* 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
|
797 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
|
798 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
|
799 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
|
800 } |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
801 |
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
|
802 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
|
803 |
0 | 804 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
|
805 daemonize(settings_root->defaults); |
0 | 806 |
389
60040a9d243f
ioloop_create() takes now pool-parameter. io_buffer_create_mmaped() takes
Timo Sirainen <tss@iki.fi>
parents:
279
diff
changeset
|
807 ioloop = io_loop_create(system_pool); |
0 | 808 |
35
b420373f88f6
Added log_path and log_timestamp settings to config file. Removed -l command
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
809 main_init(); |
0 | 810 io_loop_run(ioloop); |
811 main_deinit(); | |
812 | |
1058
3b8fb7bf7ecc
Moved settings parsing to lib-settings.
Timo Sirainen <tss@iki.fi>
parents:
1055
diff
changeset
|
813 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
|
814 io_loop_destroy(&ioloop); |
0 | 815 lib_deinit(); |
816 | |
817 return 0; | |
818 } |