main.c revision fc60e984083286229bf908fbadb896882f85dc6c
/* 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-common.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_LISTEN_FD) < 0)
i_fatal("close(listen) failed: %m");
}
if (io_ssl_listen != NULL) {
if (close(LOGIN_SSL_LISTEN_FD) < 0)
i_fatal("close(ssl_listen) failed: %m");
}
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(const char *name)
{
else {
/* log to file or stderr */
}
}
static void drop_privileges(const char *name)
{
/* Log file or syslog opening probably requires roots */
/* 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;
clients_init();
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");
}
}
/* initialize master last - it sends the "we're ok" notification */
master_init();
}
static void main_deinit(void)
{
if (lib_signal_kill != 0)
closelog();
}
{
const char *name;
#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;
}