Timo Sirainen [Tue, 22 Nov 2016 14:35:58 +0000 (16:35 +0200)]
lib-fts: Make sure address tokenizer can't return empty tokens.
This happened when address was a token that first looked like it could be
a valid address, but then got truncated due to reaching maxlen, followed
by truncating the UTF8-sequence and finally all the rest of the '-' or
'.' chars that were valid at the beginning of the address are stripped
away by fts_tokenizer_delete_trailing_invalid_char(), leaving nothing left.
Timo Sirainen [Tue, 22 Nov 2016 10:03:01 +0000 (12:03 +0200)]
lib-index: Handle invalid headers as "corruption", not "temporary error"
This is especially required for "Header's corrupted flag is set" error,
which won't get fixed otherwise.
It's a bit more questionable if we should treat major version or CPU
architecture change as corruption, but it's possible those only exist
because of corruption. It's also very unlikely that either is really
happening. Ideally there would be a hash that verifies whether the
header is corrupted or not.
Timo Sirainen [Fri, 18 Nov 2016 14:03:00 +0000 (16:03 +0200)]
imap: Fix recent flags importing when un-hibernating
The initial RECENT counter that was sent didn't include pre-hibernation
\Recent flags.
\Recent flags were also added for mails that were already expunged, which
could have caused recent counter to be wrong later on, and possibly
assert-crash with:
process A: .log is opened with seq=1
process B: Rotates the .log and writes a new dovecot.index with
log_file_seq=2
process A: dovecot.index is opened. mail_transaction_log_view_set() now
wants to file log_file_seq=2 with mail_transaction_log_find_file(), but
because open_count==0, the .log isn't refreshed.
Timo Sirainen [Tue, 15 Nov 2016 16:39:08 +0000 (18:39 +0200)]
lib: Add connection.allow_empty_args_input
This simplifies input_args() callbacks since they don't always have to check
for args[0] == NULL. This is enabled by default, because none of the current
users want it and it's somewhat unlikely there even will be those in future.
Timo Sirainen [Thu, 17 Nov 2016 23:23:13 +0000 (01:23 +0200)]
lib-index: Fix detecting whether caller synced everything in mailbox.
When mailbox_index_sync_begin() was followed by _commit(), without _next()s
in the middle actually syncing the mailbox, the tail_offset was updated to
indicate that the mailbox was fully synced. Existing code didn't rely on
this, so it probably didn't break anything.
This code hasn't worked for a long time, because log_view is always read
fully to the end in _sync_begin().
Without this, it is not possible to instantiate multiple imapc storages.
Any attempts to will result in multiple namespaces sharing the same storage,
regardless of if that was the intention.
This can be called multiple times before mail_index_transaction_finish().
It's going to perform all the work of reordering mails and dropping
unnecessary changes that can be done before changing sequences to UIDs.
This will be needed for the following patch that implements
mail_index_transaction_get_highest_modseq().
Paul Howarth [Mon, 31 Oct 2016 10:49:38 +0000 (10:49 +0000)]
configure: Fix build with old OpenSSL without SSL_clear_options
SSL_clear_options was introduced in OpenSSL 0.9.8m but may be
backported to older versions in "enterprise" OS releases, so a version
check is insufficient here.
It was originally implemented as a macro but is a function in more
recent OpenSSL versions, so a test that works for both cases is needed.
This allows backends that are adding lost mailboxes to mailbox list index to
indicate that they don't actually know the name of the mailbox, and the
mailbox list index should try to figure it out and rename the mailbox to its
proper name.
Timo Sirainen [Wed, 16 Nov 2016 01:06:31 +0000 (03:06 +0200)]
LAYOUT=index: Don't write corrupted mailbox names to box-name header.
This way when opening a mailbox the box-name header isn't overwritten by
a corrupted name.
Keep track of the corrupted names with MAILBOX_LIST_INDEX_FLAG_CORRUPTED_NAME
flag in list index records. The flag isn't removed until the mailbox is
renamed.
Timo Sirainen [Tue, 15 Nov 2016 23:09:57 +0000 (01:09 +0200)]
lib-storage: Prevent renaming mailbox under itself.
This resulted earlier in a loop, which broke the mailbox index.
Note that IMAP already prevented this, so it could only be triggered by
other tools, like doveadm.
Timo Sirainen [Wed, 16 Nov 2016 09:40:35 +0000 (11:40 +0200)]
lib: Add fd_close_maybe_stdio()
The idea is that this should be used whenever closing fds that may be 0 or
1. If they are closed normally, the following code may end up using 0/1 fd
for other purposes, which could cause problems.
Manually cleanup OpenSSL from dovecot_openssl_common_global_unref()
OpenSSL 1.1 features a cleanup function that is automatically run on shutdown
using atexit(3). This function frees all OpenSSL-allocated resources.
In dovecot, OpenSSL is loaded indirectly using dlopen(3) against the relevant
dovecot crypto module and is finally unloaded using dlclose(3). Until
OpenSSL 1.0.1c this worked fine, however OpenSSL 1.0.1c makes sure[1] that the
library stays loaded after the initial dlclose() so that the atexit(3)
handlers can run on shutdown. This, together with the fact that dovecot
uses custom allocation functions for OpenSSL and has already partially
free()'d some of OpenSSL's resources in module_free(), leads to a
segfault at process shutdown[2].
We fix this by explicitly calling OPENSSL_cleanup() during module unload. This
is safe to do, as long as we will never want to subsequently re-initialize
OpenSSL.
This is driven by the fact that OpenSSL 1.1 does not know about SSLv2 at
all and dovecot's defaults simply make OpenSSL error out with "Unknown
protocol 'SSLv2'"[1]. So we change the defaults to refer to SSLv2 iff OpenSSL
seems to know something about it.
While at it, it's also a good idea to disable SSLv3 by default as well.