client.c revision e59faf65ce864fe95dc00f5d52b8323cdbd0608a
7cb128dc4cae2a03a742f63ba7afee23c78e3af0Phil Carmody/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen/* Disconnect client when it sends too many bad commands */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstatic bool cmd_stls(struct pop3_client *client)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstatic bool cmd_quit(struct pop3_client *client)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen client_send_line(&client->common, CLIENT_CMD_REPLY_OK, "Logging out");
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen client_destroy(&client->common, "Aborted login");
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstatic bool client_command_execute(struct pop3_client *client, const char *cmd,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen client_send_line(&client->common, CLIENT_CMD_REPLY_BAD,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen "Unknown command.");
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainenstatic void pop3_client_input(struct client *client)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct pop3_client *pop3_client = (struct pop3_client *)client;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* if a command starts an authentication, stop processing further
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen commands until the authentication is finished. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen while (!client->output->closed && !client->authenticating &&
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen (line = i_stream_next_line(client->input)) != NULL) {
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen else if (++client->bad_counter > CLIENT_MAX_BAD_COMMANDS) {
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen client_send_line(client, CLIENT_CMD_REPLY_BYE,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen "Too many invalid bad commands.");
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen "Disconnected: Too many bad commands");
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen if (auth_client != NULL && !auth_client_is_connected(auth_client))
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstatic struct client *pop3_client_alloc(pool_t pool)
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen pop3_client = p_new(pool, struct pop3_client, 1);
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainenstatic void pop3_client_create(struct client *client ATTR_UNUSED,
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainenstatic void pop3_client_destroy(struct client *client)
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen struct pop3_client *pop3_client = (struct pop3_client *)client;
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainenstatic char *get_apop_challenge(struct pop3_client *client)
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen unsigned char buffer_base64[MAX_BASE64_ENCODED_SIZE(sizeof(buffer)) + 1];
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen auth_client_get_connect_id(auth_client, &client->apop_server_pid,
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen buffer_create_data(&buf, buffer_base64, sizeof(buffer_base64));
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen (unsigned long)ioloop_time,
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainenstatic void pop3_client_send_greeting(struct client *client)
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen struct pop3_client *pop3_client = (struct pop3_client *)client;
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen client->io = io_add(client->fd, IO_READ, client_input, client);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainen pop3_client->apop_challenge = get_apop_challenge(pop3_client);
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainenstatic void pop3_client_starttls(struct client *client ATTR_UNUSED)
7d800c558b4a40f11748d4ebfc2bf89eb743f03cTimo Sirainenpop3_client_send_line(struct client *client, enum client_cmd_reply reply,
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainen /* can't send status notifications */
a4392e9d312e3b5973fe5dbaee7028197a700ff0Timo Sirainenstatic void pop3_login_die(void)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* do nothing. pop3 connections typically die pretty quick anyway. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* override the default login_die() */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen master_service_set_die_callback(master_service, pop3_login_die);
void clients_deinit(void)
NULL,
NULL,