dovecot-2.2: imap-urlauth: Store urlauth keys to the new mailbox...

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 13 04:28:25 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/6e7e62ee07be
changeset: 15225:6e7e62ee07be
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Oct 13 04:28:09 2012 +0300
description:
imap-urlauth: Store urlauth keys to the new mailbox attributes.

diffstat:

 doc/example-config/conf.d/20-imap.conf          |    3 -
 src/imap-urlauth/imap-urlauth-worker-settings.c |    2 -
 src/imap-urlauth/imap-urlauth-worker-settings.h |    1 -
 src/imap-urlauth/imap-urlauth-worker.c          |   16 +-
 src/imap/imap-client.c                          |   17 +-
 src/imap/imap-settings.c                        |    2 -
 src/imap/imap-settings.h                        |    1 -
 src/lib-imap-urlauth/imap-urlauth-backend.c     |  166 +++++------------------
 src/lib-imap-urlauth/imap-urlauth-backend.h     |   12 +-
 src/lib-imap-urlauth/imap-urlauth-private.h     |    1 -
 src/lib-imap-urlauth/imap-urlauth.c             |   38 ++---
 src/lib-imap-urlauth/imap-urlauth.h             |    8 +-
 12 files changed, 74 insertions(+), 193 deletions(-)

diffs (truncated from 541 to 300 lines):

diff -r 5659c178bdeb -r 6e7e62ee07be doc/example-config/conf.d/20-imap.conf
--- a/doc/example-config/conf.d/20-imap.conf	Sat Oct 13 04:27:14 2012 +0300
+++ b/doc/example-config/conf.d/20-imap.conf	Sat Oct 13 04:28:09 2012 +0300
@@ -57,8 +57,5 @@
   #imap_client_workarounds = 
 }
 
-# Dictionary containing URLAUTH data.
-#imap_urlauth_dict = 
-
 # Host allowed in URLAUTH URLs sent by client. "*" allows all.
 #imap_urlauth_host =
diff -r 5659c178bdeb -r 6e7e62ee07be src/imap-urlauth/imap-urlauth-worker-settings.c
--- a/src/imap-urlauth/imap-urlauth-worker-settings.c	Sat Oct 13 04:27:14 2012 +0300
+++ b/src/imap-urlauth/imap-urlauth-worker-settings.c	Sat Oct 13 04:28:09 2012 +0300
@@ -56,7 +56,6 @@
 static const struct setting_define imap_urlauth_worker_setting_defines[] = {
 	DEF(SET_BOOL, verbose_proctitle),
 
-	DEF(SET_STR_VARS, imap_urlauth_dict),
 	DEF(SET_STR, imap_urlauth_host),
 	DEF(SET_UINT, imap_urlauth_port),
 
@@ -66,7 +65,6 @@
 const struct imap_urlauth_worker_settings imap_urlauth_worker_default_settings = {
 	.verbose_proctitle = FALSE,
 
-	.imap_urlauth_dict = "",
 	.imap_urlauth_host = "",
 	.imap_urlauth_port = 143
 };
diff -r 5659c178bdeb -r 6e7e62ee07be src/imap-urlauth/imap-urlauth-worker-settings.h
--- a/src/imap-urlauth/imap-urlauth-worker-settings.h	Sat Oct 13 04:27:14 2012 +0300
+++ b/src/imap-urlauth/imap-urlauth-worker-settings.h	Sat Oct 13 04:28:09 2012 +0300
@@ -7,7 +7,6 @@
 	bool verbose_proctitle;
 
 	/* imap_urlauth: */
-	const char *imap_urlauth_dict;
 	const char *imap_urlauth_host;
 	unsigned int imap_urlauth_port;
 };
diff -r 5659c178bdeb -r 6e7e62ee07be src/imap-urlauth/imap-urlauth-worker.c
--- a/src/imap-urlauth/imap-urlauth-worker.c	Sat Oct 13 04:27:14 2012 +0300
+++ b/src/imap-urlauth/imap-urlauth-worker.c	Sat Oct 13 04:28:09 2012 +0300
@@ -634,11 +634,8 @@
 	}
 
 	/* initialize urlauth context */
-	if (*set->imap_urlauth_host == '\0' ||
-	    *set->imap_urlauth_dict == '\0') {
-		i_error("%s setting is not configured for user %s",
-			*set->imap_urlauth_host == '\0' ?
-			"imap_urlauth_host" : "imap_urlauth_dict",
+	if (*set->imap_urlauth_host == '\0') {
+		i_error("imap_urlauth_host setting is not configured for user %s",
 			mail_user->username);
 		client_send_line(client, "NO");
 		client_abort(client, "Session aborted: URLAUTH not configured");
@@ -646,7 +643,6 @@
 	}
 
 	memset(&config, 0, sizeof(config));
-	config.dict_uri = set->imap_urlauth_dict;
 	config.url_host = set->imap_urlauth_host;
 	config.url_port = set->imap_urlauth_port;
 	config.access_user = client->access_user;
@@ -654,13 +650,7 @@
 	config.access_applications =
 		(const void *)array_get(&client->access_apps, &count);
 		
-	if (imap_urlauth_init(client->mail_user, &config, &client->urlauth_ctx) < 0) {
-		client_send_line(client, "NO");
-		client_abort(client,
-			"Session aborted: Failed to init URLAUTH context");
-		return 0;
-	}
-
+	client->urlauth_ctx = imap_urlauth_init(client->mail_user, &config);
 	if (client->debug) {
 		i_debug("Providing access to user account `%s' on behalf of `%s'",
 			mail_user->username, client->access_user);
diff -r 5659c178bdeb -r 6e7e62ee07be src/imap/imap-client.c
--- a/src/imap/imap-client.c	Sat Oct 13 04:27:14 2012 +0300
+++ b/src/imap/imap-client.c	Sat Oct 13 04:28:09 2012 +0300
@@ -39,12 +39,11 @@
 	client_destroy(client, "Disconnected for inactivity");
 }
 
-static int client_init_urlauth(struct client *client)
+static void client_init_urlauth(struct client *client)
 {
 	struct imap_urlauth_config config;
 
 	memset(&config, 0, sizeof(config));
-	config.dict_uri = client->set->imap_urlauth_dict;
 	config.url_host = client->set->imap_urlauth_host;
 	config.url_port = client->set->imap_urlauth_port;
 	config.socket_path = t_strconcat(client->user->set->base_dir,
@@ -53,7 +52,7 @@
 	config.access_anonymous = client->user->anonymous;
 	config.access_user = client->user->username;
 
-	return imap_urlauth_init(client->user, &config, &client->urlauth_ctx);
+	client->urlauth_ctx = imap_urlauth_init(client->user, &config);
 }
 
 struct client *client_create(int fd_in, int fd_out, const char *session_id,
@@ -129,13 +128,13 @@
 		str_append(client->capability_string, " NOTIFY");
 	}
 
-	if (*set->imap_urlauth_host != '\0' && *set->imap_urlauth_dict != '\0') {
-		if (client_init_urlauth(client) == 0 &&
-		    !explicit_capability) {
-			/* Enable URLAUTH capability only when dict is
-			   configured correctly */
+	if (*set->imap_urlauth_host != '\0' &&
+	    *mail_set->mail_attribute_dict != '\0') {
+		/* Enable URLAUTH capability only when dict is
+		   configured correctly */
+		client_init_urlauth(client);
+		if (!explicit_capability)
 			str_append(client->capability_string, " URLAUTH URLAUTH=BINARY");
-		}
 	}
 
 	ident = mail_user_get_anvil_userip_ident(client->user);
diff -r 5659c178bdeb -r 6e7e62ee07be src/imap/imap-settings.c
--- a/src/imap/imap-settings.c	Sat Oct 13 04:27:14 2012 +0300
+++ b/src/imap/imap-settings.c	Sat Oct 13 04:28:09 2012 +0300
@@ -70,7 +70,6 @@
 	DEF(SET_STR, imap_id_send),
 	DEF(SET_STR, imap_id_log),
 
-	DEF(SET_STR_VARS, imap_urlauth_dict),
 	DEF(SET_STR, imap_urlauth_host),
 	DEF(SET_UINT, imap_urlauth_port),
 
@@ -91,7 +90,6 @@
 	.imap_id_send = "",
 	.imap_id_log = "",
 
-	.imap_urlauth_dict = "",
 	.imap_urlauth_host = "",
 	.imap_urlauth_port = 143
 };
diff -r 5659c178bdeb -r 6e7e62ee07be src/imap/imap-settings.h
--- a/src/imap/imap-settings.h	Sat Oct 13 04:27:14 2012 +0300
+++ b/src/imap/imap-settings.h	Sat Oct 13 04:28:09 2012 +0300
@@ -24,7 +24,6 @@
 	const char *imap_id_log;
 
 	/* imap urlauth: */
-	const char *imap_urlauth_dict;
 	const char *imap_urlauth_host;
 	unsigned int imap_urlauth_port;
 
diff -r 5659c178bdeb -r 6e7e62ee07be src/lib-imap-urlauth/imap-urlauth-backend.c
--- a/src/lib-imap-urlauth/imap-urlauth-backend.c	Sat Oct 13 04:27:14 2012 +0300
+++ b/src/lib-imap-urlauth/imap-urlauth-backend.c	Sat Oct 13 04:28:09 2012 +0300
@@ -4,117 +4,35 @@
 #include "buffer.h"
 #include "hex-binary.h"
 #include "randgen.h"
-#include "dict.h"
 #include "mail-user.h"
 #include "mail-storage.h"
+#include "mailbox-list-iter.h"
 #include "imap-urlauth-private.h"
 #include "imap-urlauth-backend.h"
 
-#define IMAP_URLAUTH_PATH DICT_PATH_PRIVATE"imap-urlauth/"
+#define IMAP_URLAUTH_KEY "imap-urlauth"
 
-struct imap_urlauth_backend {
-	struct mail_user *user;
-	struct dict *dict;
-};
-
-int imap_urlauth_backend_create(struct mail_user *user, const char *dict_uri,
-				struct imap_urlauth_backend **backend_r)
-{
-	struct imap_urlauth_backend *backend;
-	struct dict *dict;
-	const char *error;
-
-	if (user->mail_debug)
-		i_debug("imap-urlauth backend: opening backend dict URI %s", dict_uri);
-
-	if (dict_init(dict_uri, DICT_DATA_TYPE_STRING,
-		      user->username, user->set->base_dir, &dict, &error) < 0) {
-		i_error("imap_urlauth_dict: Failed to initialize dict: %s", error);
-		return -1;
-	}
-
-	backend = i_new(struct imap_urlauth_backend, 1);
-	backend->user = user;
-	backend->dict = dict;
-
-	random_init();
-	*backend_r = backend;
-	return 0;
-}
-
-void imap_urlauth_backend_destroy(struct imap_urlauth_backend **_backend)
-{
-	struct imap_urlauth_backend *backend = *_backend;
-
-	*_backend = NULL;
-
-	if (backend->dict != NULL) {
-		(void)dict_wait(backend->dict);
-		dict_deinit(&backend->dict);
-	}
-	i_free(backend);
-	random_deinit();
-}
-
-static int
-imap_urlauth_backend_set_key(struct imap_urlauth_backend *backend,
-			     const char *path, const char *mailbox_key)
-{
-	struct dict_transaction_context *dtrans;
-
-	dtrans = dict_transaction_begin(backend->dict);
-	dict_set(dtrans, path, mailbox_key);
-	return dict_transaction_commit(&dtrans) < 0 ? -1 : 1;
-}
-
-static int
-imap_urlauth_backend_reset_key(struct imap_urlauth_backend *backend,
-			       const char *path)
-{
-	struct dict_transaction_context *dtrans;
-
-	dtrans = dict_transaction_begin(backend->dict);
-	dict_unset(dtrans, path);
-	return dict_transaction_commit(&dtrans) < 0 ? -1 : 1;
-}
-
-static int
-imap_urlauth_backend_get_key(struct imap_urlauth_backend *backend,
-			     const char *path, const char **mailbox_key_r)
-{
-	return dict_lookup(backend->dict, pool_datastack_create(), path,
-			   mailbox_key_r);
-}
-
-int imap_urlauth_backend_get_mailbox_key(struct imap_urlauth_backend *backend,
-					 struct mailbox *box, bool create,
+int imap_urlauth_backend_get_mailbox_key(struct mailbox *box, bool create,
 					 unsigned char mailbox_key_r[IMAP_URLAUTH_KEY_LEN],
 					 const char **error_r,
 					 enum mail_error *error_code_r)
 {
-	const char *path, *mailbox_key_hex = NULL;
-	struct mailbox_metadata metadata;
-	const char *mailbox = mailbox_get_vname(box);
+	struct mail_user *user = mail_storage_get_user(mailbox_get_storage(box));
+	const char *mailbox_key_hex = NULL;
 	buffer_t key_buf;
 	int ret;
 
 	*error_r = "Internal server error";
 	*error_code_r = MAIL_ERROR_TEMP;
 
-	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
-		*error_r = mailbox_get_last_error(box, error_code_r);
-		return -1;
-	}
-	mailbox = guid_128_to_string(metadata.guid);
-
-	path = t_strconcat(IMAP_URLAUTH_PATH, dict_escape_string(mailbox), NULL);
-	if ((ret = imap_urlauth_backend_get_key(backend, path,
-						&mailbox_key_hex)) < 0)
+	ret = mailbox_attribute_get(box, MAIL_ATTRIBUTE_TYPE_PRIVATE,
+				    IMAP_URLAUTH_KEY, &mailbox_key_hex);
+	if (ret < 0)
 		return -1;
 
-	if (backend->user->mail_debug) {
-		i_debug("imap-urlauth backend: %skey found for mailbox %s at %s",
-			(ret > 0 ? "" : "no "), mailbox, path);
+	if (user->mail_debug) {
+		i_debug("imap-urlauth: %skey found for mailbox %s",
+			(ret > 0 ? "" : "no "), mailbox_get_vname(box));
 	}
 
 	if (ret == 0) {
@@ -125,12 +43,13 @@
 		random_fill(mailbox_key_r, IMAP_URLAUTH_KEY_LEN);
 		mailbox_key_hex = binary_to_hex(mailbox_key_r,
 						IMAP_URLAUTH_KEY_LEN);
-		if ((ret = imap_urlauth_backend_set_key(backend, path,
-							mailbox_key_hex)) < 0)
+		ret = mailbox_attribute_set(box, MAIL_ATTRIBUTE_TYPE_PRIVATE,
+					    IMAP_URLAUTH_KEY, mailbox_key_hex);
+		if (ret < 0)
 			return -1;


More information about the dovecot-cvs mailing list