Commit Graph
24 Commits
Author SHA1 Message Date
Jonathon Reinhart 247d187576 Don't allow a configuration requiring auth with a non-TLS listener
This fixes #26
2021-04-01 01:12:34 -04:00
Jonathon Reinhart 45a676e274 Add localAuthRequired() helper function
This just makes the configuration state a little more obvious.
2021-04-01 01:12:34 -04:00
Jonathon Reinhart ca1ccd85e3 Refactor parsing of -listen string out into separate config function
This makes the "for each listen address" loop in main() look even cleaner.
2021-04-01 01:12:34 -04:00
Jonathon Reinhart 1b7b551f65 Handle signals and gracefully shut down server 2021-04-01 01:07:30 -04:00
Jonathon Reinhart 22ef0c2ee6 Move SMTP auth setup to ConfigLoad()
This has several benefits:
- Configuration errors are caught at startup rather than upon a connection
- mailHandler() has less work to do for each connection

Rather than relying on remote_user and remote_pass to control whether
authentication is used, introduce an explicit "none" type for
remote_auth, and make that the default. (This is effectively the same
default behavior since remote_user and remote_pass default to empty.)

Also, we are in a better position to more thoroughly check for
configuration errors or mismatches:
- If remote_auth is given, remote_user and remote_pass are required.
- If remote_auth is given, remote_host is also required (because it
  makes no sense to say we're going to authenticate if we have no server
  to which to authenticate.)
- If remote_user or remote_pass are given, remote_auth cannot be "none".
2021-03-14 18:41:54 -04:00
Jonathon Reinhart 76ef135d33 Clarify allowed_sender/allowed_recipient empty string behavior 2021-03-14 12:36:34 -04:00
Jonathon Reinhart 7c0ba34025 Move compilation of allowed_recipients to ConfigLoad()
This has several benefits:
- Configuration errors are caught at startup rather than upon a connection
- recipientChecker() has less work to do for each connection
2021-03-14 12:31:38 -04:00
Jonathon Reinhart a896ab2847 Move compilation of allowed_sender to ConfigLoad()
This has several benefits:
- Configuration errors are caught at startup rather than upon a connection
- senderChecker() has less work to do for each connection
2021-03-14 12:31:38 -04:00
Jonathon Reinhart 918df65a3a Require that networks in allowed_nets are networks and not hosts 2021-03-13 20:40:25 -05:00
Jonathon Reinhart 0503c12ccd Allow "allowed_nets" to be empty, meaning any network is allowed 2021-03-13 20:34:48 -05:00
Jonathon Reinhart ef3f9c8ea0 Move parsing of "allowed_nets" out to ConfigLoad()
This has several benefits:
- Configuration errors are caught at startup rather than upon a connection
- connectionChecker() has less work to do for each connection
2021-03-13 20:34:48 -05:00
Jonathon Reinhart 4036213dd5 Simplify peerIP determination in connectionChecker()
peerIP = net.ParseIP(addr.IP.String())

can be simplified to just:

    peerIP = addr.IP

but we can also skip the safe cast since we know the net.Addr will always
be net.TCPAddr because we only have TCP listeners.
2021-03-13 20:19:07 -05:00
Jonathon Reinhart 20ca816160 Discard mail if remote_host is not set
This is useful for test environments.
2021-03-13 09:28:04 -05:00
Jonathon Reinhart 9921b38046 Explicitly configure default logfile for stderr 2021-03-13 03:25:57 -05:00
Jonathon Reinhart 095fba119a Change default logfile to empty string (meaning stderr)
The causes logrus to write to stderr.
2021-03-13 03:25:57 -05:00
Jonathon Reinhart 34cb47c364 Implement structured logs using logrus
This was based loosely on an earlier implementation by
Danny Kopping <danny.kopping@grafana.com>
2021-03-13 03:25:57 -05:00
Jonathon Reinhart 009ae8f73a hasher: Check number of arguments
This makes for a better user experience than a go segfault.
2021-02-15 00:18:15 -05:00
Jonathon Reinhart 70dfe6b128 Only call AuthLoadFile() once at startup 2021-02-15 00:08:37 -05:00
Jonathon Reinhart 7fa0eebf95 Simplify range code for setting up listeners 2021-02-15 00:00:38 -05:00
Jonathon Reinhart ecf830865c Add helpful log messages for various error cases 2021-02-14 23:49:17 -05:00
Jonathon Reinhart 4fd6bb1004 Refactor common code in listener setup 2021-02-14 23:30:31 -05:00
Jonathon Reinhart fd3f513b18 Don't run ListenAndServe in a goroutine
Any errors returned in ListenAndServe() (e.g. port already in use) will be
swallowed and not evident to the user.
2021-02-14 23:24:25 -05:00
Jonathon Reinhart b202a2209e Refactor out getTLSConfig() 2021-02-14 23:21:42 -05:00
Jonathon Reinhart f33105f83c Allow email field to be empty in allowedUsers file
In this case, it is not checked.
2021-02-09 00:00:36 -05:00