Commit Graph

188 Commits

Author SHA1 Message Date
Omar Polo f2c45fdab0 warn instead of dieing on unknown accept(2) failures 2024-06-10 10:25:54 +00:00
Omar Polo d4955d2891 fmt 2024-06-10 10:25:54 +00:00
Omar Polo 22ce7eb455 use a fatalx() rather than abort()
makes up for a nicer error message, and easier troubleshoot.
2024-06-10 10:25:54 +00:00
Omar Polo 0965162959 another range check 2024-06-10 08:24:16 +00:00
Omar Polo 36bdda94c1 detect and reject NUL bytes embedded in the request 2024-06-10 08:20:35 +00:00
Omar Polo 62aa1935cc use snprintf 2024-06-10 08:20:35 +00:00
Omar Polo da834b5803 fix `fastcgi off' handling
When a matching location has a `fastcgi off' directive, we should
honour that and stop searching for further location which may have
a `fastcgi' directive.

Bug reported by Alex // nytpu, thanks!
2024-06-03 16:14:09 +00:00
Omar Polo cd12ad1132 pretty-print the socket address at configuration parsing time
saves a getnameinfo(NI_NUMERICHOST) at runtime, even if it's pretty
cheap.
2024-05-29 08:03:59 +00:00
Omar Polo 1ef0cd0cdb relax the SNI requirement
There are legitimate cases where SNI can't be used, for example
when connecting via an IPv6 address, so don't rejects those requests.
Instead, fill the requested domain with the address (literal) of
the socket they're connected to and attempt to match on it.

This possibly still incur in a "won't proxy" error if the client
then requests a different hostname.

See the github issue https://github.com/omar-polo/gmid/issues/25
2024-05-29 07:52:13 +00:00
Omar Polo 89dca7ab54 s/MIN/MINIMUM/g 2024-05-25 17:44:35 +00:00
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