Commit Graph

24 Commits

Author SHA1 Message Date
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
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
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
796c6e75d7 fix build on non-OpenBSD systems
not every system has a __dead attribute for functions.  This fixes the
build on FreeBSD.
2021-01-11 15:16:50 +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
Omar Polo
28778244d6 fix build 2021-01-11 12:53:46 +00:00
Omar Polo
33756bd235 accept both ipv4 and ipv6 2021-01-10 22:56:33 +00:00
Omar Polo
709d6e5ead log also the port of the client 2021-01-10 22:29:22 +00:00
Omar Polo
9b374f41ee macro reordering
and while there replace SAFE_SETENV with an inline function.  LOG is
more difficult to transform into an inline function, given the string
concatenations it does.  The other LOG* and FATAL macros are fine as
they already are.
2021-01-10 14:40:14 +00:00
Omar Polo
ef04b55160 switch to Bjoern Hoehrmann UTF-8 decoder
It's correct, while my hacked valid_multibyte_utf8 would allow things
that aren't technically UTF8.
2021-01-09 20:32:23 +00:00
Omar Polo
6c6c7a0ed7
rename cgi_setpoll_on_* to cgi_poll_on_* 2020-12-28 18:01:06 +01:00
Omar Polo
3d9a1c73de
fixing prototype order 2020-12-28 09:57:58 +01:00
Omar Polo
4a28dd014a
ignore also SIGHUP
SIGHUP is sent when the tty is detached and by default kills the
process.  When we run in the background we don't care anymore about
the tty, so it should be safe for us to ignore SIGHUP.  (frankly,
I expected daemon(3) to do stuff like this for us).
2020-12-28 09:55:56 +01:00
Omar Polo
6d91731552
fmt 2020-12-27 13:27:15 +01:00
Omar Polo
33d32d1fd6
implement a valid RFC3986 (URI) parser
Up until now I used a "poor man" approach: the uri parser is barely a
parser, it tries to extract the path from the request, with some minor
checking, and that's all.  This obviously is not RFC3986-compliant.

The new RFC3986 (URI) parser should be fully compliant.  It may accept
some invalid URI, but shouldn't reject or mis-parse valid URI.  (in
particular, the rule for the path is way more relaxed in this parser
than it is in the RFC text).

A difference with RFC3986 is that we don't even try to parse the
(optional) userinfo part of a URI: following the Gemini spec we treat
it as an error.

A further caveats is that %2F in the path part of the URI is
indistinguishable from a literal '/': this is NOT conforming, but due
to the scope and use of gmid, I don't see how treat a %2F sequence in
the path (reject the URI?).
2020-12-25 13:13:12 +01:00
Omar Polo
d5aba4c791
added missing copyright stuff 2020-12-24 16:49:55 +01:00
Omar Polo
488f059ac4
moving declarations to header file 2020-12-24 16:48:39 +01:00