Rely on (X + (Y - 1)) / Y being the same as ceil(X / Y) when operating on
integers.
This has a couple of benefits over the previous expression:
1) the size argument is evaluated only once
2) the generated code is simpler (no conditional instructions)
3) the generated code is smaller
The generated code shrinks in terms of both bytes and instruction count.
The following table lists the number of bytes (B) and instructions (I) used
by the code before and after this change on an assortment of architectures
when the input is not known at compile time. Unless otherwise noted, the
results are based clang 6.0.1 output.
Timo Sirainen [Sat, 17 Aug 2019 10:43:21 +0000 (13:43 +0300)]
lib: timeval_add/sub_usecs() - Add assert to make sure negative values aren't used
The current code doesn't work correctly if negative values are used.
The code could of course be changed to handle them, but maybe assert is
better to catch bugs.
The crash could happen because driver_cassandra_future_callback() can be
called any time, even before returning from driver_cassandra_set_callback().
This could result in both cb->id and cb->to being set and using the cb
after it's already freed.
Stephan Bosch [Mon, 12 Aug 2019 20:10:24 +0000 (22:10 +0200)]
login-common: Deny anonymous login by default.
Only services that explicitly enable anonymous logins will permit them. Plugins
can also mask anonymous logins by dropping the anonymous reply flag in the
sasl_check_login() client vfunc.
Stephan Bosch [Fri, 9 Aug 2019 22:33:21 +0000 (00:33 +0200)]
login-common: Fix sending locally-generated authentication error reason to client.
This is about authentication errors that emerge at the login service rather than
the auth service. The error reason was always substituted with an unhelpful
"Authentication failed", while e.g. an error like "Unsupported authentication
mechanism" was supposed to be sent instead.
Timo Sirainen [Wed, 7 Aug 2019 12:46:39 +0000 (15:46 +0300)]
imap: GETMETADATA: Ignore MAIL_ERROR_NOTPOSSIBLE errors when using DEPTH parameter
This most likely means that imap_metadata=no, but the client still wants to
fetch recursively validated metadata entries. This should return in OK
instead of NO reply.
Timo Sirainen [Wed, 24 Jul 2019 12:39:37 +0000 (15:39 +0300)]
imap: GETMETADATA: Send the last error as tagged reply
This way if there's only a single error, the error is in the tagged reply
with the [resp-code]. Clients can handle this better than untagged NO
replies.
Timo Sirainen [Wed, 24 Jul 2019 12:05:27 +0000 (15:05 +0300)]
imap: Allow SET/GETMETADATA to access validated attributes with imap_metadata=no
Some IMAP extensions use these commands to set/get their internal state.
This should be allowed even if full METADATA isn't enabled.
The initial plan was to restrict this in the lib-imap-storage layer, so it
would apply to everything using the imap-metadata API. This would have
affected for example accessing metadata in Sieve scripts, which could be
either good or bad. It might not be wanted to give users read access to
some metadata either, but admins really should be given the ability to
write Sieve scripts that access the metadata. However there's just no good
way to differentiate between admin-written (or tool-written) Sieve script
and user-written Sieve script.
Another issue is using metadata to configure virtual mailboxes. Currently
they're all admin-written and should be allowed to access metadata, but in
the future we might want to allow user-written virtual mailbox rules as
well.
So the end result at least for now is to just prevent IMAP GETMETADATA and
SETMETADATA specifically from accessing the non-validated attributes. Most
of the time there aren't any secrets in the metadata. In case there is,
users need to be prevented from accessing metadata via Sieve, and in such
systems users rarely have direct Sieve access anyway.
Timo Sirainen [Wed, 24 Jul 2019 11:42:21 +0000 (14:42 +0300)]
lib-storage: Add support for "validated attributes"
If an attribute is marked with MAIL_ATTRIBUTE_INTERNAL_FLAG_VALIDATED, it's
assumed to be "validated". This means that it has a set() callback that
validates the value, which at minimum means that its size isn't excessively
large.
MAIL_ATTRIBUTE_TYPE_FLAG_VALIDATED can be used with set/get/iterate to allow
access only to these validated attributes. Trying to access non-validated
attributes will result in error.
Stephan Bosch [Thu, 25 Jul 2019 23:57:44 +0000 (01:57 +0200)]
lib: lib-event - Add support for dropping log prefixes introduced by parent events.
This allows dropping a specific number prefixes from parents when this event is
used for logging. This does not affect the parent events. This only counts
actual prefixes and not parents. If the count is higher than the actual number
of prefixes added by parents, all will be dropped.
Stephan Bosch [Mon, 15 Jul 2019 19:50:11 +0000 (21:50 +0200)]
lib-smtp: smtp-params - Assume all capabilities are supported when adding parameter event fields.
The actual capabilities are not really needed, since any assigned field is
relevent for event processing, whether the remote end will accept it or not.
This also fixes an assert failure occuring for proxied connections. Since the
server and client (proxy) connections can have different capabilities and since
the client connection does not have a proper capability list available in the
beginning of the handshake, the event created for a client transaction would
cause an assert failure when parameters were assigned that did not match the
capabilities (none).
Timo Sirainen [Fri, 12 Jul 2019 07:16:26 +0000 (10:16 +0300)]
config: Fix memory leaks when failing to convert ssl-parameters.dat
If ssl_dh setting isn't set and ssl-parameters.dat isn't found or there's
some error reading it, memory is leaked for every config request. This
eventually results in config process dying due to reaching vsz_limit.