Commit Graph

100 Commits

Author SHA1 Message Date
Omar Polo e3ddf39095 add the ``entrypoint'' option 2021-02-06 18:28:43 +00:00
Omar Polo 6abda252e9 added ``block return'' and ``strip'' options 2021-02-06 17:22:37 +00:00
Omar Polo 102d2e9cce missing argument for LOGI 2021-02-04 18:09:42 +00:00
Omar Polo 9543e3fbaf avoid race-condition
what if we receive a SIGHUP right after unblock_signal (or during the
whole block_signals...unblock_signals) but *before* the wait_sighup?
Yeah.
2021-02-04 18:09:30 +00:00
Omar Polo ca21e10043 reload configuration on SIGHUP 2021-02-04 13:23:15 +00:00
Omar Polo e824d03efa drop unnecessary check around close 2021-02-03 16:53:34 +00:00
Omar Polo 4e2e2ab1d3 refactor executor_main
now it's symmetrical to listener_main().
2021-02-03 16:37:53 +00:00
Omar Polo d672b8fba1 refactoring startup logic 2021-02-03 16:28:00 +00:00
Omar Polo 9edb828251 drop privileges after the fork 2021-02-03 14:13:32 +00:00
Omar Polo 3c680bddab configless: fixing the case of the implicit "."
I got bitten by the scope visibility rules.  After the end of the
block, the path variable is no longer valid, and in fact later
load_vhosts fails to open that (because the buffer gets invalidated)
2021-02-02 09:30:24 +00:00
Omar Polo bcf5d929e6 ensure absolute paths in config-less mode 2021-02-01 11:07:57 +00:00
Omar Polo 8503a1431d set cloexec status on the socketpair fds
the executor forks to spawn the cgi scripts, and they inherit the
socket for communication with the listener process.  Make that
impossible.
2021-01-31 11:07:12 +00:00
Omar Polo ef0f2ae88c remove unused function 2021-01-28 14:21:57 +00:00
Omar Polo 8904fa0e64 -v for verbose logging 2021-01-27 23:14:16 +00:00
Omar Polo 13ed2fb63f improve configuration parsing error 2021-01-27 16:45:45 +00:00
Omar Polo b736ca35f2 drop unused variable 2021-01-27 15:35:55 +00:00
Omar Polo 44ee1bac8b use starts_with in puny.c 2021-01-27 15:35:09 +00:00
Omar Polo 72bbed9136 make configless mode works again. also accept every host 2021-01-27 15:00:55 +00:00
Omar Polo 46af8c6cfe drop the daemon config in favour of the -f flag
Now it daemonize by default when running with a config, unless the -f
flag is given.
2021-01-27 12:04:37 +00:00
Omar Polo 3300cbe06a initial punycode support 2021-01-27 10:47:49 +00:00
Omar Polo 390a611893 sane defaults for the config-less mode 2021-01-27 10:43:55 +00:00
Omar Polo 8443bff77a rework the configless mode: change flags and generate certs 2021-01-25 14:08:31 +00:00
Omar Polo ae08ec7da5 chroot & drop privileges 2021-01-25 10:30:07 +00:00
Omar Polo 2030e31486 order 2021-01-25 09:45:09 +00:00
Omar Polo 252908e6bb added support for location blocks 2021-01-24 18:53:26 +00:00
Omar Polo 501e489c90 initialize config 2021-01-24 12:45:22 +00:00
Omar Polo 8d6ae384be move configuration init stuff in its own function 2021-01-24 10:39:48 +00:00
Omar Polo f77a8c867e add ends_with 2021-01-21 22:45:49 +00:00
Omar Polo ea28a44931 const-ify parameter to strtonum 2021-01-21 16:15:10 +00:00
Omar Polo a5a09e44b2 use strtonum 2021-01-21 16:07:12 +00:00
Omar Polo b2a6b61371 rename mimes to mime ; pass config esplicitly to mime* functions 2021-01-21 15:01:37 +00:00
Omar Polo 0ab65593e2 don't crash on wrong vhost or missing SNI
the new logging code was crashing if the client didn't support SNI or
if required an unknown vhost: this because we short-circuit in
handle_handshake to an error, so c->iri isn't populated yet (we don't
even read the request).

fixes #1
2021-01-21 08:26:21 +00:00
Omar Polo 0be51733ef improve logs
now we log the full IRI requested (before was only the path) and the
response line (even for CGI).
2021-01-20 18:54:44 +00:00
Omar Polo 0fbe79b33c improve mime handling
we still have an hardcoded list, but this implements the API needed to
modify the mappings.
2021-01-18 18:18:57 +00:00
Omar Polo 132cae8c6f removing err/warn functions with our fatal
err/warn is not available on some systems (unfortunately!) and in any
case don't play well with our daemon mode (that closes std{in,out,err}).
Use our fatal that is daemon-aware.
2021-01-18 18:15:58 +00:00
Omar Polo d3a08f4d17 reorganize: move bunch of functions to server.c
cgi.c wasn't really needed; it better to group all the server related
functions together, cgi or not.  Now gmid.c contains only startup and
utility code.
2021-01-17 23:23:58 +00:00
Omar Polo 0170ba023f re-enable daemon mode
with the split into two process, the call to daemon was lost
2021-01-17 11:56:50 +00:00
Omar Polo 7146dd552f missing break 2021-01-17 09:34:06 +00:00
Omar Polo d939d0f09e switch to getcwd 2021-01-17 09:33:45 +00:00
Omar Polo 881a9dd9c2 split into two processes: listener and executor
this way, we can sandbox the listener with seccomp (todo) or capsicum
(already done) and still have CGI scripts.  When we want to exec, we
tell the executor what to do, the executor executes the scripts and
send the fd backt to the listener.
2021-01-16 19:41:34 +00:00
Omar Polo 7edc455ab4 move cgi stuff to its own file 2021-01-15 19:08:28 +00:00
Omar Polo 5bc3c98ed4 add protocols to the config 2021-01-15 18:55:05 +00:00
Omar Polo b777bf4b2b check also that the port number matches 2021-01-15 18:24:24 +00:00
Omar Polo f7b816dc39 style 2021-01-15 15:21:51 +00:00
Omar Polo dafb57b8af sandbox also on FreeBSD with capsicum 2021-01-15 14:03:45 +00:00
Omar Polo 1590277007 conf & vhosts
* gmid.c (main): changed behaviour: daemon off by default
(main): changed -c in -C (cert option)
(main): changed -k in -K (key option, for consistency with -C)
(main): added -c to load a configuration
(main): certs, key and doc (-C -K and -d) doesn't have a default value anymore
(handle_handshake): add vhosts support
2021-01-15 09:17:43 +00:00
Omar Polo 9862b637c2 track handshakes
This alter the current state machine by adding S_HANDSHAKE as the
initial state.  There, we ensure we did the handshake and we check
SNI.  ATM we simply continue in S_OPEN, but later we can add virtual
host checks there, and skip to S_INITIALIZING with an error state if
the client is accessing a wrong host.
2021-01-13 18:40:18 +00:00
Omar Polo 0d7a38c4ce avoid __dead and return at the end of main 2021-01-11 15:28:25 +00:00
Omar Polo 7b1d979032 reject non-gemini protocols with 53 2021-01-11 14:45:57 +00:00
Omar Polo 3c1cf9d07c s/uri/iri since we accept IRIs 2021-01-11 13:08:00 +00:00