]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm acl debug: If any errors are noticed, fix them.
authorTimo Sirainen <tss@iki.fi>
Fri, 4 Mar 2011 16:09:01 +0000 (18:09 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 4 Mar 2011 16:09:01 +0000 (18:09 +0200)
src/plugins/acl/doveadm-acl.c

index 3ada7c1f9539cd98efb75967680071f446246c3b..bc2c1e644c0f5075e354ee8bbc1ceb55b454c463 100644 (file)
@@ -334,7 +334,7 @@ cmd_acl_delete_alloc(void)
        return ctx;
 }
 
-static bool cmd_acl_debug_mailbox(struct mailbox *box)
+static bool cmd_acl_debug_mailbox(struct mailbox *box, bool *retry_r)
 {
        struct mail_namespace *ns = mailbox_get_namespace(box);
        struct acl_user *auser = ACL_USER_CONTEXT(ns->user);
@@ -345,6 +345,9 @@ static bool cmd_acl_debug_mailbox(struct mailbox *box)
        const char *const *rights, *name;
        string_t *str;
        int ret;
+       bool all_ok = TRUE;
+
+       *retry_r = FALSE;
 
        if (box->private_flags_mask == 0)
                i_info("All message flags are shared across users in mailbox");
@@ -386,10 +389,14 @@ static bool cmd_acl_debug_mailbox(struct mailbox *box)
        if (ret < 0)
                i_fatal("ACL non-owner iteration failed");
        if (ret == 0) {
-               i_error("Mailbox not found from dovecot-acl-list");
-               return FALSE;
+               i_error("Mailbox not found from dovecot-acl-list, rebuilding");
+               if (acl_backend_nonowner_lookups_rebuild(backend) < 0)
+                       i_fatal("dovecot-acl-list rebuilding failed");
+               all_ok = FALSE;
+               *retry_r = TRUE;
+       } else {
+               i_info("Mailbox found from dovecot-acl-list");
        }
-       i_info("Mailbox found from dovecot-acl-list");
 
        if (ns->type == NAMESPACE_PUBLIC) {
                i_info("Mailbox is in public namespace");
@@ -410,13 +417,17 @@ static bool cmd_acl_debug_mailbox(struct mailbox *box)
        if (acl_lookup_dict_iterate_visible_deinit(&diter) < 0)
                i_fatal("ACL shared dict iteration failed");
        if (name == NULL) {
-               i_error("User %s not found from ACL shared dict",
+               i_error("User %s not found from ACL shared dict, rebuilding",
                        ns->owner->username);
-               return FALSE;
+               if (acl_lookup_dict_rebuild(auser->acl_lookup_dict) < 0)
+                       i_fatal("ACL lookup dict rebuild failed");
+               all_ok = FALSE;
+               *retry_r = TRUE;
+       } else {
+               i_info("User %s found from ACL shared dict",
+                      ns->owner->username);
        }
-
-       i_info("User %s found from ACL shared dict", ns->owner->username);
-       return TRUE;
+       return all_ok;
 }
 
 static void
@@ -424,11 +435,17 @@ cmd_acl_debug_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
 {
        const char *mailbox = ctx->args[0];
        struct mailbox *box;
+       bool ret, retry;
 
        if (cmd_acl_mailbox_open(user, mailbox, &box) < 0)
                return;
 
-       if (cmd_acl_debug_mailbox(box))
+       ret = cmd_acl_debug_mailbox(box, &retry);
+       if (!ret && retry) {
+               i_info("Retrying after rebuilds:");
+               ret = cmd_acl_debug_mailbox(box, &retry);
+       }
+       if (ret)
                i_info("Mailbox %s is visible in LIST", box->vname);
        else
                i_info("Mailbox %s is NOT visible in LIST", box->vname);