Commit Graph

178 Commits

Author SHA1 Message Date
Omar Polo 8aba5d8b21 remove dead code 2024-03-12 14:10:36 +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 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 c440a0ded9 log ip address and port when tls_handshake fails
These connection are not otherwise logged and it could be helpful
to track down the bad ip.
2023-08-28 21:42:58 +00:00
Omar Polo 81634643db fix comment (ge -> gemexp) 2023-08-11 16:18:37 +00:00
Omar Polo 390d312b22 don't call client_close() from fcgi/proxy bev handlers
We might end up calling client_close() from start_reply(), but that
will free the fcgi/proxy bufferevent while they're still used on the
stack.

Instead, start_reply() only sets REQUEST_DONE and exits, returning the
error eventually, so callers know when to stop.
2023-08-09 19:13:13 +00:00
Omar Polo d98ef73494 move strip_path to utils.c 2023-08-08 15:56:27 +00:00
Omar Polo 26df50981f actually use the specified log style 2023-08-03 22:37:34 +00:00
Omar Polo 6a8387e5f5 add `fastcgi off' to forceful skip fastcgi for a route 2023-07-23 19:04:37 +00:00
Omar Polo a1ba9650a9 revamp fastcgi configuration: make it per-location
this revamps the syntax in the configuration to better match httpd(8)
(and in general be less weird) and to allow per-location fastcgi
configurations.

the bare `param' is now deprecated, but for compatibility it acts
like `fastcgi param' would do now.  Same story for `fastcgi <pathÂ>'.
2023-07-23 18:45:05 +00:00
Omar Polo 71b02f6390 rename do_accept() -> server_accept() 2023-07-01 22:00:08 +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 e3ce19dcc1 change on fatalx -> log_warnx
we already check the validity of the format string, but still avoid a
gratious fatal() at runtime.
2023-07-01 14:22:26 +00:00
Omar Polo 80192f4589 rename fmt_sbuf -> fmtbuf; make the buffer explicit 2023-07-01 14:21:41 +00:00
Omar Polo 994fc034e5 avoid needless strlen() 2023-07-01 14:11:21 +00:00
Omar Polo e2003e7e30 simplify request handling
get rid of check_path(), it's overly complicated.  Instead, inline
open_file() in client_read() and rework open_dir() to just use
openat() instead of the complicate dance it was doing.

Simplify open_dir() too in the process: if the directory entry for the
index is not a regular file, pretend it doesn't exist.
2023-07-01 14:11:18 +00:00
Omar Polo 2339a71178 use a function-local buffer for the canonical redirect 2023-07-01 13:13:04 +00:00
Omar Polo c9e878d6a4 use snprintf() instead of chain of strlcpy/cat 2023-06-26 10:17:43 +00:00
Omar Polo ed164e7221 call getnameinfo() only once per request 2023-06-26 09:44:46 +00:00
Omar Polo da0821b6cb avoid gratious strlen; evbuffer_readln returns the length 2023-06-24 20:19:33 +00:00
Omar Polo 841633cfec plug memory leak in client_close_ev 2023-06-24 14:22:12 +00:00
Omar Polo ddf7a437de fix client_close_ev when tls_close() returns TLS_WANT_POLLIN/OUT
in those cases we need to reschedule the function and return, instead
of going on with the cleanup.
2023-06-24 14:21:57 +00:00
Omar Polo c5edb15740 properly handle handshake failures
If a TLS handshake fails there's nothing we can do, so don't attempt
to reply an error (the connected client is not speaking Gemini as
it's not using TLS at all) and instead just close the connection.

Fixes issue #13
2023-06-24 14:15:57 +00:00
Omar Polo eac9287d29 copyright years++ 2023-06-24 10:07:17 +00:00
Omar Polo df6282815f remove unused global flag 2023-06-24 10:03:03 +00:00
Omar Polo aa30aaedc8 don't match host if connecting from the wrong socket
limit how one given virtual host can be reached based on its `listen
on' lists
2023-06-24 10:02:46 +00:00
Omar Polo e50f85adcb load the certs per listening address 2023-06-24 09:50:30 +00:00
Omar Polo a0a42860d2 send host addresses to the server process 2023-06-24 09:14:35 +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 ba290ef3af disable the privsep crypto engine on !OpenBSD
it fails bandly at runtime on various linux distros and on freebsd.
Until a fix is found, disable it so I can move forward.
2023-06-11 12:18:27 +00:00
Omar Polo 237095fd9a remove has_siginfo
and wrap siginfo behind #ifdef SIGINFO.  avoids some warnings in !BSD.
2023-06-11 11:36:31 +00:00
Omar Polo b8d68fc8e4 fixes for -Wpointer-sign 2023-06-11 11:31:22 +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 f81a97b356 drop useless debug statement 2023-06-11 09:49:01 +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 deadd9e131 readd proxy certs and `require client ca' support
Was temporarly disabled during the transition to real privsep.
While here, fix a memory leak when using `require client ca'.

Also, avoid leaking info about the parent address space layout to
server processes by not sending pointer values.
2023-06-09 09:28:26 +00:00
Omar Polo 8eeb992206 less logger.h 2023-06-08 19:30:10 +00:00
Omar Polo 3886afceec make server_init and server_configure_done 'public'
server_configure_done is the code we ran in IMSG_RECONF_END splitted
in a separate functions.

This is all needed for ge.c which doesn't do privsep but needs to
bootstrap the server process.
2023-06-08 16:21:31 +00:00
Omar Polo 2b4ef796d7 remove debug code 2023-06-08 15:47:03 +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 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 070b32952c move and dedup the tls initalization in server.c 2023-06-05 21:10:18 +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 1e0b974519 send capsicum/landlock/seccomp hack to Valhalla 2023-05-08 10:27:32 +00:00
Omar Polo eb4f96c10a typo 2022-11-27 10:06:08 +00:00