dovecot-2.0: doveadm acl debug: Show also path to mailbox if it ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 3 18:11:08 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/5b03ca65f4ed
changeset: 12839:5b03ca65f4ed
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 03 18:11:00 2011 +0300
description:
doveadm acl debug: Show also path to mailbox if it doens't exist.

diffstat:

 src/plugins/acl/doveadm-acl.c |  47 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)

diffs (64 lines):

diff -r 99da5f4f375d -r 5b03ca65f4ed src/plugins/acl/doveadm-acl.c
--- a/src/plugins/acl/doveadm-acl.c	Fri Jun 03 17:37:25 2011 +0300
+++ b/src/plugins/acl/doveadm-acl.c	Fri Jun 03 18:11:00 2011 +0300
@@ -353,6 +353,51 @@
 	return ctx;
 }
 
+static int
+cmd_acl_debug_mailbox_open(struct mail_user *user, const char *mailbox,
+			   struct mailbox **box_r)
+{
+	struct acl_user *auser = ACL_USER_CONTEXT(user);
+	struct mail_namespace *ns;
+	struct mailbox *box;
+	const char *storage_name, *path, *errstr;
+	enum mail_error error;
+
+	storage_name = mailbox;
+	ns = mail_namespace_find(user->namespaces, &storage_name);
+	if (ns == NULL) {
+		i_error("No namespace found for mailbox %s", mailbox);
+		return -1;
+	}
+	box = mailbox_alloc(ns->list, storage_name,
+			    MAILBOX_FLAG_READONLY | MAILBOX_FLAG_KEEP_RECENT |
+			    MAILBOX_FLAG_IGNORE_ACLS);
+	if (mailbox_open(box) < 0) {
+		path = mailbox_list_get_path(ns->list, storage_name,
+					     MAILBOX_LIST_PATH_TYPE_MAILBOX);
+		errstr = mail_storage_get_last_error(box->storage, &error);
+		if (error != MAIL_ERROR_NOTFOUND ||
+		    path == NULL || *path == '\0')
+			i_error("Can't open mailbox %s: %s", mailbox, errstr);
+		else {
+			i_error("Mailbox '%s' doesn't exist in %s",
+				mailbox, path);
+		}
+		mailbox_free(&box);
+		return -1;
+	}
+
+	if (auser == NULL) {
+		i_info("ACL not enabled for user %s, mailbox can be accessed",
+		       user->username);
+		mailbox_free(&box);
+		return -1;
+	}
+
+	*box_r = box;
+	return 0;
+}
+
 static bool cmd_acl_debug_mailbox(struct mailbox *box, bool *retry_r)
 {
 	struct mail_namespace *ns = mailbox_get_namespace(box);
@@ -456,7 +501,7 @@
 	struct mailbox *box;
 	bool ret, retry;
 
-	if (cmd_acl_mailbox_open(user, mailbox, &box) < 0)
+	if (cmd_acl_debug_mailbox_open(user, mailbox, &box) < 0)
 		return;
 
 	ret = cmd_acl_debug_mailbox(box, &retry);


More information about the dovecot-cvs mailing list