Commit Graph

224 Commits

Author SHA1 Message Date
Omar Polo f53f5e5fe1 fix config dumping (-nn) handling
with the privsep rework the config dumping was unadvertitely broken,
it prints the content of the key itself.
2024-04-04 11:22:06 +00:00
Omar Polo 248fb833f9 fix `log access path' with chroot
We should open the log file inside the chroot; missed in
4acf495f41.

See https://github.com/omar-polo/gmid/issues/24
2024-03-03 15:43:58 +00:00
Omar Polo 83a2644bfb convert remaining code to the imsg getters
Now gmid doesn't touch anymore the internals of the imsg structs.
2024-01-21 19:40:06 +00:00
Omar Polo 0d5282b647 configure: add --sysconfdir / $SYSCONFDIR handling
so that we don't have to hardcode /etc in gmid.c.  Helps on systems
like FreeBSD where the non-base programs are expected to look for
their config in /usr/local/etc.
2024-01-11 13:17:44 +00:00
Omar Polo e371817b34 fix configtest with chroot
The configtest checks try to open the root directories too, operation
that can fail when they're expected to be inside a chroot.
2024-01-09 14:15:58 +00:00
Omar Polo 43b38b2dbb copyright++ 2023-10-18 17:15:47 +00:00
Omar Polo 6be41efe33 tweak log_request() comment
gg -> gemexp and better wording.
2023-08-28 21:39:59 +00:00
Omar Polo ddbcd3c13f use the subject' common name as the user field in log 2023-08-07 14:04:47 +00:00
Omar Polo 35579431eb remove debugging leftover 2023-08-07 13:58:43 +00:00
Omar Polo 3b431c09d9 try hard at loading the configuration during conftest (-n)
Attempt to do also a few more steps that were previously done only
at runtime.  This can help verifying that the keypairs are matching
for example, but also that there are no typos in the path to the
root directories.

Was requested some time ago by Marian Mizik, thanks for the feature
request!
2023-08-07 12:40:44 +00:00
Omar Polo 9abba172b6 add `log syslog facility' to use a different syslog(3) facility
Was requested ages ago by Karl Jeacle, now that there is some better
support for configuring the logging there's no excuse to add this.
It helps with filtering from syslog.d / syslog.conf.
2023-08-07 09:34:19 +00:00
Omar Polo 26df50981f actually use the specified log style 2023-08-03 22:37:34 +00:00
Omar Polo b5963536c8 change the 'condensed' style to include the size of the request too
will be used in the future to log how much byte a titan request
uploaded.
2023-08-01 16:59:25 +00:00
Omar Polo 46bcc4ea95 add log syslog off; don't turn syslog off when log access is specified 2023-07-26 08:10:12 +00:00
Omar Polo cba01a8687 rename IMSG_LOG_TYPE to ACCESS 2023-07-26 07:55:51 +00:00
Omar Polo abd261d25b allow to change the logging style; introduce some new ones
add `log style <style>'; The old default is called `legacy' now, a
new default format is added called `condensed', and `common' and
`combined' to mimick Apache httpd and nginx (respectively) are also
added.
2023-07-25 20:07:26 +00:00
Omar Polo e075021085 still respect `log' when in debug mode 2023-07-24 14:07:28 +00:00
Omar Polo 4acf495f41 open the log files inside the chroot 2023-07-24 09:05:33 +00:00
Omar Polo 3bda540e34 reopen log files upon SIGUSR2 2023-07-24 09:00:19 +00:00
Omar Polo 226f13ece0 add ability to log to files with log access <path> 2023-07-24 08:50:49 +00:00
Omar Polo 2c3810687f change log_request to take the code and meta unpacked
don't know what i was smoking when I wrote log_request() like that...
2023-07-01 18:41:46 +00:00
Omar Polo ed164e7221 call getnameinfo() only once per request 2023-06-26 09:44:46 +00:00
Omar Polo 287ab86538 default chroot to user' home if unset 2023-06-24 19:42:31 +00:00
Omar Polo 509d0509a5 implement `listen on'
Listening by default on all the addresses is so bad I don't know
why I haven't changed this before.  Anyway.

Add a `listen on $hostname port $port' syntax to the config file
and deprecate the old "port" and "ipv6" global setting.  Still try
to honour them when no "listen on" directive is used for backward
compatibily, but this will go away in the next next version hopefully.

At the moment the `listen on' in server context don't filter the
host, i.e. one can still reach a host from a address not specified
in the corresponding `liste on', this will be added later.
2023-06-23 21:03:29 +00:00
Omar Polo 37df23d183 rename client->addr to raddr (remote address) and keep original length 2023-06-23 21:03:29 +00:00
Omar Polo ab55c7815e typo; use the `l' variable not `len' 2023-06-23 21:03:24 +00:00
Omar Polo 86693a33ab add a privsep crypto engine
Incorporate the OpenSMTPD' privsep crypto engine.  The idea behind
it is to never load the certificate' private keys in a networked
process, instead they are loaded in a separate process (the `crypto'
one) which signs payloads on the behalf of the server processes.
This way, we greatly reduce the risk of leaking the certificate'
private key should the server process be compromised.

This currently compiles only on LibreSSL (portable fix is in the
way).
2023-06-11 11:03:59 +00:00
Omar Polo 7fff8aa6cb parse the config file only once
Don't have all the processes read gmid.conf.  The parent needs to do
that, and the will send the config to the children (already
happening.)  The other processes were reading the config anyway to
figure out the user and the chroot (if enabled); make the parent pass
additional flag to propagate that info.

We dissociate a bit from the "usual" proc.c but it's a change worth
having.
2023-06-09 17:50:28 +00:00
Omar Polo 5af19830c3 move print_conf and make it take the config as argument 2023-06-09 17:29:52 +00:00
Omar Polo 792f302ace use fatal/fatalx instead of err/errx in daemon code 2023-06-09 17:27:41 +00:00
Omar Polo 68368f4c29 parse_conf: don't die on error, return -1
this avoids having the daemon dieing on SIGHUP with a bad config
file.
2023-06-09 17:24:37 +00:00
Omar Polo af1dab1870 don't have the config being a global 2023-06-09 17:18:04 +00:00
Omar Polo e45334e6ae move hosts into the config struct 2023-06-09 16:54:04 +00:00
Omar Polo 5d22294a59 move fastcgi from global var to the config struct
while here also make them a list rather than a fixed-size array.
2023-06-09 10:42:36 +00:00
Omar Polo ca84625a7f remove foreground / verbose from config
set them as global vars; rename foreground -> debug
2023-06-08 17:29:08 +00:00
Omar Polo 85a575a444 remove forgotten include of logger.h 2023-06-08 17:28:33 +00:00
Omar Polo 47b0ff105a move log_request to gmid.c
so that ge can provide its own log_request without requiring a
separate logger process.
2023-06-08 16:16:14 +00:00
Omar Polo 4f4937f06a move make_socket to config.c and make it private 2023-06-08 16:07:01 +00:00
Omar Polo c26f2460e4 rework the daemon to do fork+exec
It uses the 'common' proc.c from various OpenBSD-daemons.

gmid grew organically bit by bit and it was also the first place where I
tried to implement privsep.  It wasn't done very well, in fact the
parent process (that retains root privileges) just fork()s a generation
of servers, all sharing *exactly* the same address space.  No good!

Now, we fork() and re-exec() ourselves, so that each process has a fresh
address space.

Some features (require client ca for example) are temporarly disabled,
will be fixed in subsequent commits.  The "ge" program is also
temporarly disabled as it needs tweaks to do privsep too.
2023-06-08 13:59:31 +00:00
Omar Polo f1f13cb7dc absolutify the path to the pid file 2023-06-08 13:56:09 +00:00
Omar Polo eae52ad493 switch to the more usual log.c 2023-06-06 11:46:40 +00:00
Omar Polo 281a8852b3 rename log.[ch] to logger.[ch] 2023-06-06 08:50:54 +00:00
Omar Polo 3a8c76eab2 rename PROC_MAX to PREFORK_MAX 2023-06-06 08:34:31 +00:00
Omar Polo c68baad22a move config-related code to config.c
reuse it in ge too.
2023-06-06 08:18:57 +00:00
Omar Polo 0046c1fe9c call setlocale() 2023-06-06 08:11:30 +00:00
Omar Polo 070b32952c move and dedup the tls initalization in server.c 2023-06-05 21:10:18 +00:00
Omar Polo 0ac785a6fa revert aae8f6bf2b
it's just not worth it to inflict this breaking change to the users.
2023-06-05 20:35:12 +00:00
Omar Polo df5058c919 provide a more usual fatal
fatal usually appends the error string.  Add 'fatalx' that doesn't.
Fix callers and move the prototypes to log.h
2023-06-05 17:07:52 +00:00
Omar Polo a01a91db06 move some server-related code to server.c 2023-06-05 16:18:57 +00:00
Omar Polo 9a821f8c0f fold long lines 2023-06-05 15:07:24 +00:00