Mercurial > dovecot > core-2.2
changeset 19499:097a0175a591
virtual: Fixed assert-crash when opening virtual mailbox triggered backend mailbox autocreation.
Fixes assert:
Panic: file virtual-storage.c: line 335 (virtual_mailbox_opened_hook):
assertion failed: (!bbox->open_tracked)
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 09 Dec 2015 15:31:37 +0200 |
parents | d397b0ad0ac4 |
children | 452f9b0ea9f4 |
files | src/plugins/virtual/virtual-plugin.c src/plugins/virtual/virtual-storage.c src/plugins/virtual/virtual-storage.h |
diffstat | 3 files changed, 39 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/virtual/virtual-plugin.c Wed Dec 09 13:51:35 2015 +0200 +++ b/src/plugins/virtual/virtual-plugin.c Wed Dec 09 15:31:37 2015 +0200 @@ -8,7 +8,8 @@ const char *virtual_plugin_version = DOVECOT_ABI_VERSION; static struct mail_storage_hooks acl_mail_storage_hooks = { - .mailbox_opened = virtual_mailbox_opened_hook + .mailbox_allocated = virtual_backend_mailbox_allocated, + .mailbox_opened = virtual_backend_mailbox_opened }; void virtual_plugin_init(struct module *module ATTR_UNUSED)
--- a/src/plugins/virtual/virtual-storage.c Wed Dec 09 13:51:35 2015 +0200 +++ b/src/plugins/virtual/virtual-storage.c Wed Dec 09 15:31:37 2015 +0200 @@ -22,12 +22,21 @@ #define VIRTUAL_DEFAULT_MAX_OPEN_MAILBOXES 64 +#define VIRTUAL_BACKEND_CONTEXT(obj) \ + MODULE_CONTEXT(obj, virtual_backend_storage_module) + +struct virtual_backend_mailbox { + union mailbox_module_context module_ctx; +}; + extern struct mail_storage virtual_storage; extern struct mailbox virtual_mailbox; extern struct virtual_mailbox_vfuncs virtual_mailbox_vfuncs; struct virtual_storage_module virtual_storage_module = MODULE_CONTEXT_INIT(&mail_storage_module_register); +static MODULE_CONTEXT_DEFINE_INIT(virtual_backend_storage_module, + &mail_storage_module_register); static bool ns_is_visible(struct mail_namespace *ns) { @@ -323,7 +332,32 @@ return FALSE; } -void virtual_mailbox_opened_hook(struct mailbox *box) +static void virtual_backend_mailbox_close(struct mailbox *box) +{ + struct virtual_backend_box *bbox = VIRTUAL_CONTEXT(box); + struct virtual_backend_mailbox *vbox = VIRTUAL_BACKEND_CONTEXT(box); + + if (bbox != NULL && bbox->open_tracked) { + /* we could have gotten here from e.g. mailbox_autocreate() + without going through virtual_mailbox_close() */ + virtual_backend_box_close(bbox->virtual_mbox, bbox); + } + vbox->module_ctx.super.close(box); +} + +void virtual_backend_mailbox_allocated(struct mailbox *box) +{ + struct mailbox_vfuncs *v = box->vlast; + struct virtual_backend_mailbox *vbox; + + vbox = p_new(box->pool, struct virtual_backend_mailbox, 1); + vbox->module_ctx.super = *v; + box->vlast = &vbox->module_ctx.super; + v->close = virtual_backend_mailbox_close; + MODULE_CONTEXT_SET(box, virtual_backend_storage_module, vbox); +} + +void virtual_backend_mailbox_opened(struct mailbox *box) { struct virtual_backend_box *bbox = VIRTUAL_CONTEXT(box); struct virtual_mailbox *mbox;
--- a/src/plugins/virtual/virtual-storage.h Wed Dec 09 13:51:35 2015 +0200 +++ b/src/plugins/virtual/virtual-storage.h Wed Dec 09 15:31:37 2015 +0200 @@ -225,6 +225,7 @@ void virtual_box_copy_error(struct mailbox *dest, struct mailbox *src); -void virtual_mailbox_opened_hook(struct mailbox *box); +void virtual_backend_mailbox_allocated(struct mailbox *box); +void virtual_backend_mailbox_opened(struct mailbox *box); #endif