]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Added assert to make sure namespace prefix isn't attempted to be renamed.
authorTimo Sirainen <tss@iki.fi>
Thu, 5 Feb 2015 17:36:29 +0000 (19:36 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 5 Feb 2015 17:36:29 +0000 (19:36 +0200)
This can happen, I'm just not sure how exactly.. The previous behavior
caused assert-crashes also, this change just makes it happen earlier.

src/doveadm/dsync/dsync-mailbox-tree-sync.c
src/doveadm/dsync/test-dsync-mailbox-tree-sync.c

index 6cd87548a90bd9a9c6b10540989f71d8f8e81f1e..88282b12f6f1169ddecdd3d3d6e298f573a2ae97 100644 (file)
@@ -357,6 +357,22 @@ static bool node_is_existent(struct dsync_mailbox_node *node)
        return node_has_existent_children(node, TRUE);
 }
 
+static bool sync_node_is_namespace_prefix(struct dsync_mailbox_tree *tree,
+                                         struct dsync_mailbox_node *node)
+{
+       const char *full_name;
+       unsigned int prefix_len = node->ns->prefix_len;
+
+       if (prefix_len == 0)
+               return FALSE;
+
+       full_name = dsync_mailbox_node_get_full_name(tree, node);
+       if (node->ns->prefix[prefix_len-1] == mail_namespace_get_sep(node->ns))
+               prefix_len--;
+       return strncmp(full_name, node->ns->prefix, prefix_len) == 0 &&
+               full_name[prefix_len] == '\0';
+}
+
 static void
 sync_rename_node_to_temp(struct dsync_mailbox_tree_sync_ctx *ctx,
                         struct dsync_mailbox_tree *tree,
@@ -369,6 +385,8 @@ sync_rename_node_to_temp(struct dsync_mailbox_tree_sync_ctx *ctx,
        buffer_t buf;
        unsigned int prefix_len, max_prefix_len, counter = 1;
 
+       i_assert(!sync_node_is_namespace_prefix(tree, node));
+
        buffer_create_from_data(&buf, name, sizeof(name));
        max_prefix_len = TEMP_MAX_NAME_LEN - TEMP_SUFFIX_MAX_LEN - 1;
        if (node->sync_temporary_name) {
index 8ae07173f3e31655f629f7882ef6f9072cb5bf02..aca559abf82c3fd76d27f59747af7036bbac150f 100644 (file)
 
 #define MAX_DEPTH 4
 
+char mail_namespace_get_sep(struct mail_namespace *ns ATTR_UNUSED)
+{
+       return '/';
+}
+
 void mailbox_name_get_sha128(const char *name, guid_128_t guid_128_r)
 {
        unsigned char sha[SHA1_RESULTLEN];