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.
Timo Sirainen [Thu, 20 Oct 2016 17:31:33 +0000 (20:31 +0300)]
director: Code cleanup - moved username_hash generation to director.h
It's not really user_directory specific. This is especially important
in the following patches that add per-tag user_directories. It's also not
always known which tag the username_hash refers to, so there can't be
different tag-specific username_hash generators.
Timo Sirainen [Fri, 4 Nov 2016 10:04:11 +0000 (12:04 +0200)]
lib-storage: Fix doveadm search query parsing to use timezones correctly.
When using a date string, e.g. "senton 25-Mar-2007" it should work the same
way as IMAP does and show all mails whose sent date is on 25th, ignoring
whatever the timezone is in the Date header (or in case of received/saved-date
it would be using the timestamps in server's local timezone, again just like
IMAP).
When search with an exact UNIX timestamp or a time interval (e.g.
"3 days"), it should be using UTC times for doing all comparisons.
Timo Sirainen [Wed, 2 Nov 2016 21:00:50 +0000 (23:00 +0200)]
auth: Make static analyzer happier.
Don't complain about uninitialized static_password being sent to
passdb_handle_credentials(). It could only happen for failures, and
passdb_handle_credentials() wouldn't have used the password then.
Stephan Bosch [Fri, 16 Sep 2016 18:22:17 +0000 (20:22 +0200)]
lib-http: client: Implemented host name lookup TTL.
Host name lookups will now be performed again when the results have expired.
Without access to TTL information from DNS lookups, all lookups will use the same default TTL for now.
Stephan Bosch [Thu, 15 Sep 2016 23:35:09 +0000 (01:35 +0200)]
lib-http: client: Link peers to queue earlier: during connection attempts.
This makes sure that queues keep track of which peers are doing stuff on its behalf.
This is important to be able to manage the active peers when a new host name lookup was performed; if a peer is no longer listed in the returned IPs it should be dropped.
Stephan Bosch [Thu, 15 Sep 2016 00:14:46 +0000 (02:14 +0200)]
lib-http: client: Created http_client_peer_drop() function that closes a peer object gracefully.
It checks whether any connections are still present.
It checks whether a backoff timer is still active.
This change and subsequent changes prepare for being able to destroy a queue when it becomes unused.
All peers linked to such a queue are unlinked and dropped when inactive and unlinked.
Stephan Bosch [Thu, 16 Jun 2016 20:02:08 +0000 (22:02 +0200)]
lib-http: client/server: Enable the TCP_NODELAY option for all connections.
This disables the TCP Nagle algorithm. With the Nagle algorithm enabled, TCP waits a little to accumulate more data in a small segment before it is sent. For transfer of large continuous payloads, this is not useful and even harmful.
If the final remaining bit of the payload is small, the TCP layer will wait for a significant amount of time at the end of the payload. For many sequential transfers, this amounts to much waiting time.
This is particularly evident in the test-http-payload test suite tool. Setting TCP_NODELAY decreases its run time from up to 20 minutes to about half a minute my system.