client.c revision f059a046515f4b2b15a6c2a10a6f12f6166e39a5
/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
#include "common.h"
#include "buffer.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "process-title.h"
#include "safe-memset.h"
#include "str.h"
#include "strescape.h"
#include "imap-parser.h"
#include "imap-id.h"
#include "imap-resp-code.h"
#include "master-service.h"
#include "master-auth.h"
#include "client.h"
#include "client-authenticate.h"
#include "auth-client.h"
#include "ssl-proxy.h"
#include "imap-proxy.h"
#include "imap-login-settings.h"
#include <stdlib.h>
/* maximum length for IMAP command line. */
#define MAX_IMAP_LINE 8192
/* Disconnect client when it sends too many bad commands */
#define CLIENT_MAX_BAD_COMMANDS 10
const char *login_protocol = "imap";
const char *login_process_name = "imap-login";
unsigned int login_default_port = 143;
void login_process_preinit(void)
{
}
/* Skip incoming data until newline is found,
returns TRUE if newline was found. */
{
const unsigned char *data;
for (i = 0; i < data_size; i++) {
if (data[i] == '\n') {
return TRUE;
}
}
return FALSE;
}
{
return t_strconcat(cap_str,
}
{
/* Client is required to send CAPABILITY after STARTTLS, so the
capability resp-code workaround checks only pre-STARTTLS
CAPABILITY commands. */
return 1;
}
{
return 1;
}
static void
{
return;
args += 2;
}
}
{
}
}
return 1;
}
{
"NOOP completed.");
return 1;
}
{
"Logout completed.");
return 1;
}
{
"ENABLE ignored in non-authenticated state.");
return 1;
}
{
return cmd_capability(client);
return cmd_starttls(client);
return cmd_logout(client);
return cmd_enable(client);
return -1;
}
{
const char *msg;
int ret;
bool fatal;
if (client->cmd_finished) {
/* clear the previous command from memory. don't do this
immediately after handling command since we need the
cmd_tag to stay some time after authentication commands. */
/* remove \r\n */
if (!client_skip_line(client))
return FALSE;
}
}
return FALSE; /* need more data */
}
return FALSE; /* need more data */
}
case -1:
/* error */
if (fatal) {
return FALSE;
}
return TRUE;
case -2:
/* not enough data */
return FALSE;
}
/* we read the entire line - skip over the CRLF */
if (!client_skip_line(client))
i_unreached();
ret = -1;
else
if (ret < 0) {
"Too many invalid IMAP commands.");
"Disconnected: Too many invalid commands");
return FALSE;
}
"Error in IMAP command received by server.");
}
}
{
if (!client_read(client))
return;
if (!auth_client_is_connected(auth_client)) {
/* we're not yet connected to auth process -
don't allow any commands */
} else {
while (client_handle_input(imap_client)) ;
}
}
{
struct imap_client *imap_client;
return &imap_client->common;
}
{
}
{
}
{
}
{
/* CRLF is lost from buffer when streams are reopened. */
}
static void
const char *text)
{
const char *prefix = "NO";
switch (reply) {
case CLIENT_CMD_REPLY_OK:
prefix = "OK";
break;
break;
break;
break;
resp_code = "ALERT";
break;
break;
case CLIENT_CMD_REPLY_BAD:
prefix = "BAD";
break;
case CLIENT_CMD_REPLY_BYE:
prefix = "BYE";
break;
case CLIENT_CMD_REPLY_STATUS:
prefix = "OK";
break;
prefix = "BAD";
resp_code = "ALERT";
break;
}
T_BEGIN {
if (tagged)
else
} T_END;
}
void clients_init(void)
{
}
void clients_deinit(void)
{
}
struct client_vfuncs client_vfuncs = {
NULL,
NULL,
};