Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/main.c @ 8301:d46579bb7a3c HEAD
Print a help message about authentication at startup until the first successful authentication.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 19 Oct 2008 13:32:01 +0300 |
parents | a69c49565a5b |
children | e4d0ce4d3420 |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
1 /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "common.h" | |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
4 #include "array.h" |
0 | 5 #include "ioloop.h" |
6 #include "lib-signals.h" | |
7 #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
|
8 #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
|
9 #include "fd-close-on-exec.h" |
2524 | 10 #include "write-full.h" |
6313
0e08960275f8
Grow file descriptors to 64k at startup, and drop them for login and imap
Timo Sirainen <tss@iki.fi>
parents:
6303
diff
changeset
|
11 #include "restrict-process-size.h" |
0 | 12 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
13 #include "askpass.h" |
0 | 14 #include "auth-process.h" |
5789
4f22660ffd33
Move POSIX capabilities dropping into separate function.
Andrey Panin <pazke@donpac.ru>
parents:
5696
diff
changeset
|
15 #include "capabilities.h" |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
16 #include "dict-process.h" |
0 | 17 #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
|
18 #include "mail-process.h" |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
19 #include "syslog-util.h" |
5936 | 20 #include "listener.h" |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
21 #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
|
22 #include "log.h" |
0 | 23 |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
24 #include <stdio.h> |
0 | 25 #include <stdlib.h> |
26 #include <unistd.h> | |
27 #include <fcntl.h> | |
28 #include <syslog.h> | |
29 #include <sys/stat.h> | |
30 | |
6313
0e08960275f8
Grow file descriptors to 64k at startup, and drop them for login and imap
Timo Sirainen <tss@iki.fi>
parents:
6303
diff
changeset
|
31 /* Try to raise our fd limit this high at startup. If the limit is already |
0e08960275f8
Grow file descriptors to 64k at startup, and drop them for login and imap
Timo Sirainen <tss@iki.fi>
parents:
6303
diff
changeset
|
32 higher, it's not dropped. */ |
0e08960275f8
Grow file descriptors to 64k at startup, and drop them for login and imap
Timo Sirainen <tss@iki.fi>
parents:
6303
diff
changeset
|
33 #define DOVECOT_MASTER_FD_MIN_LIMIT 65536 |
0e08960275f8
Grow file descriptors to 64k at startup, and drop them for login and imap
Timo Sirainen <tss@iki.fi>
parents:
6303
diff
changeset
|
34 |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
35 #define FATAL_FILENAME "master-fatal.lastlog" |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
36 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
37 static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf"; |
0 | 38 |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
39 struct ioloop *ioloop; |
5432
2b4fa90860dd
Before unlinking auth sockets at startup, try connecting to them first to
Timo Sirainen <tss@iki.fi>
parents:
5333
diff
changeset
|
40 int null_fd = -1, inetd_login_fd; |
1617
cc3cef25662c
Replaced geteuid() calls with one in the beginning and saving it to
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
41 uid_t master_uid; |
3989
e93e39326ae1
Added ssl-build-param binary to build the ssl-parameters.dat. This way
Timo Sirainen <tss@iki.fi>
parents:
3966
diff
changeset
|
42 char program_path[PATH_MAX]; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
43 char ssl_manual_key_password[100]; |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5824
diff
changeset
|
44 const char *env_tz; |
8301
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
45 bool auth_success_written; |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
46 #ifdef DEBUG |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5824
diff
changeset
|
47 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
|
48 #endif |
0 | 49 |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
50 static void ATTR_NORETURN ATTR_FORMAT(3, 0) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
51 master_fatal_callback(enum log_type type, int status, |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
52 const char *format, va_list args) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
53 { |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
54 const struct settings *set = settings_root->defaults; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
55 const char *path, *str; |
7351
6115fe69094c
Fatals/panics logged by master weren't logged properly.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
56 va_list args2; |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
57 int fd; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
58 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
59 /* write the error message to a file */ |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
60 path = t_strconcat(set->base_dir, "/"FATAL_FILENAME, NULL); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
61 fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
62 if (fd != -1) { |
7351
6115fe69094c
Fatals/panics logged by master weren't logged properly.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
63 VA_COPY(args2, args); |
6115fe69094c
Fatals/panics logged by master weren't logged properly.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
64 str = t_strdup_vprintf(format, args2); |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
65 write_full(fd, str, strlen(str)); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
66 (void)close(fd); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
67 } |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
68 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
69 /* write it to log as well */ |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
70 if (*set->log_path == '\0') |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
71 i_syslog_fatal_handler(type, status, format, args); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
72 else |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
73 default_fatal_handler(type, status, format, args); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
74 } |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
75 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
76 static void fatal_log_check(void) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
77 { |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
78 const struct settings *set = settings_root->defaults; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
79 const char *path; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
80 char buf[1024]; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
81 ssize_t ret; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
82 int fd; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
83 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
84 path = t_strconcat(set->base_dir, "/"FATAL_FILENAME, NULL); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
85 fd = open(path, O_RDONLY); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
86 if (fd == -1) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
87 return; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
88 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
89 ret = read(fd, buf, sizeof(buf)); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
90 if (ret < 0) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
91 i_error("read(%s) failed: %m", path); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
92 else { |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
93 buf[ret] = '\0'; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
94 i_warning("Last died with error (see error log for more " |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
95 "information): %s", buf); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
96 } |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
97 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
98 close(fd); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
99 if (unlink(path) < 0) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
100 i_error("unlink(%s) failed: %m", path); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
101 } |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
102 |
8301
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
103 static void auth_warning_print(void) |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
104 { |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
105 struct stat st; |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
106 |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
107 auth_success_written = stat(AUTH_SUCCESS_PATH, &st) == 0; |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
108 if (!auth_success_written) { |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
109 i_info("If you have trouble with authentication failures,\n" |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
110 "enable auth_debug setting. " |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
111 "See http://wiki.dovecot.org/WhyDoesItNotWork"); |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
112 |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
113 } |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
114 } |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
115 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
116 static void set_logfile(struct settings *set) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
117 { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
118 int facility; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
119 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
120 if (*set->log_path == '\0') { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
121 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
|
122 facility = LOG_MAIL; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
123 |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
124 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
|
125 } else { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
126 /* log to file or stderr */ |
5333
55260092b094
Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents:
5249
diff
changeset
|
127 i_set_failure_file(set->log_path, "dovecot: "); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
128 } |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
129 i_set_fatal_handler(master_fatal_callback); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
130 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
131 if (*set->info_log_path != '\0') |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
132 i_set_info_file(set->info_log_path); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
133 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
134 i_set_failure_timestamp_format(set->log_timestamp); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
135 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
136 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
137 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
|
138 { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
139 struct server_settings *old_set = settings_root; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
140 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
141 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
|
142 |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
143 /* restart auth and login processes */ |
4670 | 144 login_processes_destroy_all(); |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
145 auth_processes_destroy_all(); |
4393
9928ebb54719
Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
146 dict_process_kill(); |
1223
52e0830ade13
Added setting mail_drop_priv_before_exec.
Timo Sirainen <tss@iki.fi>
parents:
1124
diff
changeset
|
147 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
148 if (!master_settings_read(configfile, FALSE, FALSE)) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
149 i_warning("Invalid configuration, keeping old one"); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
150 else { |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
151 if (!IS_INETD()) |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
152 listeners_open_fds(old_set, TRUE); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
153 set_logfile(settings_root->defaults); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
154 } |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
155 } |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
156 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6397
diff
changeset
|
157 static void sig_die(int signo, void *context ATTR_UNUSED) |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
158 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
159 /* 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
|
160 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
|
161 if (signo != SIGINT) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
162 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
|
163 io_loop_stop(ioloop); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
164 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
165 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6397
diff
changeset
|
166 static void sig_reload_settings(int signo ATTR_UNUSED, |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6397
diff
changeset
|
167 void *context ATTR_UNUSED) |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
168 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
169 settings_reload(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
170 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
171 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6397
diff
changeset
|
172 static void sig_reopen_logs(int signo ATTR_UNUSED, |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6397
diff
changeset
|
173 void *context ATTR_UNUSED) |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
174 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
175 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
|
176 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
177 |
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
|
178 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
|
179 { |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
180 if (*set->log_path != '\0' && |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
181 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
|
182 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
183 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
184 if (*set->info_log_path != '\0' && |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
185 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
|
186 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
187 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
188 return FALSE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
189 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
190 |
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
|
191 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
|
192 { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
193 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
|
194 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
|
195 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
196 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
|
197 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
198 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
199 server = server->next; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
200 } |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
201 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
202 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
|
203 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
204 |
5437 | 205 static void open_null_fd(void) |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
206 { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 fd_close_on_exec(null_fd, TRUE); |
5437 | 211 } |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
212 |
5437 | 213 static void open_fds(void) |
214 { | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
215 /* 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
|
216 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
|
217 null_fd = dup(null_fd); |
4578
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
218 if (null_fd == -1) |
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
219 i_fatal("dup(null_fd) failed: %m"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
220 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
|
221 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
222 |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
223 if (!IS_INETD()) { |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
224 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
225 listeners_open_fds(NULL, FALSE); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
226 } T_END; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
227 } |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
228 |
4477
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
229 /* close stdin and stdout. */ |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
230 if (dup2(null_fd, 0) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
231 i_fatal("dup2(0) failed: %m"); |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
232 if (dup2(null_fd, 1) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
233 i_fatal("dup2(1) failed: %m"); |
0 | 234 } |
235 | |
2524 | 236 static void create_pid_file(const char *path) |
237 { | |
238 const char *pid; | |
239 int fd; | |
240 | |
2534 | 241 pid = t_strconcat(dec2str(getpid()), "\n", NULL); |
2524 | 242 |
243 fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644); | |
244 if (fd == -1) | |
245 i_fatal("open(%s) failed: %m", path); | |
246 if (write_full(fd, pid, strlen(pid)) < 0) | |
247 i_fatal("write() failed in %s: %m", path); | |
248 (void)close(fd); | |
249 } | |
250 | |
7946
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
251 static void main_log_startup(void) |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
252 { |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
253 #define STARTUP_STRING PACKAGE_NAME" v"VERSION" starting up" |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
254 rlim_t core_limit; |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
255 |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
256 if (restrict_get_core_limit(&core_limit) == 0 && core_limit == 0) |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
257 i_info(STARTUP_STRING" (core dumps disabled)"); |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
258 else |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
259 i_info(STARTUP_STRING); |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
260 } |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
261 |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
262 static void main_init(bool log_error) |
0 | 263 { |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
264 drop_capabilities(); |
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
265 |
0 | 266 /* deny file access from everyone else except owner */ |
267 (void)umask(0077); | |
268 | |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
269 set_logfile(settings_root->defaults); |
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
270 /* close stderr unless we're logging into /dev/stderr. */ |
4477
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
271 if (!have_stderr(settings_root)) { |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
272 if (dup2(null_fd, 2) < 0) |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
273 i_fatal("dup2(2) failed: %m"); |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
274 } |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
275 |
5696
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
276 if (log_error) { |
6303 | 277 printf("Writing to error logs and killing myself..\n"); |
278 i_info("This is Dovecot's info log"); | |
5696
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
279 i_warning("This is Dovecot's warning log"); |
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
280 i_error("This is Dovecot's error log"); |
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
281 i_fatal("This is Dovecot's fatal log"); |
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
282 } |
7946
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
283 main_log_startup(); |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
284 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
285 lib_signals_init(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
286 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
|
287 lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL); |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4745
diff
changeset
|
288 lib_signals_ignore(SIGPIPE, TRUE); |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4745
diff
changeset
|
289 lib_signals_ignore(SIGALRM, FALSE); |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
290 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
|
291 lib_signals_set_handler(SIGUSR1, TRUE, sig_reopen_logs, NULL); |
0 | 292 |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5824
diff
changeset
|
293 child_processes_init(); |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
294 log_init(); |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
295 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
|
296 dict_process_init(); |
0 | 297 auth_processes_init(); |
298 login_processes_init(); | |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5824
diff
changeset
|
299 mail_processes_init(); |
2524 | 300 |
301 create_pid_file(t_strconcat(settings_root->defaults->base_dir, | |
302 "/master.pid", NULL)); | |
0 | 303 } |
304 | |
305 static void main_deinit(void) | |
306 { | |
2524 | 307 (void)unlink(t_strconcat(settings_root->defaults->base_dir, |
308 "/master.pid", NULL)); | |
309 | |
5846
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5844
diff
changeset
|
310 login_processes_destroy_all(); |
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5844
diff
changeset
|
311 |
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5844
diff
changeset
|
312 mail_processes_deinit(); |
0 | 313 login_processes_deinit(); |
314 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
|
315 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
|
316 ssl_deinit(); |
8062
a69c49565a5b
Master could have crashed if auth process died too early and not log the reason.
Timo Sirainen <tss@iki.fi>
parents:
8055
diff
changeset
|
317 child_processes_deinit(); |
0 | 318 |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
319 listeners_close_fds(); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
320 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
321 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
|
322 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
|
323 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
324 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
|
325 log_deinit(); |
0 | 326 closelog(); |
327 } | |
328 | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
329 static void daemonize(struct settings *set) |
0 | 330 { |
331 pid_t pid; | |
332 | |
333 pid = fork(); | |
334 if (pid < 0) | |
335 i_fatal("fork() failed: %m"); | |
336 | |
337 if (pid != 0) | |
338 _exit(0); | |
610 | 339 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
340 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
|
341 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
|
342 |
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
|
343 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
|
344 i_fatal("chdir(%s) failed: %m", set->base_dir); |
0 | 345 } |
346 | |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
347 static void print_help(void) |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
348 { |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
349 printf( |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
350 "Usage: dovecot [-F] [-c <config file>] [-p] [-n] [-a]\n" |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
351 " [--version] [--build-options] [--exec-mail <protocol> [<args>]]\n"); |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
352 } |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
353 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
354 static void print_build_options(void) |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
355 { |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
356 printf("Build options:" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
357 #ifdef IOLOOP_EPOLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
358 " ioloop=epoll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
359 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
360 #ifdef IOLOOP_KQUEUE |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
361 " ioloop=kqueue" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
362 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
363 #ifdef IOLOOP_POLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
364 " ioloop=poll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
365 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
366 #ifdef IOLOOP_SELECT |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
367 " ioloop=select" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
368 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
369 #ifdef IOLOOP_NOTIFY_DNOTIFY |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
370 " notify=dnotify" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
371 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
372 #ifdef IOLOOP_NOTIFY_INOTIFY |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
373 " notify=inotify" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
374 #endif |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
375 #ifdef IOLOOP_NOTIFY_KQUEUE |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
376 " notify=kqueue" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
377 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
378 #ifdef HAVE_IPV6 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
379 " ipv6" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
380 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
381 #ifdef HAVE_GNUTLS |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
382 " gnutls" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
383 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
384 #ifdef HAVE_OPENSSL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
385 " openssl" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
386 #endif |
6635
e4f9e2b94a90
Show mail storages in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
387 "\nMail storages: "MAIL_STORAGES"\n" |
e4f9e2b94a90
Show mail storages in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
388 "SQL drivers:" |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
389 #ifdef BUILD_MYSQL |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
390 " mysql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
391 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
392 #ifdef BUILD_PGSQL |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
393 " postgresql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
394 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
395 #ifdef BUILD_SQLITE |
3919
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
396 " sqlite" |
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
397 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
398 "\nPassdb:" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
399 #ifdef PASSDB_BSDAUTH |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
400 " bsdauth" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
401 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
402 #ifdef PASSDB_CHECKPASSWORD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
403 " checkpassword" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
404 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
405 #ifdef PASSDB_LDAP |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
406 " ldap" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
407 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
408 #ifdef PASSDB_PAM |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
409 " pam" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
410 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
411 #ifdef PASSDB_PASSWD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
412 " passwd" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
413 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
414 #ifdef PASSDB_PASSWD_FILE |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
415 " passwd-file" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
416 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
417 #ifdef PASSDB_SHADOW |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
418 " shadow" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
419 #endif |
6893
a9daec3c00b5
--build-options didn't list "sia" in passdbs.
Timo Sirainen <tss@iki.fi>
parents:
6635
diff
changeset
|
420 #ifdef PASSDB_SIA |
a9daec3c00b5
--build-options didn't list "sia" in passdbs.
Timo Sirainen <tss@iki.fi>
parents:
6635
diff
changeset
|
421 " sia" |
a9daec3c00b5
--build-options didn't list "sia" in passdbs.
Timo Sirainen <tss@iki.fi>
parents:
6635
diff
changeset
|
422 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
423 #ifdef PASSDB_SQL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
424 " sql" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
425 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
426 #ifdef PASSDB_VPOPMAIL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
427 " vpopmail" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
428 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
429 "\nUserdb:" |
7947
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
430 #ifdef USERDB_NSS |
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
431 " nss" |
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
432 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
433 #ifdef USERDB_LDAP |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
434 " ldap" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
435 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
436 #ifdef USERDB_PASSWD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
437 " passwd" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
438 #endif |
7947
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
439 #ifdef USERDB_PASSWD_FILE |
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
440 " passwd-file" |
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
441 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
442 #ifdef USERDB_PREFETCH |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
443 " prefetch" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
444 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
445 #ifdef USERDB_SQL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
446 " sql" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
447 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
448 #ifdef USERDB_STATIC |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
449 " static" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
450 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
451 #ifdef USERDB_VPOPMAIL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
452 " vpopmail" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
453 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
454 "\n"); |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
455 } |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
456 |
0 | 457 int main(int argc, char *argv[]) |
458 { | |
459 /* parse arguments */ | |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
460 const char *exec_protocol = NULL, **exec_args = NULL, *user, *home; |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
461 bool foreground = FALSE, ask_key_pass = FALSE, log_error = FALSE; |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
462 bool dump_config = FALSE, dump_config_nondefaults = FALSE; |
0 | 463 int i; |
464 | |
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
|
465 #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
|
466 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
|
467 #endif |
0 | 468 lib_init(); |
469 | |
1617
cc3cef25662c
Replaced geteuid() calls with one in the beginning and saving it to
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
470 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
|
471 inetd_login_fd = -1; |
0 | 472 for (i = 1; i < argc; i++) { |
473 if (strcmp(argv[i], "-F") == 0) { | |
474 /* foreground */ | |
475 foreground = TRUE; | |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
476 } else if (strcmp(argv[i], "-a") == 0) { |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
477 dump_config = TRUE; |
0 | 478 } else if (strcmp(argv[i], "-c") == 0) { |
479 /* config file */ | |
480 i++; | |
481 if (i == argc) i_fatal("Missing config file argument"); | |
482 configfile = argv[i]; | |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
483 } else if (strcmp(argv[i], "-n") == 0) { |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
484 dump_config_nondefaults = dump_config = TRUE; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
485 } 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
|
486 /* 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
|
487 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
|
488 } else if (strcmp(argv[i], "--exec-mail") == 0) { |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
489 /* <protocol> [<args>] |
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
|
490 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
|
491 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
|
492 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
|
493 exec_protocol = argv[i]; |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
494 exec_args = (const char **)&argv[i+1]; |
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
495 break; |
1260 | 496 } else if (strcmp(argv[i], "--version") == 0) { |
497 printf("%s\n", VERSION); | |
498 return 0; | |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
499 } 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
|
500 print_build_options(); |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
501 return 0; |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
502 } else if (strcmp(argv[i], "--log-error") == 0) { |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
503 log_error = TRUE; |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
504 foreground = TRUE; |
0 | 505 } else { |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
506 print_help(); |
0 | 507 i_fatal("Unknown argument: %s", argv[1]); |
508 } | |
509 } | |
510 | |
5437 | 511 /* need to have this open before reading settings */ |
512 open_null_fd(); | |
513 | |
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
|
514 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
|
515 /* 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
|
516 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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 } |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
522 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
523 if (dump_config) { |
4485
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
524 /* print the config file path before parsing it, so in case |
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
525 of errors it's still shown */ |
5589
271c35971331
Print also Dovecot version with dovecot -n.
Timo Sirainen <tss@iki.fi>
parents:
5437
diff
changeset
|
526 printf("# "VERSION": %s\n", configfile); |
4485
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
527 } |
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
528 |
0 | 529 /* read and verify settings before forking */ |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
530 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
531 master_settings_init(); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
532 if (!master_settings_read(configfile, exec_protocol != NULL, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
533 dump_config || log_error)) |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
534 i_fatal("Invalid configuration in %s", configfile); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
535 } T_END; |
0 | 536 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
537 if (dump_config) { |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
538 master_settings_dump(settings_root, dump_config_nondefaults); |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
539 return 0; |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
540 } |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
541 |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
542 if (ask_key_pass) T_BEGIN { |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
543 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
|
544 |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
545 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
|
546 "%s: ", |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
547 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
|
548 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
|
549 sizeof(ssl_manual_key_password)); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
550 } T_END; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
551 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
552 /* 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
|
553 correctly. */ |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
554 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
|
555 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
|
556 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
|
557 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
558 /* 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
|
559 env_clean(); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
560 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
561 /* put back the TZ */ |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
562 if (env_tz != NULL) |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
563 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
|
564 |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
565 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
|
566 /* 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
|
567 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
|
568 env_put(t_strconcat("HOME=", home, NULL)); |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
569 mail_process_exec(exec_protocol, exec_args); |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
570 } |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
571 |
6303 | 572 if (!log_error) |
573 open_fds(); | |
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
|
574 |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
575 fatal_log_check(); |
8301
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
576 if (strcmp(settings_root->defaults->protocols, "none") != 0) |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
577 auth_warning_print(); |
0 | 578 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
|
579 daemonize(settings_root->defaults); |
0 | 580 |
5249
784dc7224718
Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents:
5201
diff
changeset
|
581 ioloop = io_loop_create(); |
0 | 582 |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
583 main_init(log_error); |
0 | 584 io_loop_run(ioloop); |
585 main_deinit(); | |
586 | |
1058
3b8fb7bf7ecc
Moved settings parsing to lib-settings.
Timo Sirainen <tss@iki.fi>
parents:
1055
diff
changeset
|
587 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
|
588 io_loop_destroy(&ioloop); |
0 | 589 lib_deinit(); |
590 | |
591 return 0; | |
592 } |