Commit Graph

164 Commits

Author SHA1 Message Date
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
cbb7f9fc28 move logger() prototype to gmid.h and delete logger.h 2023-06-08 17:03:13 +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
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
fc9cc497e0 move some new_* functions from parse.y to utils.c 2023-06-08 15:59:53 +00:00
Omar Polo
e69e1151f6 drop now unused dispatch_imsg 2023-06-08 15:57:11 +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
3a8c76eab2 rename PROC_MAX to PREFORK_MAX 2023-06-06 08:34:31 +00:00
Omar Polo
f057c92622 adjust comments 2023-06-06 08:20:09 +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
bb595bff79 remove unused define 2023-06-05 21:11:40 +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
534afd0ddc make the various strings in the config fixed-length
will help in future restructuring to have fixed-size objects.
2022-10-05 15:10:44 +00:00
Omar Polo
9715efe6f3 retire fcgi' prog field
spawning programs was a hidden feature used only for testing.  It's
gross and when got removed, I forgot to remove the field as well.
2022-10-05 10:41:54 +00:00
Omar Polo
c5b4db930e specify custom version strings for the various cmds 2022-09-10 14:29:40 +00:00
Omar Polo
5c4855299c remove remnats tentacles of the executor process 2022-09-10 13:28:19 +00:00
Omar Polo
934f957f29 remove unused entrypoint field
ventige of the cgi support (and lack of url rewriting)
2022-09-10 10:22:24 +00:00
Omar Polo
2025e96d97 drop cgi vestiges from the struct host
The `env' list is no longer used since CGI scripts were removed
2022-09-10 09:48:30 +00:00
Omar Polo
cd5826b8ba retire the deprecated mime' and map' config options 2022-09-10 09:43:57 +00:00
Omar Polo
aa9543b9fd make the mime types fixed-sized too 2022-09-10 09:40:05 +00:00
Omar Polo
7277bb7dc2 make config fields chroot' and user' fixed-size 2022-09-10 09:21:09 +00:00
Omar Polo
7600099513 optionally disable the sandbox on some systems
The FreeBSD and Linux' sandbox can't deal with `fastcgi' and `proxy'
configuration rules: new sockets needs to be opened and it's either
impossible (the former) or a huge pain in the arse (the latter).

The sandbox is still always used in case only static files are served.
2022-09-06 16:40:38 +00:00
Omar Polo
36e6e793a1 gc FILE_EXECUTABLE 2022-09-06 16:25:10 +00:00
Omar Polo
1ab7c96bb3 gc sandbox_executor_process 2022-09-06 16:24:45 +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
f2f8eb35c8 encode file names in the directory index
Spotted the hard way by cage
2022-07-04 09:31:36 +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
ea27eaaa83 fix an out-of-bound access in start_cgi
Long time ago, client->req was a static buffer so the memcpy was safe.
However, it's been since moved to a dynamically allocated string, so
it's very often smaller than sizeof(req.buf) (1024), hence the out of
bound access which results in a SIGSEGV very often on OpenBSD thanks to
Otto' malloc.

The situation with the iri parser, client->req and how the request is
forwarded to the other process needs to be improved: this is just a fix
to address the issue quickly, a better one would be to restructure the
iri parser APIs and rethink how the info is forwarded to the ex process.
2022-03-27 12:52:59 +00:00
Omar Polo
3fdc457c8d swap try_client_by_id with client_by_id
i.e. allow client_by_id to fail and return NULL.

Initially I thought it was a good idea to shut down a server process
if we receive an invalid client id as reply from one of our requests
to the executor process.  This turned out not to be correct since a
client can (read: will) disconnect in the delay beteewn we acknowledge
their request and the cgi script execution.

The fastcgi and proxy handler already handled this situation, so
they're unaffected.

This allows an attacker to make gmid unresponsible by just making
enough requests until they hit the right timing.
2022-03-26 11:32:26 +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
e0f6dc646d improve proxy error path
properly release everything when during client_close if the request
was managed by a proxy.
2022-01-27 09:55:52 +00:00
Omar Polo
ba94a608a8 add `require client ca' for proxy blocks
refactor the code that calls validate_against_ca into an helper
function to reuse it in both apply_require_ca and (optionally) in
apply_reverse_proxy.
2022-01-04 23:14:34 +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
593e412b49 allow to disable TLS when proxying requests 2022-01-01 20:16:14 +00:00
Omar Polo
c7c8ef448b add protocols' option to proxy' rule 2022-01-01 19:04:50 +00:00
Omar Polo
5128c0b0e3 add verifyname' option for proxy' rule 2022-01-01 18:50:10 +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
bd5f79542c update copyright years 2022-01-01 16:36:17 +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
054387bb26 move struct iri and parser at the top of the file 2021-12-29 19:24:33 +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
492a274fd7 add compat for sys/tree.h 2021-10-07 11:36:25 +00:00