dovecot-2.2: lib-storage: If session_id isn't given, generate a ...

dovecot at dovecot.org dovecot at dovecot.org
Sun May 24 21:43:04 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/5f95cc2bd7aa
changeset: 18747:5f95cc2bd7aa
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 24 17:40:53 2015 -0400
description:
lib-storage: If session_id isn't given, generate a new one.
This is useful for tracking logs written by services that aren't directly
related to any specific user session.

diffstat:

 src/lib-storage/mail-storage-service.c |  19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diffs (43 lines):

diff -r 2de3c7248922 -r 5f95cc2bd7aa src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c	Sun May 24 16:13:57 2015 -0400
+++ b/src/lib-storage/mail-storage-service.c	Sun May 24 17:40:53 2015 -0400
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "array.h"
+#include "base64.h"
 #include "hostpid.h"
 #include "module-dir.h"
 #include "restrict-access.h"
@@ -1024,6 +1025,20 @@
 	i_set_failure_prefix("%s", str_c(str));
 }
 
+static const char *mail_storage_service_generate_session_id(pool_t pool)
+{
+	guid_128_t guid;
+	string_t *str = str_new(pool, MAX_BASE64_ENCODED_SIZE(sizeof(guid)));
+
+	guid_128_generate(guid);
+	base64_encode(guid, sizeof(guid), str);
+	/* remove the trailing "==" */
+	i_assert(str_data(str)[str_len(str)-2] == '=');
+	str_truncate(str, str_len(str)-2);
+	return str_c(str);
+
+}
+
 static int
 mail_storage_service_lookup_real(struct mail_storage_service_ctx *ctx,
 				 const struct mail_storage_service_input *input,
@@ -1123,6 +1138,10 @@
 	user->input.userdb_fields = NULL;
 	user->input.username = p_strdup(user_pool, username);
 	user->input.session_id = p_strdup(user_pool, input->session_id);
+	if (user->input.session_id == NULL) {
+		user->input.session_id =
+			mail_storage_service_generate_session_id(user_pool);
+	}
 	user->user_info = user_info;
 	user->flags = flags;
 


More information about the dovecot-cvs mailing list