main.c revision e2ba2c102942d03ae7165cd20896fe5eb331b464
/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
#include "common.h"
#include "array.h"
#include "ioloop.h"
#include "network.h"
#include "lib-signals.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
#include "child-wait.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 :) */
i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)",
}
}
static void open_logfile(void)
{
const char *env;
return;
}
} else {
/* log to file or stderr */
}
}
{
if (*user == '\0')
return (uid_t)-1;
errno = 0;
if (errno != 0)
setpwent();
if (errno != 0)
i_fatal("getpwent() failed: %m");
i_fatal("getpwnam() failed for some reason. "
"Is auth_process_size set to too low?");
}
}
}
{
if (*group == '\0')
return (gid_t)-1;
errno = 0;
if (errno != 0)
else
}
}
int backlog)
{
int fd;
if (fd == -1) {
if (errno == EADDRINUSE)
else
}
i_fatal("chown(%s, %s(%s), %s(%s)) failed: %m",
}
return fd;
}
static void
struct auth_socket_unix_settings *const *sets,
{
unsigned int i;
int fd;
for (i = 0; i < count; i++) {
}
}
{
struct auth_master_listener *listener;
struct auth_socket_settings *const *sockets;
struct auth_socket_unix_settings *const *unix_sockets;
return;
for (i = 0; i < count; i++) {
continue;
}
}
}
}
static void drop_privileges(void)
{
i_fatal("Dovecot version mismatch: "
"(if you don't care, set version_ignore=yes)", version);
}
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).");
}
i_fatal("Missing AUTH_NAME environment");
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();
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 */
if (worker) {
return;
}
/* starting standalone */
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);
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++;
}
T_BEGIN {
} T_END;
main_deinit();
lib_deinit();
return 0;
}