[Dovecot] 1.0-test69

Andrey Panin pazke at donpac.ru
Mon May 9 10:19:57 EEST 2005


On 128, 05 08, 2005 at 06:57:48PM +0100, Andrew Hucthings wrote:
> Funky stuff, I'm sure I'll annoy you with an obscure bug I dig up
> shortly ;)
> 
> Gonna see if I can write a minor patch for dovecot this week so that we
> can see number of messages downloading in a pop3 session in the logfile.
> Similar to the way UW does it, will be very useful for us at work trying
> to trace customers POP problems, I will submit it if anyone will find it
> useful.

Don't waste your time :) Take a look at the attached patch.

-- 
Andrey Panin		| Linux and UNIX system administrator
pazke at donpac.ru		| PGP key: wwwkeys.pgp.net
-------------- next part --------------
diff -urdpNX /usr/share/dontdiff dovecot-1.0-test69.vanilla/src/imap-login/client-authenticate.c dovecot-1.0-test69/src/imap-login/client-authenticate.c
--- dovecot-1.0-test69.vanilla/src/imap-login/client-authenticate.c	2005-01-08 17:59:03.000000000 +0300
+++ dovecot-1.0-test69/src/imap-login/client-authenticate.c	2005-05-09 10:52:38.418290440 +0400
@@ -188,7 +188,12 @@ static void sasl_callback(struct client 
 
 		client_send_tagline(client, "OK Logged in.");
 		client_destroy(client, t_strconcat(
-			"Login: ", client->common.virtual_user, NULL));
+			"Login: ", client->common.virtual_user,
+			", method: ", client->common.auth_mech_name,
+			client->common.secured ? ", SSL" : "",
+			", lip: [", net_ip2addr(&client->common.local_ip),
+			"], rip:",
+			NULL));
 		break;
 	case SASL_SERVER_REPLY_AUTH_FAILED:
 		if (args != NULL) {
diff -urdpNX /usr/share/dontdiff dovecot-1.0-test69.vanilla/src/pop3/client.c dovecot-1.0-test69/src/pop3/client.c
--- dovecot-1.0-test69.vanilla/src/pop3/client.c	2005-04-29 15:37:34.000000000 +0400
+++ dovecot-1.0-test69/src/pop3/client.c	2005-05-09 10:52:38.437287552 +0400
@@ -156,12 +156,12 @@ struct client *client_create(int hin, in
 		i_error("Couldn't open INBOX: %s",
 			mail_storage_get_last_error(storage, &syntax_error));
 		client_send_line(client, "-ERR No INBOX for user.");
-		client_destroy(client);
+		client_destroy(client, "No INBOX for user.");
 		return NULL;
 	}
 
 	if (!init_mailbox(client)) {
-		client_destroy(client);
+		client_destroy(client, "Mailbox init failed");
 		return NULL;
 	}
 
@@ -173,8 +173,18 @@ struct client *client_create(int hin, in
 	return client;
 }
 
-void client_destroy(struct client *client)
+static const char *client_stats(struct client *client)
+{
+	return t_strdup_printf("top=%d, retr=%d, del=%d/%d", 
+		client->top_bytes, client->retr_bytes,
+		client->deleted_count, client->messages_count);
+}
+
+void client_destroy(struct client *client, const char *reason)
 {
+	if (reason != NULL)
+		i_info("%s %s", reason, client_stats(client));
+
 	if (client->cmd != NULL) {
 		/* deinitialize command */
 		i_stream_close(client->input);
@@ -204,8 +214,11 @@ void client_destroy(struct client *clien
 	io_loop_stop(ioloop);
 }
 
-void client_disconnect(struct client *client)
+void client_disconnect(struct client *client, const char *reason)
 {
+	if (reason != NULL)
+		i_info("%s %s", reason, client_stats(client));
+
 	(void)o_stream_flush(client->output);
 
 	i_stream_close(client->input);
@@ -266,7 +279,7 @@ void client_send_storage_error(struct cl
 	if (mailbox_is_inconsistent(client->mailbox)) {
 		client_send_line(client, "-ERR Mailbox is in inconsistent "
 				 "state, please relogin.");
-		client_disconnect(client);
+		client_disconnect(client, "Mailbox is in inconsistent state.");
 		return;
 	}
 
@@ -295,12 +308,12 @@ static void client_input(void *context)
 	switch (i_stream_read(client->input)) {
 	case -1:
 		/* disconnected */
-		client_destroy(client);
+		client_destroy(client, "Disconnected");
 		return;
 	case -2:
 		/* line too long, kill it */
 		client_send_line(client, "-ERR Input line too long.");
-		client_destroy(client);
+		client_destroy(client, "Input line too long.");
 		return;
 	}
 
@@ -323,13 +336,13 @@ static void client_input(void *context)
 			}
 		} else if (++client->bad_counter > CLIENT_MAX_BAD_COMMANDS) {
 			client_send_line(client, "-ERR Too many bad commands.");
-			client_disconnect(client);
+			client_disconnect(client, "Too many bad commands.");
 		}
 	}
 	o_stream_uncork(client->output);
 
 	if (client->output->closed)
-		client_destroy(client);
+		client_destroy(client, NULL);
 }
 
 static int client_output(void *context)
@@ -338,7 +351,7 @@ static int client_output(void *context)
 	int ret;
 
 	if ((ret = o_stream_flush(client->output)) < 0) {
-		client_destroy(client);
+		client_destroy(client, NULL);
 		return 1;
 	}
 
@@ -371,13 +384,13 @@ static void idle_timeout(void *context _
 	if (my_client->cmd != NULL) {
 		if (ioloop_time - my_client->last_output >=
 		    CLIENT_OUTPUT_TIMEOUT)
-			client_destroy(my_client);
+			client_destroy(my_client, "Disconnected for inactivity.");
 	} else {
 		if (ioloop_time - my_client->last_input >=
 		    CLIENT_IDLE_TIMEOUT) {
 			client_send_line(my_client,
 					 "-ERR Disconnected for inactivity.");
-			client_destroy(my_client);
+			client_destroy(my_client, "Disconnected for inactivity.");
 		}
 	}
 }
@@ -392,7 +405,7 @@ void clients_deinit(void)
 {
 	if (my_client != NULL) {
 		client_send_line(my_client, "-ERR Server shutting down.");
-		client_destroy(my_client);
+		client_destroy(my_client, "Server shutting down.");
 	}
 
 	timeout_remove(to_idle);
diff -urdpNX /usr/share/dontdiff dovecot-1.0-test69.vanilla/src/pop3/client.h dovecot-1.0-test69/src/pop3/client.h
--- dovecot-1.0-test69.vanilla/src/pop3/client.h	2004-12-16 23:50:12.000000000 +0300
+++ dovecot-1.0-test69/src/pop3/client.h	2005-05-09 10:52:38.440287096 +0400
@@ -30,6 +30,10 @@ struct client {
 	uoff_t deleted_size;
 	uint32_t last_seen;
 
+	unsigned int top_bytes;
+	unsigned int retr_bytes;
+	unsigned int *byte_counter;
+
 	unsigned char *deleted_bitmask;
 
 	unsigned int deleted:1;
@@ -39,10 +43,10 @@ struct client {
 /* Create new client with specified input/output handles. socket specifies
    if the handle is a socket. */
 struct client *client_create(int hin, int hout, struct mail_storage *storage);
-void client_destroy(struct client *client);
+void client_destroy(struct client *client, const char *reason);
 
 /* Disconnect client connection */
-void client_disconnect(struct client *client);
+void client_disconnect(struct client *client, const char *reason);
 
 /* Send a line of data to client */
 int client_send_line(struct client *client, const char *fmt, ...)
diff -urdpNX /usr/share/dontdiff dovecot-1.0-test69.vanilla/src/pop3/commands.c dovecot-1.0-test69/src/pop3/commands.c
--- dovecot-1.0-test69.vanilla/src/pop3/commands.c	2005-05-08 13:37:43.000000000 +0400
+++ dovecot-1.0-test69/src/pop3/commands.c	2005-05-09 10:52:38.476281624 +0400
@@ -217,7 +217,7 @@ static int cmd_quit(struct client *clien
 	if (client->deleted) {
 		if (!expunge_mails(client)) {
 			client_send_storage_error(client);
-			client_disconnect(client);
+			client_disconnect(client, "Storage error during logout.");
 			return TRUE;
 		}
 	}
@@ -230,7 +230,7 @@ static int cmd_quit(struct client *clien
 	else
 		client_send_line(client, "+OK Logging out, messages deleted.");
 
-	client_disconnect(client);
+	client_disconnect(client, "Logout.");
 	return TRUE;
 }
 
@@ -311,6 +311,7 @@ static void fetch_callback(struct client
 				break;
 			ctx->last = data[i-1];
 			i_stream_skip(ctx->stream, i);
+			*client->byte_counter += i;
 		}
 
 		if (o_stream_get_buffer_used_size(client->output) >= 4096) {
@@ -326,6 +327,8 @@ static void fetch_callback(struct client
 			if (o_stream_send(client->output, &add, 1) < 0)
 				break;
 
+			*client->byte_counter += 1;
+
 			ctx->last = add;
 			if (add == 0x80)
 				i_stream_skip(ctx->stream, 1);
@@ -335,11 +338,13 @@ static void fetch_callback(struct client
 	if (ctx->last != '\n') {
 		/* didn't end with CRLF */
 		(void)o_stream_send(client->output, "\r\n", 2);
+		*client->byte_counter += 2;
 	}
 
 	if (!ctx->in_body && (client_workarounds & WORKAROUND_OE_NS_EOH) != 0) {
 		/* Add the missing end of headers line. */
 		(void)o_stream_send(client->output, "\r\n", 2);
+		*client->byte_counter += 2;
 	}
 
 	client_send_line(client, ".");
@@ -405,6 +410,8 @@ static int cmd_retr(struct client *clien
 	if (client->last_seen <= msgnum)
 		client->last_seen = msgnum+1;
 
+	client->byte_counter = &client->retr_bytes;
+
 	fetch(client, msgnum, (uoff_t)-1);
 	return TRUE;
 }
@@ -468,6 +475,8 @@ static int cmd_top(struct client *client
 	if (get_size(client, args, &max_lines) == NULL)
 		return FALSE;
 
+	client->byte_counter = &client->top_bytes;
+
 	fetch(client, msgnum, max_lines);
 	return TRUE;
 }
diff -urdpNX /usr/share/dontdiff dovecot-1.0-test69.vanilla/src/pop3-login/client-authenticate.c dovecot-1.0-test69/src/pop3-login/client-authenticate.c
--- dovecot-1.0-test69.vanilla/src/pop3-login/client-authenticate.c	2005-03-08 23:26:56.000000000 +0300
+++ dovecot-1.0-test69/src/pop3-login/client-authenticate.c	2005-05-09 10:52:38.480281016 +0400
@@ -161,7 +161,12 @@ static void sasl_callback(struct client 
 
 		client_send_line(client, "+OK Logged in.");
 		client_destroy(client, t_strconcat(
-			"Login: ", client->common.virtual_user, NULL));
+			"Login: ", client->common.virtual_user,
+			", auth: ", client->common.auth_mech_name,
+			client->common.secured ? ", SSL" : "",
+			", lip: [", net_ip2addr(&client->common.local_ip),
+			"], rip:",
+			NULL));
 		break;
 	case SASL_SERVER_REPLY_AUTH_FAILED:
 		if (args != NULL) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://dovecot.org/pipermail/dovecot/attachments/20050509/89c118ad/attachment-0001.bin>


More information about the dovecot mailing list