dovecot-2.2: imap-urlauth: Use mailbox GUID instead of mailbox n...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Oct 13 02:08:22 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/327dc9a8decc
changeset: 15221:327dc9a8decc
user: Timo Sirainen <tss at iki.fi>
date: Sat Oct 13 01:57:24 2012 +0300
description:
imap-urlauth: Use mailbox GUID instead of mailbox name for dict keys
diffstat:
src/imap/cmd-resetkey.c | 9 +++++++--
src/lib-imap-urlauth/imap-urlauth-backend.c | 29 +++++++++++++++++++++++------
src/lib-imap-urlauth/imap-urlauth-backend.h | 4 +++-
src/lib-imap-urlauth/imap-urlauth.c | 12 ++++++------
4 files changed, 39 insertions(+), 15 deletions(-)
diffs (152 lines):
diff -r dbefcfb9d330 -r 327dc9a8decc src/imap/cmd-resetkey.c
--- a/src/imap/cmd-resetkey.c Sat Oct 13 01:38:48 2012 +0300
+++ b/src/imap/cmd-resetkey.c Sat Oct 13 01:57:24 2012 +0300
@@ -24,6 +24,7 @@
struct mail_namespace *ns;
enum mailbox_flags flags = MAILBOX_FLAG_READONLY;
struct mailbox *box;
+ int ret;
/* check mechanism arguments (we support only INTERNAL mechanism) */
while (!IMAP_ARG_IS_EOL(mech_args)) {
@@ -65,8 +66,12 @@
}
/* check urlauth environment and reset requested key */
- if (imap_urlauth_reset_mailbox_key(cmd->client->urlauth_ctx, box) < 0) {
- client_send_internal_error(cmd);
+ ret = imap_urlauth_reset_mailbox_key(cmd->client->urlauth_ctx, box);
+ if (ret <= 0) {
+ if (ret < 0)
+ client_send_internal_error(cmd);
+ else
+ client_send_storage_error(cmd, mailbox_get_storage(box));
mailbox_free(&box);
return TRUE;
}
diff -r dbefcfb9d330 -r 327dc9a8decc src/lib-imap-urlauth/imap-urlauth-backend.c
--- a/src/lib-imap-urlauth/imap-urlauth-backend.c Sat Oct 13 01:38:48 2012 +0300
+++ b/src/lib-imap-urlauth/imap-urlauth-backend.c Sat Oct 13 01:57:24 2012 +0300
@@ -88,13 +88,25 @@
int imap_urlauth_backend_get_mailbox_key(struct imap_urlauth_backend *backend,
struct mailbox *box, bool create,
- unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN])
+ 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);
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)
@@ -110,8 +122,8 @@
return 0;
/* create new key */
- random_fill(mailbox_key, IMAP_URLAUTH_KEY_LEN);
- mailbox_key_hex = binary_to_hex(mailbox_key,
+ 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)
@@ -122,7 +134,7 @@
}
} else {
/* read existing key */
- buffer_create_from_data(&key_buf, mailbox_key,
+ buffer_create_from_data(&key_buf, mailbox_key_r,
IMAP_URLAUTH_KEY_LEN);
if (strlen(mailbox_key_hex) != 2*IMAP_URLAUTH_KEY_LEN ||
hex_to_binary(mailbox_key_hex, &key_buf) < 0 ||
@@ -131,7 +143,7 @@
mailbox, path);
return -1;
}
- memcpy(mailbox_key, key_buf.data, IMAP_URLAUTH_KEY_LEN);
+ memcpy(mailbox_key_r, key_buf.data, IMAP_URLAUTH_KEY_LEN);
}
return 1;
}
@@ -139,7 +151,12 @@
int imap_urlauth_backend_reset_mailbox_key(struct imap_urlauth_backend *backend,
struct mailbox *box)
{
- const char *path, *mailbox = mailbox_get_vname(box);
+ const char *path, *mailbox;
+ struct mailbox_metadata metadata;
+
+ if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0)
+ return 0;
+ mailbox = guid_128_to_string(metadata.guid);
path = t_strconcat(IMAP_URLAUTH_PATH, dict_escape_string(mailbox), NULL);
return imap_urlauth_backend_reset_key(backend, path) < 0 ? -1 : 1;
diff -r dbefcfb9d330 -r 327dc9a8decc src/lib-imap-urlauth/imap-urlauth-backend.h
--- a/src/lib-imap-urlauth/imap-urlauth-backend.h Sat Oct 13 01:38:48 2012 +0300
+++ b/src/lib-imap-urlauth/imap-urlauth-backend.h Sat Oct 13 01:57:24 2012 +0300
@@ -11,7 +11,9 @@
int imap_urlauth_backend_get_mailbox_key(struct imap_urlauth_backend *backend,
struct mailbox *box, bool create,
- unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN]);
+ unsigned char mailbox_key_r[IMAP_URLAUTH_KEY_LEN],
+ const char **error_r,
+ enum mail_error *error_code_r);
int imap_urlauth_backend_reset_mailbox_key(struct imap_urlauth_backend *backend,
struct mailbox *box);
int imap_urlauth_backend_reset_all_keys(struct imap_urlauth_backend *backend);
diff -r dbefcfb9d330 -r 327dc9a8decc src/lib-imap-urlauth/imap-urlauth.c
--- a/src/lib-imap-urlauth/imap-urlauth.c Sat Oct 13 01:38:48 2012 +0300
+++ b/src/lib-imap-urlauth/imap-urlauth.c Sat Oct 13 01:57:24 2012 +0300
@@ -238,6 +238,7 @@
struct imap_msgpart_url *mpurl;
struct mailbox *box;
const char *error;
+ enum mail_error error_code;
unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN];
const unsigned char *token;
size_t token_len;
@@ -298,11 +299,11 @@
/* obtain mailbox key */
ret = imap_urlauth_backend_get_mailbox_key(uctx->backend, box, TRUE,
- mailbox_key);
+ mailbox_key, error_r,
+ &error_code);
if (ret < 0) {
- *error_r = "Internal server error";
imap_msgpart_url_free(&mpurl);
- return -1;
+ return ret;
}
token = imap_urlauth_internal_generate(rumpurl, mailbox_key, &token_len);
@@ -418,10 +419,9 @@
/* obtain mailbox key */
ret = imap_urlauth_backend_get_mailbox_key(uctx->backend, box, FALSE,
- mailbox_key);
+ mailbox_key, error_r,
+ error_code_r);
if (ret < 0) {
- *error_r = "Internal server error";
- *error_code_r = MAIL_ERROR_TEMP;
imap_msgpart_url_free(&mpurl);
return -1;
}
More information about the dovecot-cvs
mailing list