From 26a0113bb4ae3dff2a559d987df8af2fd3c0b2a6 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 4 Mar 2011 18:09:01 +0200 Subject: [PATCH] doveadm acl debug: If any errors are noticed, fix them. --- src/plugins/acl/doveadm-acl.c | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/plugins/acl/doveadm-acl.c b/src/plugins/acl/doveadm-acl.c index 3ada7c1f95..bc2c1e644c 100644 --- a/src/plugins/acl/doveadm-acl.c +++ b/src/plugins/acl/doveadm-acl.c @@ -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); -- 2.47.3