main.c revision 89795c6bbbc52bb382e88bc8617d22092223e9a5
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenbool disable_plaintext_auth, process_per_connection, greeting_capability;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenbool verbose_proctitle, verbose_ssl, verbose_auth;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenconst char *const *log_format_elements;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenstatic const char *process_name;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenstatic unsigned int listen_count, ssl_listen_count;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen /* nothing to do, quit */
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen } else if (closing_down && clients_get_count() == 0) {
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen /* last login finished, close all communications
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen to master process */
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen /* we might still be proxying. close the connection to
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen dovecot-auth, since it's not needed anymore. */
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen } else if (clients_get_count() == 0) {
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen /* make sure we clear all the memory used by the
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen authentication connections. also this makes sure that if
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen this connection's authentication was finished but the master
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen login wasn't, the next connection won't be able to log in
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen as this user by finishing the master login. */
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainenstatic void sig_die(int signo, void *context ATTR_UNUSED)
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen /* warn about being killed because of some signal, except SIGINT (^C)
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen which is too common at least while testing :) */
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen int listen_fd = POINTER_CAST_TO(context, int);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen fd = net_accept(listen_fd, &remote_ip, &remote_port);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen if (net_getsockname(fd, &local_ip, &local_port) < 0) {
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen client = client_create(fd, FALSE, &local_ip, &remote_ip);
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen int listen_fd = POINTER_CAST_TO(context, int);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen fd = net_accept(listen_fd, &remote_ip, &remote_port);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen if (net_getsockname(fd, &local_ip, &local_port) < 0) {
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen fd_ssl = ssl_proxy_new(fd, &remote_ip, &proxy);
d65a556a5ec078cd7f1d0060adb16fc860d66b27Timo Sirainen client = client_create(fd_ssl, TRUE, &local_ip, &remote_ip);
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen unsigned int i, current_count;
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainen /* typically happens only with
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen login_process_per_connection=yes after client logs in */
b516a7812b9acc04522869fead3aa6d2787dcdc6Timo Sirainen master_notify_state_change(LOGIN_STATE_FULL_LOGINS);
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen current_count = ssl_proxy_get_count() + login_proxy_get_count();
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainen /* can't accept any more connections until existing proxies
af6c7862e6160ffaecec458f4cec43b94272ad57Timo Sirainen get destroyed */
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen i_array_init(&listen_ios, listen_count + ssl_listen_count);
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen for (i = 0; i < listen_count; i++, cur_fd++) {
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen for (i = 0; i < ssl_listen_count; i++, cur_fd++) {
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen io = io_add(cur_fd, IO_READ, login_accept_ssl,
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch /* the initial notification tells master that we're ok. if we die
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen before sending it, the master should shutdown itself. */
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainen master_notify_state_change(LOGIN_STATE_LISTENING);
void main_listen_stop(void)
unsigned int i, count;
int cur_fd;
if (!listening)
for (i = 0; i < count; i++)
if (closing_down) {
cur_fd);
unsigned int current_count;
if (connected)
static void drop_privileges(void)
const char *value;
if (!is_inetd)
random_init();
static void main_init(void)
const char *value;
if (login_process_uid == 0)
/* capability default is set in imap/pop3-login */
main_refcount = 0;
clients_init();
if (!is_inetd) {
static void main_deinit(void)
closelog();
const char *group_name;
#ifdef DEBUG
const char *env;
lib_init();
if (is_inetd) {
main_init();
if (is_inetd) {
local_port = 0;
main_deinit();
lib_deinit();