main.c revision e959e240bb8975cba293a94dbc61712b232904f6
/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
#include "common.h"
#include "buffer.h"
#include "ioloop.h"
#include "network.h"
#include "lib-signals.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
#include "sql-api.h"
#include "module-dir.h"
#include "randgen.h"
#include "password-scheme.h"
#include "mech.h"
#include "auth.h"
#include "auth-request-handler.h"
#include "auth-worker-server.h"
#include "auth-worker-client.h"
#include "auth-master-interface.h"
#include "auth-master-listener.h"
#include "auth-master-connection.h"
#include "auth-client-connection.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <pwd.h>
#include <grp.h>
static struct auth_worker_client *worker_client;
{
/* warn about being killed because of some signal, except SIGINT (^C)
which is too common at least while testing :) */
}
static void open_logfile(void)
{
const char *env;
return;
}
} else {
/* log to file or stderr */
}
}
{
return (uid_t)-1;
}
{
return (gid_t)-1;
}
{
unsigned int mask;
int fd, i;
return -1;
else {
}
for (i = 0; i < 5; i++) {
if (fd != -1)
break;
if (errno != EADDRINUSE)
/* see if it really exists */
/* delete and try again */
}
i_fatal("chown(%s, %s, %s) failed: %m",
}
return fd;
}
static void add_extra_listeners(void)
{
struct auth_master_listener *listener;
unsigned int i;
for (i = 1;; i++) {
break;
if (master_fd != -1) {
}
if (client_fd != -1) {
}
}
}
static void drop_privileges(void)
{
const char *version;
i_fatal("Dovecot version mismatch: "
"(if you don't care, set version_ignore=yes)", version);
}
open_logfile();
random_init();
/* Load built-in SQL drivers (if any) */
/* Initialize databases so their configuration files can be readable
only by root. Also load all modules here. */
passdbs_init();
userdbs_init();
auth = auth_preinit();
if (!worker)
/* Password lookups etc. may require roots, allow it. */
}
{
struct auth_master_listener *listener;
/* If auth caches aren't used, just ignore these signals */
mech_init();
if (worker) {
return;
}
if (standalone) {
/* starting standalone */
i_fatal("dovecot-auth is usually started through "
"dovecot master process. If you wish to run "
"it standalone, you'll need to set AUTH_* "
"environment variables (AUTH_1 isn't set).");
}
if (!nodaemon) {
switch (fork()) {
case -1:
i_fatal("fork() failed: %m");
case 0:
break;
default:
exit(0);
}
if (setsid() < 0)
i_fatal("setsid() failed: %m");
if (chdir("/") < 0)
i_fatal("chdir(/) failed: %m");
}
} else {
}
/* everything initialized, notify masters that all is well */
}
static void main_deinit(void)
{
if (worker_client != NULL)
else
auth_deinit(&auth);
mech_deinit();
closelog();
}
{
bool foreground = FALSE;
#ifdef DEBUG
#endif
/* NOTE: we start rooted, so keep the code minimal until
restrict_access_by_env() is called */
lib_init();
ioloop = io_loop_create();
foreground = TRUE;
argv++;
}
);
main_deinit();
lib_deinit();
return 0;
}