Paul Howarth [Mon, 5 Dec 2016 15:17:30 +0000 (15:17 +0000)]
configure: Fix some implicit function declarations
Some configure tests fail unexpectedly if the compiler flag
-Werror=implicit-function-declarations is enabled, which can result
in the wrong implementations being used.
This compiler flag is now enabled by default in Fedora Rawhide:
https://fedoraproject.org/wiki/Changes/Fedora26CFlags
<stdlib.h> is needed for exit()
<string.h> is needed for strcpy()
manuel [Wed, 7 Dec 2016 13:23:12 +0000 (14:23 +0100)]
openssl: Clear error queue after an incomplete SSL_shutdown
If the SSL_shutdown-call fails (e.g. because the underlaying socket has
already been closed) OpenSSL puts the corresponding error into the
queue. We don't care about details so we need to clear the queue.
Otherwise the error will be pulled while error checking the next OpenSSL
call of an unrelated connection.
Timo Sirainen [Fri, 9 Dec 2016 13:06:05 +0000 (15:06 +0200)]
imapc: Don't send NOOP immediately after SELECT
NOOP is normally used by mailbox syncing to check if there are any changes
done by other concurrent IMAP sessions. But doing it immediately after
SELECT is unnecessary, because nothing could have changed.
Timo Sirainen [Tue, 6 Dec 2016 22:14:08 +0000 (00:14 +0200)]
cassandra: Treat "Request timed out" also as SQL_RESULT_ERROR_TYPE_WRITE_UNCERTAIN
CASS_ERROR_SERVER_WRITE_TIMEOUT is "Write timeout" as reported by Cassandra
server, while CASS_ERROR_LIB_REQUEST_TIMED_OUT is timeout as reported by the
Cassandra library.
Clang cannot see that ret is -1, 0, or 1 upon assigment, and therefore
-1 or 0 upon entry into the if block. Therefore it considers ret==0
not to be a tautology if ret!=-1, and thus falsifiable. It concludes
that bad things can later happen.
The easiest way to persuade it otherwise and make it clear to a human
that things are sane is to make the first error check to be for any
negative ret value, which forces the else path to explicitly imply
ret==0, which means that clause can also be removed. Just removing the
ret==0 doesn't make it so clear to the human that there's no third case.
The final change is simply to mimic the ret==-1 to ret<0 change earlier.
clang's error message:
doveadm-mail-crypt.c:290:14: error: variable 'pubid' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
} else if (ret == 0 &&
^~~~~~~~
doveadm-mail-crypt.c:304:35: note: uninitialized use occurs here
res->id = p_strdup(_ctx->pool, pubid);
^~~~~
doveadm-mail-crypt.c:290:14: note: remove the '&&' if its condition is always true
} else if (ret == 0 &&
^~~~~~~~~~~
Timo Sirainen [Wed, 30 Nov 2016 13:59:01 +0000 (15:59 +0200)]
dict-client: Don't timeout lookups without waiting 1sec in dict ioloop.
What could have happened was:
- dict-client sends a request to dict-server
- dict-client process starts doing something else
- dict-server answers
- dict-client process continues doing something else for over 30 seconds,
not reading the dict-server answer
- dict-client process gets back to dict ioloop, which runs the timeout
before checking if there is anything available for reading.
Now we'll wait for 1 second in the last dict ioloop before assuming that
there's a timeout.
Timo Sirainen [Wed, 30 Nov 2016 10:34:45 +0000 (12:34 +0200)]
lib-storage: If mailbox_create() fails, don't leave box in partially opened state.
For example with sdbox it may have opened the indexes, but not set mailbox's
GUID. A following MAILBOX_METADATA_GUID would then assert-crash because GUID
is empty.
Aki Tuomi [Tue, 29 Nov 2016 21:18:56 +0000 (23:18 +0200)]
lib: Add hmac helpers
These run hmac for given data with given parameters
and returns stack allocated buffer. They are helpful
when doing lots of HMACs, such as the AWS4 signing
protocol.
Aki Tuomi [Mon, 28 Nov 2016 11:36:56 +0000 (13:36 +0200)]
mail-crypt: Skip undef values if OpenSSL is <1.0.2
OpenSSL 1.0.1 and earlier generate undef warnings due
to using stack as randomness source in a way that
valgrind does not like, so we disable undef value
checks for mail-crypt-plugin.
Timo Sirainen [Mon, 21 Nov 2016 23:28:33 +0000 (01:28 +0200)]
mkcert.sh: Use umask to create key file as 0600
Fixes a race condition between creation of the file and a later chmod.
This script was mostly meant as an example though, and not really for
production use. Especially because it generates self-signed certs.
CVE-2016-4983
Timo Sirainen [Thu, 24 Nov 2016 15:52:01 +0000 (17:52 +0200)]
lib-storge: Call mail_storage.list_index_corrupted() when needed
The callback is called whenever mailbox list index appears to be corrupted
with LAYOUT=index. The storage is responsible for adding to the index any
mailboxes that are missing.
Timo Sirainen [Thu, 24 Nov 2016 15:16:30 +0000 (17:16 +0200)]
lib-index: Add mail_index_unset_fscked()
This can be used to easily remove MAIL_INDEX_HDR_FLAG_FSCKD. It takes a
transaction parameter instead of sync_ctx because some index rebuilds
are done with a separate transaction while the sync_ctx is rolled back.
Timo Sirainen [Thu, 24 Nov 2016 17:53:17 +0000 (19:53 +0200)]
lib-storage: Fail if no namespaces have list=yes
The previous check allowed all namespaces to have list=children. This
crashed later on in mail_namespaces_get_root_sep(), because it couldn't
find any list=yes namespaces.
Timo Sirainen [Tue, 22 Nov 2016 16:33:12 +0000 (18:33 +0200)]
lib-mail: Fix assert-crash in mail_html2text_more() with invalid input.
parse_data() continues forward thinking that it might have valid input,
until it has enough data and realizes that there's nothing valid. This
triggers:
Timo Sirainen [Wed, 23 Nov 2016 21:19:05 +0000 (23:19 +0200)]
lib-storage: Rotate dovecot.list.index.log* more often.
The history in these files isn't as important as in mailbox indexes.
Reduce disk space usage by rotating them more often and deleting the
.log.2 more quickly.
Timo Sirainen [Wed, 23 Nov 2016 20:42:03 +0000 (22:42 +0200)]
lib-storage: Try harder to rename a corrupted mailbox name to its old name.
If the old name exists, use it as a prefix for the new name. This is
especially useful when restoring autocreated mailboxes. A new mailbox
could have already been autocreated, but it's still useful to have
the broken one renamed with the same prefix, so it'll be clear that
these mailboxes should be merged.
Aki Tuomi [Thu, 24 Nov 2016 17:32:44 +0000 (19:32 +0200)]
dsync: Do not try replace remote folder GUID when doing oneway sync
Oneway sync tried to replace remote folder's GUID when
running in one way mode. This causes trouble, e.g.
when running with imapc, because you can't do this.
Timo Sirainen [Wed, 23 Nov 2016 16:43:17 +0000 (18:43 +0200)]
lib-storage: Fix rotation of dovecot.list.index.log
After b9da8540e665138b3cad0b637c08c0ab7d7a7eeb the tail offsets weren't
being updated anymore when mail_index_sync_next() wasn't used to skip
over all the data. Mailbox list index wasn't doing this, and so the log
was never rotated since tail_offset was never equal to head_offset.
Timo Sirainen [Wed, 23 Nov 2016 15:14:48 +0000 (17:14 +0200)]
imapc: Fix assert that checks if mail is expunged locally.
The EXPUNGE may have been sent while imapc_sync_index() was issuing
remote imapc commands. It would end up being in delayed_expunged_uids,
so the assert needs to check that too.
Timo Sirainen [Wed, 23 Nov 2016 11:25:54 +0000 (13:25 +0200)]
sdbox: Don't log an error if stub is added twice
There's no locking for them, so it's fine if two processes add the same
mail. The second one could be ignored, but it was a bit easier to just
let it rename over the first one.
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.