]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fix lock file collisions when mail_volatile_path is shared
authorMichael M Slusarz <michael.slusarz@open-xchange.com>
Fri, 1 May 2026 07:21:19 +0000 (01:21 -0600)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 12 May 2026 04:53:00 +0000 (04:53 +0000)
src/lib-storage/mail-storage.c

index cab99efc4c36baf65ff7fa89ecbea05799325775..a4363fc73c5c1bb201627c1b5bd5d3b63848e00b 100644 (file)
@@ -4030,10 +4030,18 @@ int mailbox_lock_file_create(struct mailbox *box, const char *lock_fname,
                   be too large as a filename and creating the full directory
                   structure would be pretty troublesome. It would also make
                   it more difficult to perform the automated deletion of empty
-                  lock directories. */
+                  lock directories.
+                  The SHA1 is calculated from the namespace prefix concatenated
+                  with the mailbox name (prefix first, then name) to avoid
+                  collisions when multiple namespaces share the same
+                  mail_volatile_path. */
                str_printfa(str, "%s/%s.", box->list->mail_set->mail_volatile_path,
                            lock_fname);
-               sha1_get_digest(box->name, strlen(box->name), box_name_sha1);
+               struct sha1_ctxt ctx;
+               sha1_init(&ctx);
+               sha1_loop(&ctx, box->list->ns->prefix, box->list->ns->prefix_len);
+               sha1_loop(&ctx, box->name, strlen(box->name));
+               sha1_result(&ctx, box_name_sha1);
                binary_to_hex_append(str, box_name_sha1, sizeof(box_name_sha1));
                lock_path = str_c(str);
                set.mkdir_mode = 0700;