Commit Graph

164 Commits

Author SHA1 Message Date
Omar Polo aae8f6bf2b change the flags to be consistent with other OpenBSD daemons
-d is `debug' (run in the foreground)
 -f to load the configuration file

adjust regress and contrib accordingly
2022-09-08 21:34:29 +00:00
Omar Polo 32fbc47803 drop the configless mode from gmid; now it's provided by `ge' 2022-09-08 20:44:35 +00:00
Omar Polo d29a2ee224 get rid of the CGI support
I really want to get rid of the `executor' process hack for CGI scripts
and its escalation to allow fastcgi and proxying to work on non-OpenBSD.

This drops the CGI support and the `executor' process entirely and is
the first step towards gmid 2.0.  It also allows to have more secure
defaults.

On non-OpenBSD systems this means that the sandbox will be deactivated
as soon as fastcgi or proxying are used: you can't open sockets under
FreeBSD' capsicum(4) and I don't want to go thru the pain of making it
work under linux' seccomp/landlock.  Patches are always welcome however.

For folks using CGI scripts (hey, I'm one of you!) not all hope is lost:
fcgiwrap or OpenBSD' slowcgi(8) are ways to run CGI scripts as they were
FastCGI applications.

fixes for the documentation and to the non-OpenBSD sandboxes will
follow.
2022-09-06 16:11:09 +00:00
Omar Polo a555e0d67b copyright years 2022-07-04 09:48:39 +00:00
Omar Polo 18bd83915e sort the MIME mappings and do a binary search to match 2022-04-08 15:14:09 +00:00
Omar Polo 54203115cd don't load the built-in list when using `types' 2022-04-08 13:52:35 +00:00
Omar Polo d8d170aa5e allow add_mime to fail
add_mime nows allocate dinamically copies of the passed strings, so
that we can actually free what we parse from the config file.

This matters a lot especially with lengthy `types' block: strings that
reach the internal mapping are never free'd, so every manual addition
is leaked.
2022-04-08 13:44:49 +00:00
Omar Polo e5d82d9472 const-ify some tables
matches found with

	% grep -R '=[	 ]*{' . | fgrep -v const
2022-03-19 11:02:42 +00:00
Omar Polo 1cdea97b6c allow using a custom hostname for SNI during proxying
add a `sni' option for the `proxy' block: the given name is used instead
of the one extracted by the `relay-to' rule.
2022-01-30 10:14:44 +00:00
Omar Polo b7967bc1f6 proxy: allow multiple proxy blocks, matching options and validations
as a side effect the order of the content of a server block is relaxed:
options, location or proxy blocks can be put in any order.
2022-01-02 16:33:28 +00:00
Omar Polo 7bdcc91ec7 simplify the proxying code
it doesn't make any sense to keep the proxying info per-location:
proxying only one per-vhost.  It can't work differently, it doesn't make
sense anyway.
2022-01-01 17:08:39 +00:00
Omar Polo d49093c105 support optional client certificate for proxy rule 2022-01-01 16:33:44 +00:00
Omar Polo 72b033ef18 add ability to proxy requests
Add to gmid the ability to forwad a request to another gemini server and
thus acting like a reverse proxy.  The current syntax for the config
file is

	server "example.com" {
		...
		proxy relay-to host:port
	}

Further options (like the use of custom certificates) are planned.

cf. github issue #7
2021-12-29 20:36:54 +00:00
Omar Polo 193380eaa4 free OCSP path when clearing the config
was forgotten in ff05125eb8
2021-10-24 16:57:31 +00:00
Omar Polo 7fa6717647 fmt 2021-10-15 08:03:11 +00:00
Stephen Gregoratto ff05125eb8 Implement OCSP stapling support
Currently dogfooding this patch at gemini.sgregoratto.me. To test,
run the following command and look for the "OCSP response" header:

 openssl s_client -connect "gemini.sgregoratto.me:1965" -status
2021-10-15 09:58:23 +02:00
Omar Polo f0a01fc742 two -n to dump the parsed configuration
This adds a barebone dumping of the parsed configuration.  It is not
complete, but I'm interested in dumping the full path to `cert' and
`key' in order to write some scripts that can inspect the
configuration, extract the certificates and renew them when expired
automatically.

It's not easy to parse gmid configuration otherwise because the syntax
is flexible and users can use macros.  Instead, the idea is to run
gmid and let it dump the configuration once it's been parsed in a
static and predictable format.

Now is possible to parse gmid configuration with, say, awk or perl.
2021-10-09 21:40:55 +00:00
Omar Polo 807869c14e print the error too if we can't open a directory
It's not intuitive to print

	open ... for domain xyz

it doesn't convey that the open failed.

now it appends the error string, at least the user can understand that
something went wrong.

reported by cage on irc, thanks!
2021-10-07 17:19:45 +00:00
Omar Polo 4cd2520965 one FastCGI connection per client
FastCGI is designed to multiplex requests over a single connection, so
ideally the server can open only one connection per worker to the
FastCGI application and that's that.

Doing this kind of multiplexing makes the code harder to follow and
easier to break/leak etc on the gmid side however.  OpenBSD' httpd
seems to open one connection per client, so why can't we too?

One connection per request is still way better (lighter) than using
CGI, and we can avoid all the pitfalls of the multiplexing (keeping
track of "live ids", properly shut down etc...)
2021-10-07 10:47:02 +00:00
Omar Polo 81e0f00078 fmt 2021-09-24 08:10:07 +00:00
Omar Polo df0c2926cc use memset(3) rather than bzero(3)
There's no difference, but bzero(3) says

STANDARDS
     The bzero() function conforms to the X/Open System Interfaces option of
     the IEEE Std 1003.1-2004 (“POSIX.1”) specification.  It was removed from
     the standard in IEEE Std 1003.1-2008 (“POSIX.1”), which recommends using
     memset(3) instead.

so here we are.
2021-09-24 08:08:49 +00:00
Omar Polo 2e31927606 don't crash if -n is given without -c
If -n is given without -c, config_path is still NULL and it would
crash due to a NULL deference.
2021-08-23 22:43:56 +00:00
Omar Polo 735336b21e unbreak configless mode
An un-initialized field in the configless code path leads to a crash
on the first request.
2021-07-19 11:15:44 +00:00
Omar Polo 391825e360 move parse_portno to gmid.c
it's used only to parse the -p flag.  While there add check_port_num
to check the range for the port.
2021-07-09 13:06:58 +00:00
Omar Polo a8a1f43921 style(9)-ify 2021-07-07 09:46:37 +00:00
Omar Polo 8a50fc0330 initialize the logger early
Initialize the logger as soon as possible and log by default to
stderr.  With this, some (common?) errors are printed early instead of
ending up in syslog.

	# NB: this is in configless mode
	% ./gmid -p 80
	[2021-07-07 11:05:57] bind: Address already in use
	% ./gmid -p 81
	[2021-07-07 11:13:53] bind: Permission denied
	%
2021-07-07 09:18:24 +00:00
Omar Polo 090b8a89fa gracefully shut down fastcgi backends
we need to delete the events associated with the backends, otherwise
the server process won't ever quit.

Here, we add a pending counter to every backend and shut down
immediately if they aren't handling any client; otherwise we try to
close them as soon as possible (i.e. when they close the connection to
the last connected client.)
2021-07-06 10:54:27 +00:00
Omar Polo ef945cf415 reset fcgi array in free_config
otherwise path, port and/or prog could become an invalid pointer.
2021-07-06 10:46:50 +00:00
Omar Polo f98e9045ae add -D to define macros from the cmd line 2021-06-29 12:39:34 +00:00
Omar Polo 0be2a537e6 sync the usage; while there also change order and capitalize 2021-06-29 11:04:29 +00:00
Omar Polo fdb43a4c0e define GMID_STRING and reuse-it
GMID_VERSION follows the CGI/FastCGI style, i.e. project_name/version.

Define GMID_STRING with a more "human" variant "project_name version",
and reuse that in the --help and --version codepath.
2021-06-29 10:56:07 +00:00
Omar Polo 0233b0f6b9 add version in usage 2021-06-29 10:51:42 +00:00
Omar Polo 9327bc045a use getprogname() in usage() 2021-06-29 10:50:39 +00:00
Omar Polo 5777923bb0 use getopt_long, add --help as synonym of -h and -V/--version 2021-06-29 10:49:59 +00:00
Omar Polo e952c5052a allow sending fd to log on to the logger process
the logger process now can receive a file descriptor to write logs
to.  At the moment the logic is simple, if it receives a file it logs
there, otherwise it logs to syslog.  This will allow to log on custom
log files.
2021-06-15 08:06:10 +00:00
Omar Polo ab1e0169b9 free fastcgi param list 2021-06-12 10:20:36 +00:00
Omar Polo 3b33eab3ad TAILQ_REMOVE env and aliases during config_free
it's not technically required, since a couple of lines below we free
whole host struct, and we don't have code that may use
h->{env,aliases} afterwards, but it's nice not to have invalid
pointers around.  it may bite in the future.
2021-06-12 10:19:17 +00:00
Omar Polo 8ad1c57024 fastcgi: a first implementation
Not production-ready yet, but it's a start.

This adds a third ``backend'' for gmid: until now there it served
local files or CGI scripts, now FastCGI applications too.

FastCGI is meant to be an improvement over CGI: instead of exec'ing a
script for every request, it allows to open a single connection to an
``application'' and send the requests/receive the responses over that
socket using a simple binary protocol.

At the moment gmid supports three different methods of opening a
fastcgi connection:

 - local unix sockets, with: fastcgi "/path/to/sock"
 - network sockets, with: fastcgi tcp "host" [port]
   port defaults to 9000 and can be either a string or a number
 - subprocess, with: fastcgi spawn "/path/to/program"
   the fastcgi protocol is done over the executed program stdin

of these, the last is only for testing and may be removed in the
future.

P.S.: the fastcgi rule is per-location of course :)
2021-05-09 18:23:36 +00:00
Omar Polo 7b2d743260 move pidfile & cgi to global vars 2021-05-01 12:17:42 +00:00
Omar Polo fdea6aa0bc allow ``root'' rule to be specified per-location block 2021-04-30 17:16:34 +00:00
Omar Polo cc8c2901ad added ``alias'' option to define hostname aliases for a server 2021-04-29 18:23:35 +00:00
Omar Polo 8e8b2e252c pidfile support with `-P pidfile' 2021-04-28 12:45:22 +00:00
Omar Polo 48b69cb2dc fix some logging
- we can't use log_* or fatal() before logger_init
- err -> errx if errno isn't involved
2021-04-28 12:43:17 +00:00
Omar Polo 9cc630aa63 added ``env'' option to define environment vars for CGI scripts 2021-04-28 12:43:17 +00:00
Omar Polo 419a423520 keep verbosity level after config reload 2021-04-28 12:42:36 +00:00
Omar Polo 1b333122a9 typo 2021-04-26 20:58:06 +00:00
Omar Polo 5d1474a561 typo in comment 2021-04-20 09:53:33 +00:00
Omar Polo 3841a36930 restore signal handlers before exec'ing CGI scripts 2021-04-20 09:53:03 +00:00
Omar Polo b8e64ccd44 list instead of fixed-size array for vhosts and locations
saves some bytes of memory and removes the limit on the maximum number
of vhosts and location blocks.
2021-03-31 16:32:18 +00:00
Omar Polo 7e1df73d7d fix mkdirs: create directories recursively 2021-03-31 13:56:58 +00:00