main.c revision 2421fd34d51fed6da985c62b5e078d7e96640653
/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
#include "common.h"
#include "ioloop.h"
#include "network.h"
#include "ostream.h"
#include "str.h"
#include "base64.h"
#include "istream.h"
#include "lib-signals.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
#include "process-title.h"
#include "module-dir.h"
#include "dict.h"
#include "mail-storage.h"
#include "commands.h"
#include "mail-namespace.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#define IS_STANDALONE() \
struct client_workaround_list {
const char *name;
enum client_workarounds num;
};
static struct client_workaround_list client_workaround_list[] = {
{ "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
{ "outlook-idle", 0 }, /* only for backwards compatibility */
{ "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
{ "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
{ NULL, 0 }
};
unsigned int imap_max_line_length;
enum client_workarounds client_workarounds = 0;
const char *logout_format;
const char *imap_id_send, *imap_id_log;
{
/* warn about being killed because of some signal, except SIGINT (^C)
which is too common at least while testing :) */
}
{
/* the log fd is closed, don't die when trying to log later */
}
static void parse_workarounds(void)
{
struct client_workaround_list *list;
return;
break;
}
}
}
}
static void open_logfile(void)
{
const char *user;
return;
}
else {
if (IS_STANDALONE())
user = "??";
}
/* quite a long user name, cut it */
}
}
} else {
/* log to file or stderr */
}
}
static void drop_privileges(void)
{
const char *version;
i_fatal("Dovecot version mismatch: "
"(if you don't care, set version_ignore=yes)", version);
}
/* Log file or syslog opening probably requires roots */
open_logfile();
/* Load the plugins before chrooting. Their init() is called later. */
if (plugin_dir == NULL)
}
}
static void main_init(void)
{
if (IS_STANDALONE())
i_fatal("USER environment missing");
}
i_info("Effective uid=%s, gid=%s, home=%s",
}
/* If master dies, the log fd gets closed and we'll quit */
}
clients_init();
exit(0);
}
/* Overrides all capabilities */
}
if (logout_format == NULL)
logout_format = "bytes=%i/%o";
if (mail_namespaces_init(user) < 0)
i_fatal("Namespace initialization failed");
/* IMAPLOGINTAG environment is compatible with mailfront */
"* PREAUTH [CAPABILITY ",
} else {
tag, " OK [CAPABILITY ",
}
i_panic("Couldn't add client input to stream");
(void)client_handle_input(client);
}
} T_END;
}
static void main_deinit(void)
{
closelog();
}
{
#ifdef DEBUG
#endif
if (IS_STANDALONE() && getuid() == 0 &&
printf("* BAD [ALERT] imap binary must not be started from "
"inetd, use imap-login instead.\n");
return 1;
}
/* NOTE: we start rooted, so keep the code minimal until
restrict_access_by_env() is called */
lib_init();
ioloop = io_loop_create();
/* fake that we're running, so we know if client was destroyed
while initializing */
main_init();
if (io_loop_is_running(ioloop))
main_deinit();
lib_deinit();
return 0;
}