]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Don't drop useless namespaces automatically while creating a new one.
authorTimo Sirainen <tss@iki.fi>
Thu, 20 Nov 2008 17:32:58 +0000 (19:32 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 20 Nov 2008 17:32:58 +0000 (19:32 +0200)
It may free namespaces that are still being used elsewhere. Rather do it
explicitly at the beginning of each mailbox sync.

--HG--
branch : HEAD

src/imap/imap-sync.c
src/lib-storage/index/shared/shared-storage.c
src/lib-storage/mail-user.c
src/lib-storage/mail-user.h

index 0b509fa5ae0870075a80cd512bc0dae9ebd72173..5de70ebd55b50ed9b1a8daa4a021a55f29de1f25 100644 (file)
@@ -4,6 +4,7 @@
 #include "str.h"
 #include "ostream.h"
 #include "mail-storage.h"
+#include "mail-user.h"
 #include "imap-quote.h"
 #include "imap-util.h"
 #include "imap-sync.h"
@@ -138,6 +139,10 @@ imap_sync_init(struct client *client, struct mailbox *box,
        ctx->box = box;
        ctx->imap_flags = imap_flags;
 
+       /* make sure user can't DoS the system by causing Dovecot to create
+          tons of useless namespaces. */
+       mail_user_drop_useless_namespaces(client->user);
+
        ctx->sync_ctx = mailbox_sync_init(box, flags);
        ctx->t = mailbox_transaction_begin(box, 0);
        ctx->mail = mail_alloc(ctx->t, MAIL_FETCH_FLAGS, 0);
index dd1696c951be9c28ce1fc278f2b498abc4465508..055abcec9120e0570e0e4dac77924d127c29227a 100644 (file)
@@ -163,20 +163,6 @@ static void get_nonexisting_user_location(struct shared_storage *storage,
        str_append(location, PKG_RUNDIR"/user-not-found");
 }
 
-static void drop_unusable_shared_namespaces(struct mail_user *user)
-{
-#define NS_UNUSABLE_FLAGS (NAMESPACE_FLAG_AUTOCREATED | )
-       struct mail_namespace *ns, *next;
-
-       for (ns = user->namespaces; ns != NULL; ns = next) {
-               next = ns->next;
-
-               if ((ns->flags & NAMESPACE_FLAG_USABLE) == 0 &&
-                   (ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0)
-                       mail_namespace_destroy(ns);
-       }
-}
-
 int shared_storage_get_namespace(struct mail_storage *_storage,
                                 const char **_name,
                                 struct mail_namespace **ns_r)
@@ -298,7 +284,6 @@ int shared_storage_get_namespace(struct mail_storage *_storage,
                                          ns->prefix, error);
                return -1;
        }
-       drop_unusable_shared_namespaces(user);
        mail_user_add_namespace(user, ns);
 
        *_name = mail_namespace_fix_sep(ns, name);
index fd415af54b30b6680f8aa4880046f2d6612a1c3b..c975c7c71e53f9c7d7e89bbf6f3bda13f160f7e3 100644 (file)
@@ -59,6 +59,19 @@ void mail_user_add_namespace(struct mail_user *user, struct mail_namespace *ns)
        }
 }
 
+void mail_user_drop_useless_namespaces(struct mail_user *user)
+{
+       struct mail_namespace *ns, *next;
+
+       for (ns = user->namespaces; ns != NULL; ns = next) {
+               next = ns->next;
+
+               if ((ns->flags & NAMESPACE_FLAG_USABLE) == 0 &&
+                   (ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0)
+                       mail_namespace_destroy(ns);
+       }
+}
+
 const char *mail_user_home_expand(struct mail_user *user, const char *path)
 {
        (void)mail_user_try_home_expand(user, &path);
index 56760ed5d959ec1ab1a3c19a61f6e78d4b00e0bd..97d9f8d704e5a288c3a28bdb5028fda7e9135deb 100644 (file)
@@ -38,6 +38,8 @@ void mail_user_deinit(struct mail_user **user);
 
 /* Add a new namespace to user's namespaces. */
 void mail_user_add_namespace(struct mail_user *user, struct mail_namespace *ns);
+/* Drop autocreated shared namespaces that don't have any "usable" mailboxes. */
+void mail_user_drop_useless_namespaces(struct mail_user *user);
 
 /* Replace ~/ at the beginning of the path with the user's home directory. */
 const char *mail_user_home_expand(struct mail_user *user, const char *path);