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.
Timo Sirainen [Mon, 14 Nov 2016 13:51:45 +0000 (14:51 +0100)]
master: Remove redundant check to guarantee stdin/stdout/stderr fd existence.
The previous method also wasn't correct, since it was setting close-on-exec
flag for the fds. Although this didn't normally make any difference, since
stdin & stdout was explicitly dup2()ed to /dev/null and for all except the
log process stderr was also being dup2()ed.
Aki Tuomi [Mon, 14 Nov 2016 14:45:24 +0000 (16:45 +0200)]
lib: Mark istream with eof=TRUE on all errors
Previously only i_stream_read() did this, but i_stream_seek(), _stat(),
_get_size() and _create() didn't. This caused assert-crashes on error
conditions in code which assumed that when stream_errno != 0, eof==TRUE.