main.c revision 646817f0cfb39b0e0eb545900f1566b76a851b20
/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
#include "imap-common.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "path-util.h"
#include "str.h"
#include "base64.h"
#include "process-title.h"
#include "randgen.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
#include "settings-parser.h"
#include "master-interface.h"
#include "master-service.h"
#include "master-login.h"
#include "mail-user.h"
#include "mail-storage-service.h"
#include "lda-settings.h"
#include "imap-master-client.h"
#include "imap-resp-code.h"
#include "imap-commands.h"
#include "imap-fetch.h"
#include <stdio.h>
#include <unistd.h>
#define IS_STANDALONE() \
#define IMAP_DIE_IDLE_SECS 10
static bool verbose_proctitle = FALSE;
static struct mail_storage_service_ctx *storage_service;
bool imap_debug = FALSE;
{
return old_hook;
}
void imap_refresh_proctitle(void)
{
#define IMAP_PROCTITLE_PREFERRED_LEN 80
struct client_command_context *cmd;
bool wait_output;
if (!verbose_proctitle)
return;
switch (imap_client_count) {
case 0:
break;
case 1:
}
wait_output = FALSE;
continue;
}
wait_output = TRUE;
}
if (wait_output) {
}
break;
default:
break;
}
}
{
return;
}
static void imap_die(void)
{
unsigned int stop_msecs;
if (last_io <= stop_timestamp)
else {
}
}
}
struct client_input {
const char *tag;
const unsigned char *input;
bool send_untagged_capability;
};
static void
struct client_input *input_r)
{
if (data[0] == '1')
}
}
static void
{
struct client_input input;
if (client_input_size > 0) {
if (input.input_size > 0 &&
i_panic("Couldn't add client input to stream");
} else {
/* IMAPLOGINTAG environment is compatible with mailfront */
}
"* PREAUTH [CAPABILITY ",
} else if (input.send_untagged_capability) {
/* client doesn't seem to understand tagged capabilities. send
untagged instead and hope that it works. */
} else {
}
(void)client_handle_input(client);
/* we could have already handled LOGOUT, or we might need to continue
pending ambiguous commands. */
if (client->disconnected)
else
}
{
struct mail_storage_service_user *user;
struct mail_namespace *ns;
struct imap_settings *imap_set;
struct lda_settings *lda_set;
const char *errstr;
enum mail_error mail_error;
return -1;
/* this is mainly for imapc: make sure we can do at least minimal
access to the mailbox list or fail immediately. otherwise the IMAP
client could be trying a lot of commands and we'd return failures
for all of them. FIXME: There should be a bit less kludgy way to
check this, but I'm not sure if it's worth the trouble just for
imapc. */
if (mail_error != MAIL_ERROR_NONE) {
return -1;
}
if (imap_set->verbose_proctitle)
&errstr) <= 0 ||
&errstr) <= 0) {
return -1;
}
return 0;
}
static void main_stdio_run(const char *username)
{
struct mail_storage_service_input input;
i_fatal("USER environment missing");
if (input_base64 == NULL)
else {
}
/* client may be destroyed now */
}
static void
const char *username, const char *const *extra_fields)
{
struct mail_storage_service_input input;
enum mail_auth_request_flags flags;
const char *error;
strlen(MSG_BYE_INTERNAL_ERROR)) < 0) {
i_error("write(client) failed: %m");
}
i_close_fd(&fd);
return;
}
if ((flags & MAIL_AUTH_REQUEST_FLAG_TLS_COMPRESSION) != 0)
/* client may be destroyed now */
}
const char *errormsg)
{
struct client_input input;
const char *msg;
/* ignored */
}
}
{
/* when running standalone, we shouldn't even get here */
/* restoring existing IMAP connection (e.g. from imap-idle) */
} else {
}
}
{
static const struct setting_parser_info *set_roots[] = {
};
struct master_login_settings login_set;
enum master_service_flags service_flags = 0;
int c;
if (IS_STANDALONE() && getuid() == 0 &&
printf("* BAD [ALERT] imap binary must not be started from "
"inetd, use imap-login instead.\n");
return 1;
}
if (IS_STANDALONE()) {
} else {
}
while ((c = master_getopt(master_service)) > 0) {
switch (c) {
case 'a':
break;
case 't':
break;
case 'u':
break;
case 'D':
imap_debug = TRUE;
break;
default:
return FATAL_DEFAULT;
}
}
/* plugins may want to add commands, so this needs to be called early */
random_init();
/* fake that we're running, so we know if client was destroyed
while handling its initial input */
if (IS_STANDALONE()) {
T_BEGIN {
} T_END;
} else T_BEGIN {
const char *error;
&error) < 0) {
error);
}
}
}
} T_END;
if (master_login != NULL)
return 0;
}