#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"
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);
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)
ns->prefix, error);
return -1;
}
- drop_unusable_shared_namespaces(user);
mail_user_add_namespace(user, ns);
*_name = mail_namespace_fix_sep(ns, name);
}
}
+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);
/* 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);