client.c revision 5f5870385cff47efd2f58e7892f251cf13761528
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Disconnect client when it sends too many bad commands */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk client_send_line(&client->common, CLIENT_CMD_REPLY_OK, "Logging out");
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk client_destroy(&client->common, "Aborted login");
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic bool client_command_execute(struct pop3_client *client, const char *cmd,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk const char *args)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk client_send_line(&client->common, CLIENT_CMD_REPLY_BAD,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk "Unknown command.");
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic void pop3_client_input(struct client *client)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk struct pop3_client *pop3_client = (struct pop3_client *)client;
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* if a command starts an authentication, stop processing further
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk commands until the authentication is finished. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk while (!client->output->closed && !client->authenticating &&
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk (line = i_stream_next_line(client->input)) != NULL) {
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk else if (++client->bad_counter > CLIENT_MAX_BAD_COMMANDS) {
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk "Too many invalid bad commands.");
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk "Disconnected: Too many bad commands");
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk if (auth_client != NULL && !auth_client_is_connected(auth_client))
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic struct client *pop3_client_alloc(pool_t pool)
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen pop3_client = p_new(pool, struct pop3_client, 1);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic void pop3_client_create(struct client *client ATTR_UNUSED,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic void pop3_client_destroy(struct client *client)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk struct pop3_client *pop3_client = (struct pop3_client *)client;
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic char *get_apop_challenge(struct pop3_client *client)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk unsigned char buffer_base64[MAX_BASE64_ENCODED_SIZE(sizeof(buffer)) + 1];
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk if (auth_client_find_mech(auth_client, "APOP") == NULL) {
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* disabled, no need to present the challenge */
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainen auth_client_get_connect_id(auth_client, &client->apop_server_pid,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk buffer_create_data(&buf, buffer_base64, sizeof(buffer_base64));
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk (unsigned long)ioloop_time,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic void pop3_client_send_greeting(struct client *client)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk struct pop3_client *pop3_client = (struct pop3_client *)client;
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk client->io = io_add(client->fd, IO_READ, client_input, client);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk pop3_client->apop_challenge = get_apop_challenge(pop3_client);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic void pop3_client_starttls(struct client *client ATTR_UNUSED)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkpop3_client_send_line(struct client *client, enum client_cmd_reply reply,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk const char *text)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* can't send status notifications */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic void pop3_login_die(void)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* do nothing. pop3 connections typically die pretty quick anyway. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic void pop3_login_preinit(void)
static void pop3_login_init(void)
static void pop3_login_deinit(void)
NULL,
NULL,