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.
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 [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.
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.