Commit Graph

693 Commits

Author SHA1 Message Date
Omar Polo 536026c565 add script to automatically renew self-signed certificates 2021-10-11 14:42:11 +00: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 5eb3fc905f don't work around a missing -Wno-unused-parameter
It's been there for a long time, and it's frankly annoying to pretend
to use parameters.  Most of the time, they're there to satisfy an
interface and nothings more.
2021-10-09 18:54:41 +00:00
Omar Polo c6bcc919c6 don't wrap the paths inside a <code></code> 2021-10-09 17:19:25 +00:00
Omar Polo c7b79c9eed fix navigation in contrib page 2021-10-09 17:13:35 +00:00
Omar Polo 1298e4307f split the cert generation example on multiple lines 2021-10-09 17:09:56 +00:00
Omar Polo 679d5d1a61 tweak the style for the manpage exported in HTML 2021-10-09 17:09:56 +00:00
Omar Polo 35340c9f1e typos 2021-10-09 16:54:33 +00:00
Omar Polo 540d05dedc typo 2021-10-09 16:31:43 +00:00
Omar Polo 0111ad5d26 add the Quickstart page 2021-10-09 16:30:36 +00:00
Omar Polo a83ba84448 mention gencert in contrib.{gmi,html} 2021-10-09 14:16:28 +00:00
Omar Polo d7e2e22c58 add gencert, a simple script to generate self-signed certs 2021-10-09 14:07:21 +00:00
Omar Polo 9bb2f62e24 tweak landlock comment 2021-10-08 15:55:48 +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 492a274fd7 add compat for sys/tree.h 2021-10-07 11:36:25 +00:00
Omar Polo 207b3e80d8 Store clients inside a splay tree
From day one we've been using a static array of client struct to hold
the clients data.  This has variuos drawbacks, among which:

 * reuse of the storage  ("shades of heartbleed")
 * maximum fixed amount of clients connected at the same time
 * bugs are harder to debug

The last point in particular is important because if we mess the client
ids, or try to execute some functions (e.g. the various fcgi_*) after a
client has been disconnected, it's harder to "see" this "use after
free"-tier kind of bug.

Now I'm using a splay tree to hold the data about the live connections.
Each client' data is managed by malloc.  If we try to access a client
data after the disconnection we'll probably crash with a SIGSEGV and
find the bug is more easy.  

Performance-wise the connection phase should be faster since we don't
have to loop anymore to find an empty spot in the clients array, but
some operations could be slightly slower (compare the O(1) access in an
array with a SPLAY_FIND operation -- still be faster than O(n) thought.)
2021-10-07 11:20:34 +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 3096da4ef4 allow to run only a subset of the runtime tests
with
	make TESTS='test_1 test_2 ...' regress

now it's possible to run only that specified subset of tests.  It's
really useful during debugging :)
2021-10-07 08:55:44 +00:00
Omar Polo e4daebe44a plug a memory leak
c->req is set in client_read but never deallocated
2021-10-06 17:38:37 +00:00
Omar Polo 807a80cb9e fmt 2021-10-06 16:36:31 +00:00
Omar Polo b4c6cd9768 add the upload target to ease publishing the site 2021-10-04 13:01:41 +00:00
Omar Polo 9212cf1ba9 [gemini] tweak the contrib page
I find it more readable with some empty lines here and there
2021-10-04 12:57:46 +00:00
Omar Polo eb82dcfbf4 improve the service file usage instructions
Thanks Martin for providing these information :)
2021-10-04 12:56:11 +00:00
Omar Polo 12866f1911 add targets to serve the site locally 2021-10-04 12:54:46 +00:00
Omar Polo ae6870fa3b import the capsule/website 2021-10-04 10:42:35 +00:00
Omar Polo 568419b2c1 add .cirrus.yml
Add a cirrus CI config file that runs the regression suite on linux
amd64/aarch64 and on freebsd.
2021-10-04 10:05:34 +00:00
Omar Polo 6e0f14d51e re-add sha script; it's used in the Makefile
While there, use it in the tests too
2021-10-04 09:40:05 +00:00
Omar Polo 2072343d6b sync changelog 2021-10-04 09:35:17 +00:00
Omar Polo 260becda9c reduced the timeout time for single checks 2021-10-04 09:34:39 +00:00
Omar Polo d046e4d6b5 copy only `len' bytes, not the whole buffer
We ended up copying too much data from the fastcgi process.
2021-10-04 09:31:43 +00:00
Omar Polo 4a2a525d7c allow running only specific tests
It's now possible to run only a subset of the tests with:

	./runtime test1 test2 ...
2021-10-04 09:30:18 +00:00
Omar Polo c1272f63e4 sync 2021-10-04 09:08:21 +00:00
Omar Polo 99c91b4a51 remove unused script 2021-10-04 09:07:42 +00:00
Omar Polo 176179b2a9 rework the regression suite
The tests are still there, the suite is equivalent to the old one, but
this one is better structured.

The biggest annoyance I had with the old one was that it wasn't
straightforward to test only a specific set of tests.  It's still
impossible, but it's way easier to do it now.

This extract all the tests to their own functions.  It's overall
better in all possible regards.
2021-10-04 09:04:33 +00:00
Omar Polo c28994868e update clean target 2021-10-02 19:35:30 +00:00
Omar Polo a49800c86a sync 2021-10-02 17:21:26 +00:00
Omar Polo acafce5b7d libevent2 fix: unfreeze the client evbuffer
libevent2 has this concept of "freezeness" of a buffer.  It's a way to
avoid accidentally write/remove data from the wrong "edge" of the
buffer.  The client_tls_{read,write} functions need to add/drain data
from the opposite edge, hence the need for the unfreeze call.

This is the minimum change in order to work on libevent2 too.  Another
way would be to define evbuffer_{un,}freeze as NOP on libevent 1, but
it's ugly IMHO.
2021-10-02 17:20:56 +00:00
Omar Polo efb6210d77 improve libevent2 handling
* add configure check
* change the way the headers are required (copied from tmux)
2021-10-02 17:20:56 +00:00
Omar Polo d0071d8321 verbose logging for getnameinfo 2021-10-02 17:20:56 +00:00
Omar Polo 827cc37cff update tests
* we don't add a space before the lang anymore
* we're more strict in CGI handling: the `invalid' CGI script now
  triggers a 42 CGI ERROR
2021-10-02 17:20:56 +00:00
Omar Polo fa0299a26d drop now unused trim_req_iri 2021-10-02 17:20:56 +00:00
Omar Polo efe7d18029 new I/O handling on top of bufferevents
This is a big change in how gmid handles I/O.  Initially we used a
hand-written loop over poll(2), that then was evolved into something
powered by libevent basic API.  This meant that there were a lot of
small "asynchronous" function that did one step, eventually scheduling
the re-execution, that called each others in a chain.

The new implementation revolves completely around libevent'
bufferevents.  It's more clear, as everything is implemented around the
client_read and client_write functions.

There is still space for improvements, like adding timeouts for one, but
it's solid enough to be committed as is and then further improved.
2021-10-02 17:20:56 +00:00
Omar Polo 403c422041 [cgi] switch from pipe(2) to socketpair(2)
We can't use normal pipe(2)s with libevent in some cases.  Switch to
socketpair(2), which doesn't have the same problem.

This has the drawback that it doesn't prevent the CGI script from
reading stdout, for instance.  (sockets are two-way, pipes only one-way)
2021-10-02 17:20:56 +00:00
Omar Polo b618111a68 log more details for FastCGI errors
add the reported request id if there's a mismatch and both the gai error
and the errno value if getnameinfo fails.
2021-10-02 17:20:10 +00:00
Omar Polo 5f37f9c20d simplify error check 2021-10-02 17:20:10 +00:00
Omar Polo c016b65ca9 typo 2021-10-02 17:20:10 +00:00
Omar Polo f7ee799023 enforce PR_SET_NO_NEW_PRIVS in the logger process
otherwise landlock will refuse to enable itself and the logger process
dies.
2021-10-02 17:20:10 +00:00
Omar Polo 0c66b6ad55 forgot include 2021-09-26 20:01:32 +00:00
Omar Polo 6f27d2595a [seccomp] allow ioctl(FIONREAD)
it's needed by bufferevent_read
2021-09-26 20:00:38 +00:00
Omar Polo 2a44a2ab6e sync changelog 2021-09-26 17:00:16 +00:00