dovecot-1.2: Don't drop useless namespaces automatically while c...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Nov 20 19:33:02 EET 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/f5554ae61732
changeset: 8457:f5554ae61732
user: Timo Sirainen <tss at iki.fi>
date: Thu Nov 20 19:32:58 2008 +0200
description:
Don't drop useless namespaces automatically while creating a new one.
It may free namespaces that are still being used elsewhere. Rather do it
explicitly at the beginning of each mailbox sync.
diffstat:
4 files changed, 20 insertions(+), 15 deletions(-)
src/imap/imap-sync.c | 5 +++++
src/lib-storage/index/shared/shared-storage.c | 15 ---------------
src/lib-storage/mail-user.c | 13 +++++++++++++
src/lib-storage/mail-user.h | 2 ++
diffs (89 lines):
diff -r 529034798b6b -r f5554ae61732 src/imap/imap-sync.c
--- a/src/imap/imap-sync.c Wed Nov 19 20:09:34 2008 +0200
+++ b/src/imap/imap-sync.c Thu Nov 20 19:32:58 2008 +0200
@@ -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"
@@ -137,6 +138,10 @@ imap_sync_init(struct client *client, st
ctx->client = client;
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);
diff -r 529034798b6b -r f5554ae61732 src/lib-storage/index/shared/shared-storage.c
--- a/src/lib-storage/index/shared/shared-storage.c Wed Nov 19 20:09:34 2008 +0200
+++ b/src/lib-storage/index/shared/shared-storage.c Thu Nov 20 19:32:58 2008 +0200
@@ -161,20 +161,6 @@ static void get_nonexisting_user_locatio
/* use a reachable but non-existing path as the mail root directory */
str_append(location, storage->base_dir);
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,
@@ -298,7 +284,6 @@ int shared_storage_get_namespace(struct
ns->prefix, error);
return -1;
}
- drop_unusable_shared_namespaces(user);
mail_user_add_namespace(user, ns);
*_name = mail_namespace_fix_sep(ns, name);
diff -r 529034798b6b -r f5554ae61732 src/lib-storage/mail-user.c
--- a/src/lib-storage/mail-user.c Wed Nov 19 20:09:34 2008 +0200
+++ b/src/lib-storage/mail-user.c Thu Nov 20 19:32:58 2008 +0200
@@ -59,6 +59,19 @@ void mail_user_add_namespace(struct mail
}
}
+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);
diff -r 529034798b6b -r f5554ae61732 src/lib-storage/mail-user.h
--- a/src/lib-storage/mail-user.h Wed Nov 19 20:09:34 2008 +0200
+++ b/src/lib-storage/mail-user.h Thu Nov 20 19:32:58 2008 +0200
@@ -38,6 +38,8 @@ void mail_user_deinit(struct mail_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);
More information about the dovecot-cvs
mailing list