main.c revision c0435c854a0e7246373b9752d163095cc4fbe985
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "lib-signals.h"
#include "restrict-access.h"
#include "process-title.h"
#include "fd-close-on-exec.h"
#include "auth-connection.h"
#include "master.h"
#include "client.h"
#include "ssl-proxy.h"
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
unsigned int max_logging_users;
unsigned int login_process_uid;
static int main_refcount;
static int closing_down;
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();
}
}
void main_close_listen(void)
{
if (closing_down)
return;
if (close(LOGIN_IMAP_LISTEN_FD) < 0)
i_fatal("can't close() IMAP listen handle");
}
if (close(LOGIN_IMAPS_LISTEN_FD) < 0)
i_fatal("can't close() IMAPS listen handle");
}
closing_down = TRUE;
}
{
}
{
int fd;
if (fd < 0) {
if (fd < -1)
i_fatal("accept() failed: %m");
return;
}
}
{
if (fd < 0) {
if (fd < -1)
i_fatal("accept() failed: %m");
return;
}
if (fd_ssl == -1)
else {
}
}
static void open_logfile(void)
{
else {
/* log to file or stderr */
}
}
static void drop_privileges(void)
{
/* Log file or syslog opening probably requires roots */
open_logfile();
/* Initialize SSL proxy so it can read certificate and private
key file. */
/* Refuse to run as root - we should never need it and it's
dangerous with SSL. */
}
static void main_init(void)
{
const char *value;
i_fatal("BUG: PROCESS_UID environment not given");
if (login_process_uid == 0)
i_fatal("BUG: PROCESS_UID environment is 0");
main_refcount = 0;
master_init();
clients_init();
/* we're listening for imap */
login_accept, NULL);
}
/* we're listening for imaps */
if (!ssl_initialized) {
/* this shouldn't happen, master should have
disabled the imaps socket.. */
i_fatal("BUG: SSL initialization parameters not given "
"while they should have been");
}
}
}
static void main_deinit(void)
{
if (lib_signal_kill != 0)
closelog();
}
{
#ifdef DEBUG
#endif
/* NOTE: we start rooted, so keep the code minimal until
restrict_access_by_env() is called */
lib_init();
main_init();
main_deinit();
lib_deinit();
return 0;
}