dovecot-2.2-pigeonhole: Added a "session ID" string for managesi...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sun May 20 13:17:09 EEST 2012


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/e55350fb6786
changeset: 1612:e55350fb6786
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Thu Mar 08 11:02:05 2012 +0100
description:
Added a "session ID" string for managesieve connections, available in %{session} variable.
This change matches a similar change in Dovecot for IMAP/POP3.
Also includes other small changes that make ManageSieve match IMAP implementation a little more closely.

diffstat:

 src/managesieve/main.c               |  11 +++++++++--
 src/managesieve/managesieve-client.c |  16 +++++++++-------
 src/managesieve/managesieve-client.h |   9 ++++++---
 src/managesieve/managesieve-common.h |   4 ++++
 4 files changed, 28 insertions(+), 12 deletions(-)

diffs (159 lines):

diff -r 36c9ab4d2b45 -r e55350fb6786 src/managesieve/main.c
--- a/src/managesieve/main.c	Wed Mar 07 22:04:06 2012 +0100
+++ b/src/managesieve/main.c	Thu Mar 08 11:02:05 2012 +0100
@@ -139,11 +139,11 @@
 	if (set->verbose_proctitle)
 		verbose_proctitle = TRUE;
 
-	client = client_create(fd_in, fd_out, mail_user, user, set);
+	client = client_create
+		(fd_in, fd_out, input->session_id, mail_user, user, set);
 	T_BEGIN {
 		client_add_input(client, input_buf);
 	} T_END;
-
 	return 0;
 }
 
@@ -178,6 +178,7 @@
 login_client_connected(const struct master_login_client *client,
 		       const char *username, const char *const *extra_fields)
 {
+#define MSG_BYE_INTERNAL_ERROR "BYE \""CRITICAL_MSG"\"\r\n"
 	struct mail_storage_service_input input;
 	const char *error;
 	buffer_t input_buf;
@@ -188,11 +189,17 @@
 	input.remote_ip = client->auth_req.remote_ip;
 	input.username = username;
 	input.userdb_fields = extra_fields;
+	input.session_id = client->session_id;
 
 	buffer_create_const_data(&input_buf, client->data,
 				 client->auth_req.data_size);
 	if (client_create_from_input(&input, client->fd, client->fd,
 				     &input_buf, &error) < 0) {
+		if (write(client->fd, MSG_BYE_INTERNAL_ERROR,
+			  strlen(MSG_BYE_INTERNAL_ERROR)) < 0) {
+			if (errno != EAGAIN && errno != EPIPE)
+				i_error("write(client) failed: %m");
+		}
 		i_error("%s", error);
 		(void)close(client->fd);
 		master_service_client_connection_destroyed(master_service);
diff -r 36c9ab4d2b45 -r e55350fb6786 src/managesieve/managesieve-client.c
--- a/src/managesieve/managesieve-client.c	Wed Mar 07 22:04:06 2012 +0100
+++ b/src/managesieve/managesieve-client.c	Thu Mar 08 11:02:05 2012 +0100
@@ -24,10 +24,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#define CRITICAL_MSG \
-  "Internal error occured. Refer to server log for more information."
-#define CRITICAL_MSG_STAMP CRITICAL_MSG " [%Y-%m-%d %H:%M:%S]"
-
 extern struct mail_storage_callbacks mail_storage_callbacks;
 struct managesieve_module_register managesieve_module_register = { 0 };
 
@@ -106,7 +102,7 @@
 }
 
 struct client *client_create
-(int fd_in, int fd_out, struct mail_user *user,
+(int fd_in, int fd_out, const char *session_id, struct mail_user *user,
 	struct mail_storage_service_user *service_user,
 	const struct managesieve_settings *set)
 {
@@ -114,6 +110,7 @@
 	const char *ident;
 	struct sieve_instance *svinst;
 	struct sieve_storage *storage;
+	pool_t pool;
 
 	/* Always use nonblocking I/O */
 
@@ -132,9 +129,12 @@
 	net_set_nonblock(fd_in, TRUE);
 	net_set_nonblock(fd_out, TRUE);
 
-	client = i_new(struct client, 1);
+	pool = pool_alloconly_create("managesieve client", 1024);
+	client = p_new(pool, struct client, 1);
+	client->pool = pool;
 	client->set = set;
 	client->service_user = service_user;
+	client->session_id = p_strdup(pool, session_id);
 	client->fd_in = fd_in;
 	client->fd_out = fd_out;
 	client->input = i_stream_create_fd
@@ -179,6 +179,7 @@
 	static struct var_expand_table static_tab[] = {
 		{ 'i', NULL, "input" },
 		{ 'o', NULL, "output" },
+		{ '\0', NULL, "session" },
 		{ '\0', NULL, NULL }
 	};
 	struct var_expand_table *tab;
@@ -189,6 +190,7 @@
 
 	tab[0].value = dec2str(client->input->v_offset);
 	tab[1].value = dec2str(client->output->offset);
+	tab[2].value = client->session_id;
 
 	str = t_str_new(128);
 	var_expand(str, client->set->managesieve_logout_format, tab);
@@ -264,7 +266,7 @@
 	sieve_deinit(&client->svinst);
 
 	pool_unref(&client->cmd.pool);
-	i_free(client);
+	pool_unref(&client->pool);
 
 	master_service_client_connection_destroyed(master_service);
 	managesieve_refresh_proctitle();
diff -r 36c9ab4d2b45 -r e55350fb6786 src/managesieve/managesieve-client.h
--- a/src/managesieve/managesieve-client.h	Wed Mar 07 22:04:06 2012 +0100
+++ b/src/managesieve/managesieve-client.h	Thu Mar 08 11:02:05 2012 +0100
@@ -35,12 +35,14 @@
 struct client {
 	struct client *prev, *next;
 
+	const char *session_id;
 	int fd_in, fd_out;
 	struct io *io;
 	struct istream *input;
 	struct ostream *output;
 	struct timeout *to_idle, *to_idle_output;
 
+	pool_t pool;
 	struct mail_storage_service_user *service_user;
 	const struct managesieve_settings *set;
 
@@ -71,9 +73,10 @@
 
 /* Create new client with specified input/output handles. socket specifies
    if the handle is a socket. */
-struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
-			     struct mail_storage_service_user *service_user,
-			     const struct managesieve_settings *set);
+struct client *client_create
+	(int fd_in, int fd_out, const char *session_id, struct mail_user *user, 
+		struct mail_storage_service_user *service_user,
+		const struct managesieve_settings *set);
 void client_destroy(struct client *client, const char *reason);
 
 void client_dump_capability(struct client *client);
diff -r 36c9ab4d2b45 -r e55350fb6786 src/managesieve/managesieve-common.h
--- a/src/managesieve/managesieve-common.h	Wed Mar 07 22:04:06 2012 +0100
+++ b/src/managesieve/managesieve-common.h	Thu Mar 08 11:02:05 2012 +0100
@@ -18,6 +18,10 @@
 /* Disconnect client when it sends too many bad commands in a row */
 #define CLIENT_MAX_BAD_COMMANDS 20
 
+#define CRITICAL_MSG \
+  "Internal error occured. Refer to server log for more information."
+#define CRITICAL_MSG_STAMP CRITICAL_MSG " [%Y-%m-%d %H:%M:%S]"
+
 #include "lib.h"
 #include "managesieve-client.h"
 #include "managesieve-settings.h"


More information about the dovecot-cvs mailing list