65 Commits

Author SHA1 Message Date
Albert ARIBAUD
fa074ec16c chasquid-util: switch --configdir into --config_dir and deprecate --configdir
There's an inconsistency between chasquid (which uses `--config_dir`) and
chasquid-util (which uses `--configdir`).

That is prone to cause confusion, so this patch renames chasquid-util's
flag, leaving the old one as deprecated with a warning message.

Closes https://github.com/albertito/chasquid/pull/60.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Added test case for the deprecated option, adjusted commit message.
2025-03-31 09:19:45 +01:00
Alberto Bertogli
ad0388569a chasquid-util: Fix creating the directory on user-add
`chasquid-util user-add` is meant to create the domain directory if it
doesn't exist; however there's a bug that makes this not happen, and
instead the command fails with:

  Error writing database: open <path>: no such file or directory

This patch fixes the issue and adds a test to ensure we don't have any
regressions on this behaviour.

Thanks to raspbeguy (https://github.com/raspbeguy) for reporting this
issue (on IRC).
2025-01-20 23:31:32 +00:00
Alberto Bertogli
aae0367c60 Log how many things were loaded for each domain
This patch makes chasquid log how many users, aliases and DKIM keys were
loaded for each domain.

This makes it easier to confirm changes, and troubleshoot problems
related to these per-domain configuration files.
2024-05-10 12:19:49 +01:00
Alberto Bertogli
e6a9410377 Exit if there's an error reading users/aliases files on startup
Today, when starting up, if there's an error reading the users or
aliases files, we only log but do not exit. And then those files will
not be attempted to be read on the periodic reload.

We also treat "file does not exist" as an error for users file, but not
aliases file, resulting in inconsistent behaviour between the two.

All of this makes some classes of problems (like permission errors) more
difficult to spot and troubleshoot. For example,
https://github.com/albertito/chasquid/issues/55.

So this patch makes errors reading users/aliases files on startup a
fatal error, and also unifies the "file does not exist" behaviour to
make it not an error in both cases.

Note that the behaviour on the periodic reload is unchanged: treat these
errors as fatal too. This may be changed in future patches.
2024-05-10 12:09:53 +01:00
Alberto Bertogli
7a2e49c849 test/t-21-dkim: Add cross-tool check against driusan/dkimverify
This patch adds a cross-tool integration check that uses
driusan/dkim's dkimverify to confirm it can verify our own DKIM signatures.

It is optional, since the tool may not be present.
2024-03-12 20:43:21 +00:00
Alberto Bertogli
76a72367ae dkim: Implement internal dkim signing and verification
This patch implements internal DKIM signing and verification.
2024-03-12 20:43:21 +00:00
Alberto Bertogli
06aea2f786 chasquid-util: Move tests to chamuyero scripts
We already use chamuyero scripts for some of chasquid-util's tests, this
patch moves most of the rest too, for consistency.
2024-03-07 23:07:37 +00:00
Alberto Bertogli
ac2b037f33 chasquid-util: Include in coverage tests
This patch adds chasquid-util command-line to the coverage tests, so it is
easier to identify testing gaps.
2024-03-07 23:07:37 +00:00
Alberto Bertogli
b0877f0866 chasquid-util: Print errors to stderr
To make it more difficult to accidentally supress errors, or mistake them
for legitimate output, print errors to stderr.
2024-03-07 23:07:37 +00:00
Alberto Bertogli
8e1fd52442 chasquid-util: Add short descriptions of each subcommand
This patch adds short descriptions of each subcommand, to make the help
message more helpful.
2024-03-07 23:07:36 +00:00
Alberto Bertogli
83ae4c3478 userdb: Add support for receive-only users
Some use cases, like receive-only MTAs, need domain users for receiving
emails, but have no real need for passwords since they will never use
submission.

Today, that is not supported, and those use-cases require the
administrator to come up with a password unnecessarily, adding
complexity and possibly risk.

This patch implements "receive-only users", which don't have a valid
password, thus exist for the purposes of delivering mail, but always
fail authentication.

See https://github.com/albertito/chasquid/issues/44 for more details and
rationale.

Thanks to xavierg who suggested this feature on IRC.
2023-12-03 11:59:26 +00:00
Alberto Bertogli
5cdbd9ff6e Fix documentation/comment typos
This patch fixes a variety of typos in documentation and comments, found
by running `codespell`.
2023-10-07 12:41:57 +01:00
Alberto Bertogli
47535651d2 chasquid-util: Remove aliases-add subcommand
The aliases-add subcommand was added before aliases hooks were
implemented and polished, it is undocumented, and the implementation is
nowadays a bit brittle, has some rough edges, and adds significant code
complexity to chasquid-util.

AFAIK nobody is using it either (checked with some specific folks
directly, and it's not very discoverable either).

For all those reasons, this patch removes it.
2023-08-10 00:12:56 +01:00
Alberto Bertogli
e6c6df457d chasquid-util: Use server for aliases-resolve and domaininfo-remove
This patch makes chasquid-util's aliases-resolve and domaininfo-remove
commands talk to the chasquid server (via the new localrpc server).

For aliases-resolve, currently has fairly hacky logic which reimplements
a bunch of the servers', and is also incomplete because it does not
support hooks.

In this patch we fix that by having it talk to the server, where we get
authoritative responses and have no issues with aliases hooks. This
resolves https://github.com/albertito/chasquid/issues/18.

For domaininfo-remove, currently its implementation is also very hacky
since it manipulates files behind the servers' back and without even
using the internal library.

In this patch we fix that by doing the operation through the server,
avoiding the need for those hacks, and also remove the need to manually
reload the server afterwards.
2023-07-30 13:21:07 +01:00
znerol
ad0dbb9cda smtp-check: Add flag to specify local name
Some MTAs reject client connections unless the local name (used in the
HELO/EHLO command) looks like an FQDN. Currently, smtp-check always uses
`localhost`, which does not look like an FQDN.

This patch adds a command line flag to smtp-check to specify the
local name to be used.

Fixes https://github.com/albertito/chasquid/issues/37.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Minor edits to the commit message, adjust flag name, go fmt.
2023-07-16 10:03:50 +01:00
Alberto Bertogli
7d6a59ba77 test: Update coverage tests to Go 1.20
Go 1.20 finally includes proper support for instrumenting binaries for
coverage. This allows us to drop quite a few hacks and workarounds that
we used for it, and we can now also test exiting cases.

The downside is that coverage tests now require Go 1.20, but it is an
acceptable price to pay for the more accurate results.

Normal integration tests are unchanged.

This patch updates the coverage testing infrastructure to make use of
the new Go 1.20 features.
2023-02-01 23:43:12 +00:00
Alberto Bertogli
948cee1ce1 Improve bash quoting, and other similar best practices
This patch updates the shell scripts with some of the common best
practices, which should make them more resilient to unusual failures and
unexpected environments (in particular, directories with spaces).

Most of these were identified by shellcheck.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
4a00a83c23 Add tracing annotations
This patch changes several internal packages to receive and pass tracing
annotations, making use of the new tracing library, so we can have
better debugging information.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
3ebe5c5173 Replace uses of ioutil
ioutil package was deprecated in Go 1.16, replace all uses with their
respective replacements.

This patch was generated with a combination of `gofmt -r`, `eg`, and
manually (for `ioutil.ReadDir`).
2022-11-12 20:06:35 +00:00
Alberto Bertogli
b779941f90 Remove spf-check debugging tool
The spf-check debugging tool is quite primitive, rarely (if ever) used,
not tested, and has been superceded by the one in the spf library
(https://blitiri.com.ar/git/r/spf/b/master/t/cmd/spf-check/f=spf-check.go.html).

This patch removes it.
2022-08-08 17:56:58 +01:00
Alberto Bertogli
5bb17c7066 Update build tag constraints
This patch updates all build tag constraints to add the new format,
alongside the old one, to maintain backwards compatibility.

This was done by using `go fmt`.

See https://go.dev/doc/go1.17#gofmt and
https://golang.org/design/draft-gobuild for more details.
2022-08-08 17:52:34 +01:00
Alberto Bertogli
f303e43082 aliases: Implement catch-all
This patch implements support for catch-all aliases, where users can add
a `*: destination` alias. Mails sent to unknown users (or other aliases)
will not be rejected, but sent to the indicated destination instead.

Please see https://github.com/albertito/chasquid/issues/23 and
https://github.com/albertito/chasquid/pull/24 for more discussion and
background.

Thanks to Alex Ellwein (aellwein@github) for the alternative patch and
help with testing; and to ThinkChaos (ThinkChaos@github) for help with
testing.
2022-03-11 20:51:06 +00:00
Alberto Bertogli
fa1db7d81a config: Support "" values for drop_characters and suffix_separators
If the `drop_characters` or `suffix_separators` options are set to "",
currently instead of the empty string, their default value is used instead.

This is a bug, and it also happens on other config options, but because
the others have to be set in order for chasquid to function, it's not a
problem in practice.

Thanks Björn Busse (bbusse@github) for finding and reporting this
problem, on irc and in https://github.com/albertito/chasquid/issues/25.

This patch fixes the problem by marking these fields explicitly
optional, which enables presence testing, as described in the protobuf
documentation:
https://github.com/protocolbuffers/protobuf/blob/master/docs/field_presence.md.
2022-01-21 12:07:34 +00:00
Alberto Bertogli
fcdc49d742 chasquid-util: Update ReadPassword dependency
Today, we use `golang.org/x/crypto/ssh/terminal` to read passwords. That
package is obsolete, replaced with `golang.org/x/term`.

We couldn't move them because term wasn't compatible with Go 1.11 which
was our oldest supported Go version.

Now that we moved to Go 1.15 as the oldest supported version, we can do
the update.
2021-10-08 23:11:29 +01:00
Alberto Bertogli
8f1f943fca mda-lmtp: Add -to_puny, to punycode-encode addresses
Some LMTP servers (like dovecot) can't handle UTF8 addresses in the LMTP
commands. This can be problematic if we want to use them with UTF8
domains or usernames, which are well supported by chasquid.

To help workaround this issue, this patch adds a new -to_puny flag for
mda-lmtp, that makes it encode `from` and `recipient` in punycode.

That way, the server will get punycode-encoded (ASCII) strings in the
LTMP commands.

This can be particularly convenient when the recipients are ASCII
(because they're under the mail server control), but `from` may not be
(because it comes from the network).
2021-06-25 12:15:42 +01:00
Alberto Bertogli
5c09138db8 chasquid-util: Remove dependency on docopt-go
The docopt-go library is quite convenient, but it has been abandoned for
a while :(

Since we only use it for chasquid-util, this patch removes it and
replaces it with a custom small parser, that is a reasonable fit for the
required use cases.

The patch also adds a couple of tests to increase coverage.

NOTE: docopt-go accepted some undocumented behaviour, in particular the
use of "-a b" instead of "-a=b". The new parser does not, so some
user scripts may require updating.

I think this should be rare enough not to be worth the complexity of
adjusting the parser to allow it.
2021-01-16 23:21:35 +00:00
Alberto Bertogli
def6e1cee2 dovecot-auth-cli: Test invalid arguments handling
This patch adds a minor test to dovecot-auth-cli to verify that the
check for invalid number of arguments is working as expected.

It's mostly for consistency, as the utility is only used for testing
purposes.
2021-01-16 23:21:35 +00:00
Leandro Lucarella
c9d3ba0ca0 Add @domain to chasquid-util --help where appropriate
This makes it more clear how to specify which domain the user being
operated on is the sub-command targeting when using `--help`.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Update code to match the updated parameter name.
2020-11-12 23:24:21 +00:00
Alberto Bertogli
380da0c1a1 dovecot-auth-cli: Add help message
The dovecot-auth-cli binary can be useful to debug and troubleshoot
dovecot auth issues.

This patch adds a small help message to make it easier for users to
understand how to use it.
2020-07-08 00:30:11 +01:00
Alberto Bertogli
4c28efcb20 config: Allow overrides from the command line
This patch allows the configuration values to be overridden from the
command-line, with a new -config_overrides flag.

There is a fairly specific use case for this, when editing the
configuration file is not feasible or convenient (e.g. running an
user-supplied configuration in a managed environment).
2020-05-17 00:10:06 +01:00
Alberto Bertogli
b1fe4f81f9 config: Improve logging of errors
Currently, the config package logs errors itself, in addition to
returning them.

That is confusing and results in some duplication of logging.

This patch makes config just return errors, and adjusts the callers
to log them properly.
2020-05-16 23:46:43 +01:00
Alberto Bertogli
50986a7b7e Update protobuf library to v2
There is a new protobuf library (and corresponding code generator) for
Go: google.golang.org/protobuf.

It is fairly compatible with the previous v1 API
(github.com/golang/protobuf), but there are some changes.

This patch adjusts the code and generated files to the new API.

The on-wire/on-disk format remains unchanged so this should be
transparent to the users.
2020-05-16 10:12:51 +01:00
Alberto Bertogli
d6b512166b Make it explicit when we are intentionally not checking errors
The linter complains that we're not checking for errors, but on some
cases it's on code paths were it is reasonable to do so (e.g. we're
closing the connection and it's a best-effort write).

This patch adjusts the code to make those cases explicit.
2020-04-14 12:01:01 +01:00
Alberto Bertogli
15b79d9de9 chasquid-util: Check that we can create the database directory
When creating a database directory, we were missing the check to see if
it had succeeded, which would make issues more difficult to troubleshoot.

This patch adds the missing check.
2020-04-14 12:01:01 +01:00
Alberto Bertogli
929a9947bf chasquid-util: Use docopt.ParseDoc
docopt.Parse is deprecated. This patch updates the code to the newer
variant, ParseDoc, since the default options are what we want.

There are no functional changes.
2020-04-14 12:01:01 +01:00
Alberto Bertogli
27227986ab smtp-check: Improve error reporting
smtp-check exits on the first error, which is not ideal when
troubleshooting, as seeing only one error can mask others, or make it
more difficult to find the underlying cause.

This patch improves how smtp-check reports errors by tweaking the
presentation a bit, as well as perform almost all checks regardless of
whether they pass or not.
2019-10-19 14:26:47 +01:00
Alberto Bertogli
605e39d0e3 test: Extend chasquid-util aliases-add tests 2019-10-19 13:06:30 +01:00
Thor77
8d910fc84d Add aliases-add subcommand to chasquid-util 2019-10-19 13:06:30 +01:00
Alberto Bertogli
41d960590d smtpsrv: Use spf.CheckHostWithSender
The spf library has gained support for macros, but to process them
properly, a new function needs to be called with the full sender
address, spf.CheckHostWithSender.

This patch updates chasquid's calls to the new API.
2019-10-14 19:37:14 +01:00
Alberto Bertogli
23deaf1f88 Reinstate the MTA-STS (Strict Transport Security) implementation
This commit brings back the experimental MTA-STS (Strict Transport
Security) implementation, removed in commit
7f5bedf4aa.

We will continue development in the "sts" branch, subject to rebase,
until it is ready to be integrated into "next" again.
2018-07-01 12:19:02 +01:00
Alberto Bertogli
cf81fbee74 dovecot: Add tests for more error cases
This patch adds more tests for the dovecot library, in particular:
 - Protocol errors (invalid versions, etc.).
 - Invalid command (cli-specific test).
 - Connection breakups.
2018-06-04 01:34:32 +01:00
Alberto Bertogli
36692b52d3 dovecot: Include cli-based tests in the coverage tests
Many areas of the dovecot library are tested via chamuyero scripts, but
these were not being included in the coverage report.

This patch extends the dovecot-auth-cli tests so that they are now
coverage-aware.
2018-06-04 01:18:24 +01:00
Alberto Bertogli
4373f56a82 chasquid-util: Add domaininfo-remove
This patch adds a chasquid-util subcommand to remove a domain
information entry.

The main use case is to manually allow a security level downgrade, after
performing manual verification.
2018-05-24 23:02:57 +01:00
Alberto Bertogli
f3b01cb493 docs: Add missing docstrings, adjust wording to match standard style
This patch adds a missing docstrings for exported identifiers, and
adjust some of the existing ones to match the standard style.

In some cases, the identifiers were un-exported after noticing they had
no external users.

Besides improving documentation, it also reduces the linter noise
significantly.
2018-03-04 16:00:06 +00:00
Alberto Bertogli
bb90274edd test: Add tools to generate test coverage information
This patch adds some tooling and scripts to generate test coverage
information.

Unfortunately, this involves some hacks as Go does not have support for
generating coverage-enabled binaries, or merging coverage reports; but
overall it's not very intrusive.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
51e7c5c19e dovecot: Dovecot authentication package
This patch adds a new package which implements two basic primitives for
authenticating against dovecot ("user exists", and "check password").

It is still experimental/work in progress.
2018-02-10 23:01:23 +00:00
Alberto Bertogli
4851b07098 test: Add missing test file in mda-lmtp
The mda-lmtp tests are missing a file in the repository, which causes the
test to fail. This went unnoticed because they are not included in the
automated test suite, which will be fixed in a follow-up patch.

This patch adds the mising test file, with a harder to miss name.
2017-12-09 18:41:27 +00:00
Alberto Bertogli
033a5d657b Use the external log, spf and systemd packages
The log, spf and systemd packages have been externalized; use them
instead of the internal version to avoid having two versions of the same
thing.
2017-09-17 22:17:14 +01:00
Alberto Bertogli
0972964722 mda-lmtp: Handle "<>" addresses
Either the recipient or from addresses can be "<>" to indicate the null
address. mda-lmtp does not handle that well, as it sends "<<>>" which is
invalid.

This patch fixes that by special-casing them, which is unfortunate but
reasonably common.
2017-08-08 09:12:53 +01:00
Alberto Bertogli
82a1e4597f mda-lmtp: Add a very basic MDA that uses LMTP to do the mail delivery.
mda-lmtp is a very basic MDA that uses LMTP to do the mail delivery.

It takes command line arguments similar to maildrop or procmail, reads an
email via standard input, and sends it over the given LMTP server.
Supports connecting to LMTP servers over UNIX sockets and TCP.

Since chasquid does not support direct LMTP local delivery, this can be
used as a workaround instead.

Example of use:
$ mda-lmtp --addr localhost:1234 -f juan@casa -d jose < email
2017-07-13 22:05:45 +01:00