main.c revision 12cf3d0e03fc70fb0c8b91bc8fd83b4e14d7cdef
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "lib-signals.h"
#include "randgen.h"
#include "restrict-access.h"
#include "restrict-process-size.h"
#include "process-title.h"
#include "fd-close-on-exec.h"
#include "master.h"
#include "client-common.h"
#include "auth-client.h"
#include "ssl-proxy.h"
#include "login-proxy.h"
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
const char *greeting, *log_format;
const char *const *log_format_elements;
unsigned int max_connections;
unsigned int login_process_uid;
struct auth_client *auth_client;
bool closing_down;
static const char *process_name;
static int main_refcount;
void main_ref(void)
{
}
void main_unref(void)
{
if (--main_refcount == 0) {
/* nothing to do, quit */
} else if (closing_down && clients_get_count() == 0) {
/* last login finished, close all communications
to master process */
master_close();
}
}
{
/* warn about being killed because of some signal, except SIGINT (^C)
which is too common at least while testing :) */
}
{
unsigned int remote_port, local_port;
int fd;
if (fd < 0) {
if (fd < -1)
i_fatal("accept() failed: %m");
return;
}
local_port = 0;
}
if (process_per_connection) {
closing_down = TRUE;
}
}
{
unsigned int remote_port, local_port;
if (fd < 0) {
if (fd < -1)
i_fatal("accept() failed: %m");
return;
}
local_port = 0;
}
if (fd_ssl == -1)
else {
}
if (process_per_connection) {
closing_down = TRUE;
}
}
void main_listen_start(void)
{
unsigned int current_count;
if (listening)
return;
if (closing_down) {
/* typically happens only with
login_process_per_connection=yes after client logs in */
return;
}
if (current_count >= max_connections) {
/* can't accept any more connections until existing proxies
get destroyed */
return;
}
login_accept, NULL);
}
if (!ssl_initialized) {
/* this shouldn't happen, master should have
disabled the ssl socket.. */
i_fatal("BUG: SSL initialization parameters not given "
"while they should have been");
}
}
/* the initial notification tells master that we're ok. if we die
before sending it, the master should shutdown itself. */
}
void main_listen_stop(void)
{
if (!listening)
return;
if (closing_down) {
if (close(LOGIN_LISTEN_FD) < 0)
i_fatal("close(listen) failed: %m");
}
}
if (io_ssl_listen != NULL) {
if (closing_down) {
if (close(LOGIN_SSL_LISTEN_FD) < 0)
i_fatal("close(ssl_listen) failed: %m");
}
}
}
void connection_queue_add(unsigned int connection_count)
{
unsigned int current_count;
return;
/* after this client we've reached max users count,
so stop listening for more. reserve +1 extra for SSL
connections. */
if (current_count >= max_connections) {
/* already reached max. users count, kill few of the
oldest connections.
this happens when we've maxed out the login process
count and master has told us to start listening for
new connections even though we're full. */
}
}
}
{
if (connected)
}
static void drop_privileges(void)
{
const char *env;
if (!is_inetd)
else {
/* log to syslog */
/* if we don't chroot, we must chdir */
}
}
/* Initialize SSL proxy so it can read certificate and private
key file. */
random_init();
/* Refuse to run as root - we should never need it and it's
dangerous with SSL. */
/* make sure we can't fork() */
}
static void main_init(void)
{
const char *value;
i_fatal("Dovecot version mismatch: "
"(if you don't care, set version_ignore=yes)", value);
}
value = "user=<%u> method=%m rip=%r lip=%l %c : %$";
if (log_format == NULL)
log_format = "%$: %s";
i_fatal("BUG: PROCESS_UID environment not given");
if (login_process_uid == 0)
i_fatal("BUG: PROCESS_UID environment is 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 *name, *group_name;
unsigned int remote_port, local_port;
#ifdef DEBUG
#endif
/* NOTE: we start rooted, so keep the code minimal until
restrict_access_by_env() is called */
lib_init();
if (is_inetd) {
/* running from inetd. create master process before
dropping privileges. */
for (i = 1; i < argc; i++) {
break;
}
}
}
main_init();
if (is_inetd) {
i_fatal("%s can be started only through dovecot "
"master process, inetd or equilevant", argv[0]);
}
local_port = 0;
}
fd = 1;
for (i = 1; i < argc; i++) {
}
/* hardcoded imaps and pop3s ports to be SSL by default */
if (fd == -1)
return 1;
}
closing_down = TRUE;
if (fd != -1) {
}
}
main_deinit();
lib_deinit();
return 0;
}