]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Shared mailboxes: Find the final storage before calling mail_storage.mailbox_open...
authorTimo Sirainen <tss@iki.fi>
Tue, 7 Apr 2009 21:54:32 +0000 (17:54 -0400)
committerTimo Sirainen <tss@iki.fi>
Tue, 7 Apr 2009 21:54:32 +0000 (17:54 -0400)
This fixes some crashes with plugins.

--HG--
branch : HEAD

src/lib-storage/index/shared/shared-list.c
src/lib-storage/index/shared/shared-storage.c
src/lib-storage/list/mailbox-list-fs.c
src/lib-storage/list/mailbox-list-maildir.c
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-list-private.h

index 3989af0fe1863ef75ca1977861c9462ba26d933f..b9e29703184d9cfed2604c65f686b174419e5f15 100644 (file)
@@ -42,6 +42,18 @@ static void shared_list_copy_error(struct mailbox_list *shared_list,
        mailbox_list_set_error(shared_list, error, str);
 }
 
+static int
+shared_get_storage(struct mailbox_list *list, const char *name,
+                  struct mail_storage **storage_r)
+{
+       struct mail_namespace *ns;
+
+       if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
+               return -1;
+       *storage_r = ns->storage;
+       return 0;
+}
+
 static bool
 shared_is_valid_pattern(struct mailbox_list *list, const char *pattern)
 {
@@ -292,6 +304,7 @@ struct mailbox_list shared_mailbox_list = {
        {
                shared_list_alloc,
                shared_list_deinit,
+               shared_get_storage,
                shared_is_valid_pattern,
                shared_is_valid_existing_name,
                shared_is_valid_create_name,
index 612935ec81f2dce599204d9d088b1ec7c8446f51..a4f14682b75005703f091b63c9faf9190a97068b 100644 (file)
@@ -291,33 +291,6 @@ static void shared_mailbox_copy_error(struct mail_storage *shared_storage,
        mail_storage_set_error(shared_storage, error, str);
 }
 
-static struct mailbox *
-shared_mailbox_open(struct mail_storage *storage, const char *name,
-                   struct istream *input, enum mailbox_open_flags flags)
-{
-       struct mail_namespace *ns;
-       struct mailbox *box;
-
-       if (input != NULL) {
-               mail_storage_set_critical(storage,
-                       "Shared storage doesn't support streamed mailboxes");
-               return NULL;
-       }
-
-       if (shared_storage_get_namespace(storage, &name, &ns) < 0)
-               return NULL;
-
-       /* if we call the normal mailbox_open() here the plugins will see
-          mailbox_open() called twice and they could break. */
-       box = ns->storage->storage_class->v.
-               mailbox_open(ns->storage, name, NULL, flags);
-       if (box == NULL)
-               shared_mailbox_copy_error(storage, ns);
-       else
-               ns->flags |= NAMESPACE_FLAG_USABLE;
-       return box;
-}
-
 static int shared_mailbox_create(struct mail_storage *storage,
                                 const char *name, bool directory)
 {
@@ -345,7 +318,7 @@ struct mail_storage shared_storage = {
                shared_create,
                index_storage_destroy,
                NULL,
-               shared_mailbox_open,
+               NULL,
                shared_mailbox_create
        }
 };
index e3a398fa68e577511483184000256f18723ee8cb..5a8496e73638a1fd14a06059fb11c99021e83457 100644 (file)
@@ -370,6 +370,7 @@ struct mailbox_list fs_mailbox_list = {
        {
                fs_list_alloc,
                fs_list_deinit,
+               NULL,
                fs_is_valid_pattern,
                fs_is_valid_existing_name,
                fs_is_valid_create_name,
index b1a4e997895fdf9fbf405e641ac9f8909c4a0ec0..6118c5e79dddb09485ceadbff25e2dab132da304 100644 (file)
@@ -441,6 +441,7 @@ struct mailbox_list maildir_mailbox_list = {
        {
                maildir_list_alloc,
                maildir_list_deinit,
+               NULL,
                maildir_is_valid_pattern,
                maildir_is_valid_existing_name,
                maildir_is_valid_create_name,
@@ -468,6 +469,7 @@ struct mailbox_list imapdir_mailbox_list = {
        {
                imapdir_list_alloc,
                maildir_list_deinit,
+               NULL,
                maildir_is_valid_pattern,
                maildir_is_valid_existing_name,
                maildir_is_valid_create_name,
index 121e6358ffc66bcc06292c3c1443d5fa9a84aa5b..1fb72d64c94e3e921e4b15841528b3feb8d430f7 100644 (file)
@@ -423,11 +423,18 @@ struct mailbox *mailbox_open(struct mail_storage **_storage, const char *name,
                             enum mailbox_open_flags flags)
 {
        struct mail_storage *storage = *_storage;
+       struct mailbox_list *list = storage->list;
        struct mailbox *box;
 
+       if (list->v.get_storage != NULL) {
+               if (list->v.get_storage(list, name, &storage) < 0)
+                       return NULL;
+               *_storage = storage;
+       }
+
        mail_storage_clear_error(storage);
 
-       if (!mailbox_list_is_valid_existing_name(storage->list, name)) {
+       if (!mailbox_list_is_valid_existing_name(list, name)) {
                mail_storage_set_error(storage, MAIL_ERROR_PARAMS,
                                       "Invalid mailbox name");
                return NULL;
@@ -438,9 +445,6 @@ struct mailbox *mailbox_open(struct mail_storage **_storage, const char *name,
                if (hook_mailbox_opened != NULL && box != NULL)
                        hook_mailbox_opened(box);
        } T_END;
-
-       if (box != NULL)
-               *_storage = box->storage;
        return box;
 }
 
index bc6717ab2365c44ce79d956372a743e60a29de88..8e4e9c22dedc7d082082b4a083ceac85bdbf5cdf 100644 (file)
@@ -13,6 +13,8 @@ struct mailbox_list_vfuncs {
        struct mailbox_list *(*alloc)(void);
        void (*deinit)(struct mailbox_list *list);
 
+       int (*get_storage)(struct mailbox_list *list,
+                          const char *name, struct mail_storage **storage_r);
        bool (*is_valid_pattern)(struct mailbox_list *list,
                                 const char *pattern);
        bool (*is_valid_existing_name)(struct mailbox_list *list,