]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail-crypt: mail_crypt_user_set_private_key() - Move mailbox alloc later to avoid...
authorMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Thu, 16 Jun 2022 13:53:47 +0000 (16:53 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 17 Jun 2022 07:59:06 +0000 (07:59 +0000)
This fixes:

  Panic: file mail-user.c: line 252 (mail_user_deinit): assertion failed: ((*user)->refcount == 1)

When mail_crypt_require_encrypted_user_key is enabled and the user does
not have key or password.

src/plugins/mail-crypt/mail-crypt-key.c

index 76e8114c8d2f94fc359588650381cad696234db6..df52cdbb6b83d2ce7eadbd9c9f181909e93bb3bd 100644 (file)
@@ -466,9 +466,6 @@ int mail_crypt_user_set_private_key(struct mail_user *user, const char *pubid,
                                    struct dcrypt_private_key *key,
                                    const char **error_r)
 {
-       struct mail_namespace *ns = mail_namespace_find_inbox(user->namespaces);
-       struct mailbox *box = mailbox_alloc(ns->list, "INBOX",
-                                           MAILBOX_FLAG_READONLY);
        struct dcrypt_private_key *env_key = NULL;
        struct dcrypt_public_key *enc_key = NULL;
        struct mailbox_transaction_context *t;
@@ -494,6 +491,9 @@ int mail_crypt_user_set_private_key(struct mail_user *user, const char *pubid,
                return -1;
        }
 
+       struct mail_namespace *ns = mail_namespace_find_inbox(user->namespaces);
+       struct mailbox *box = mailbox_alloc(ns->list, "INBOX",
+                                           MAILBOX_FLAG_READONLY);
        if (mailbox_open(box) < 0) {
                *error_r = t_strdup_printf("mailbox_open(%s) failed: %s",
                                           "INBOX",