lib-lua: Make DLUA_REQUIRE_ARGS*() take the lua_State * directly
This is the first in a series of commits that convert a number of functions
to pass around the lua_State pointer directly and to use it instead of using
the lua_State pointed to by the struct dlua_script.
This change is needed to eventually support the 'yield' functionality and
"sequential looking, but async behind the scenes" lua scripts. To support
this, the C code needs to instantiate multiple lua_States and then operate
on the correct one - whichever one is passed back by the lua runtime. This
lays the ground work for that.
Timo Sirainen [Thu, 22 Oct 2020 19:49:56 +0000 (22:49 +0300)]
lib-storage: Detect corrupted mail size when calculating body size
When body size is calculated from message size - header size, make sure that
the message size is at least as large as the header size. Otherwise treat
the message size as corrupted.
Siavash Tavakoli [Sun, 22 Nov 2020 19:16:03 +0000 (19:16 +0000)]
stats: openmetrics: Do not duplicate counter and duration metrics for histograms
Histograms generate "_count" and "_sum" metrics either for each quantile or
for the whole distribution. This patch prevents creating a duplicate metric
with type counter which results in metric name collision.
Timo Sirainen [Mon, 21 Dec 2020 19:24:50 +0000 (21:24 +0200)]
lib-master, master: Add "worker" service type
The worker services are expected to reach their process_limit regularly.
There shouldn't be a warning logged about temporarily reaching the limit,
since it can happen due to race conditions.
Timo Sirainen [Thu, 16 Jan 2020 12:58:21 +0000 (14:58 +0200)]
lib-master: Notify master immediately when process can accept more clients
Instead of delaying it for 1 second. Otherwise the master might be
complaining about process/client limit being reached or creating more
processes unnecessarily.
Siavash Tavakoli [Mon, 28 Dec 2020 10:26:07 +0000 (10:26 +0000)]
lib-mail: message-snippet: Fix expected number of leading non-whitespace chars
If message body starts with a single char + space (e.g. "I am"), the
space is wrongly removed (i.e. snippet would be "Iam") because at least two
non-whitespace characters are expected. Fix the minimum to 1 to fix this.
Set metadata without actually opening the mailbox.
As a side-effect this changes SETMETADATA command response when ACL
rules are present and user only has lookup right. For non-existing
mailboxes, command fails with "Mailbox doesn't exist" message instead of
"Permission denied" error.
imap: cmd-getmetadata: Retrieve metadata values without opening the mailbox
No need to actually opening the mailbox, only check for its existence.
This also makes GETMETADATA command behave more in line with RFC 5464 when
acls are preset. Changes to command results for different cases:
- User with only "l" right:
- for non-existing mailbox command failure error changed from "Permission denied"
to "Mailbox doesn't exist"
- User with "l" right and one of "s", "w", "i", and "p" rights:
- for INBOX, command result changed from "Permission denied" failure to "OK"
- for existing mailboxes, command result changed from "Permission denied"
failure to "OK"
- for non-existing mailboxes, command failure error changed from "Permission denied"
to "Mailbox doesn't exist"
- for autocreated mailboxes, command result changed from "Permission denied"
failure to "OK"
- User with "l" right and one of "x", "c", "d", and "a" rights:
- for non-existing mailboxes, command failure error changed from "Permission denied"
to "Mailbox doesn't exist"
- User with only "r" right:
- for INBOX, command result changed from "OK" to "Mailbox doesn't exist"
- for existing mailboxes, command result changed from "OK" to "Mailbox doesn't exist"
- for autocreated mailboxes, command result changed from "OK" to "Mailbox doesn't exist"
imap: cmd-getmetadata: Do not ignore NOTFOUND and PERM when handling errors
Don't ignore MAIL_ERROR_NOTFOUND MAIL_ERROR_PERM in cmd_getmetadata_handle_error
and fail GETMETADATA command properly. This code was added in the initial
GETMETADATA implementation commit. It doesn't seem like it has ever done
anything useful.
doveadm: doveadm-mail-mailbox-metadata: Add flag for prefixes in metadata list
Add an optional "-p" flag for metadata list command. Keys should have been
listed with "/private" or "/shared" prefixes from the get-go but for the
sake of not breaking users' workflow put this behind a flag.
This happens e.g. on FreeBSD when closing a socket that has not been
fully flushed to client. Since we can't do anything about that,
we might as well just ignore it.
Aki Tuomi [Mon, 21 Dec 2020 09:50:51 +0000 (11:50 +0200)]
lib: fd-util - Ignore ECONNRESET when closing fd
This happens e.g. on FreeBSD when closing a socket that has not been
fully flushed to client. Since we can't do anything about that,
we might as well just ignore it.
Aki Tuomi [Thu, 24 Sep 2020 06:22:38 +0000 (09:22 +0300)]
lib-lua: Store script pointer in LUA_REGISTRY
This will allow us to translate any lua thread to a script pointer. This is
not meant to allow multi-threaded lua scripts, but it is necessary to allow
yields to work.
Timo Sirainen [Wed, 18 Nov 2020 18:48:11 +0000 (20:48 +0200)]
lib-imap: Fix writing BODYSTRUCTURE for truncated multipart/ part
If the max nesting limit is reached, write the last part out as
application/octet-stream. The original content-type could be confusing
IMAP clients when they don't see any child parts.
Timo Sirainen [Fri, 11 Sep 2020 07:57:51 +0000 (10:57 +0300)]
lib-imap: Don't generate invalid BODYSTRUCTURE when reaching MIME part limit
If the last MIME part was message/rfc822 and its child was truncated away,
BODYSTRUCTURE was missing the ENVELOPE and BODY[STRUCTURE] parts. Fixed by
writing empty dummy ones.
This turns this into a full-fledged library. This addresses the issue where
libdovecot-lua is completely included in anything that uses it, which caused
unnecessarily bloat and could have caused linker problems with multiple
definitions of the same symbol.
Marvin W [Mon, 16 Nov 2020 19:55:14 +0000 (20:55 +0100)]
auth: db-lua - Fix invalid stack empty check
3e11b97 introduced assertions to ensure the lua stack is empty after
execution. In auth_lua_call_password_verify() this check was inserted
*before* popping the error message from the stack, ultimately causing the
assertion to fail every time the lua script has a runtime error, leading to
process crashing.