main.c revision 64e244defe74f513ce94f33d000a048ddbe2ea23
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "lib-signals.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 <stdlib.h>
#include <unistd.h>
#include <syslog.h>
int verbose_ssl;
unsigned int max_logging_users;
unsigned int login_process_uid;
struct auth_client *auth_client;
static int main_refcount;
static int is_inetd, 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 {
}
}
{
if (connected)
}
static void drop_privileges()
{
/* 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. */
/* make sure we can't fork() */
}
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();
if (!is_inetd) {
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 */
}
}
static void main_deinit(void)
{
if (lib_signal_kill != 0)
closelog();
}
{
const char *name, *group_name;
#ifdef DEBUG
if (!is_inetd)
#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]);
}
fd = 1;
for (i = 1; i < argc; i++) {
if (fd == -1)
i_fatal("SSL initialization failed");
}
closing_down = TRUE;
if (fd != -1) {
}
}
main_deinit();
lib_deinit();
return 0;
}