Commit Graph

57 Commits

Author SHA1 Message Date
Omar Polo
2fafa2d23e bring the CGI implementation in par with GLV-1.12556 2021-02-01 11:11:43 +00:00
Omar Polo
6016a593a3 invert the location precedence: first match wins
It's how httpd(8) does it, and it allows us to call fnmatch less time
2021-01-30 12:04:20 +00:00
Omar Polo
a2fd801327 puny_decode: set an error string 2021-01-29 17:11:03 +00:00
Omar Polo
35cf19e3f3 punycode: refactoring
use the correct term "label" instead of "component" when speaking
about the parts of a hostname.  Also, fix the sizes for max hostname
and label.
2021-01-28 16:25:59 +00:00
Omar Polo
473e4531d5 delete unused constant 2021-01-28 16:24:48 +00:00
Omar Polo
ef0f2ae88c remove unused function 2021-01-28 14:21:57 +00:00
Omar Polo
13ed2fb63f improve configuration parsing error 2021-01-27 16:45:45 +00:00
Omar Polo
fe5967cd02 const-ify strings in struct location 2021-01-27 15:53:30 +00:00
Omar Polo
44ee1bac8b use starts_with in puny.c 2021-01-27 15:35:09 +00:00
Omar Polo
c4f682f855 trim_req_iri: set error string 2021-01-27 15:05:16 +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
7957cbd9aa const-ify puny_decode (and add puny.c) 2021-01-27 11:21:23 +00:00
Omar Polo
3300cbe06a initial punycode support 2021-01-27 10:47:49 +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
252908e6bb added support for location blocks 2021-01-24 18:53:26 +00:00
Omar Polo
c8b7433918 added support for location blocks 2021-01-24 14:11:40 +00:00
Omar Polo
07b0a14218 void-ify some functions
their return value is no longer used, it's only confusing at this point.
2021-01-24 09:54:44 +00:00
Omar Polo
a87f662565 refactoring state management
instead of having a flag to discern between two different behaviours
in S_SENDING, split that state into S_SENDING_FILE and S_SENDING_CGI
(this will also make it easier in the future to add other sending
states).  While there, also get rid of `goodbye' and make start_reply
advance the state machine by itself.
2021-01-24 09:49:09 +00:00
Omar Polo
e7a2a99b5a added index option 2021-01-24 09:14:01 +00:00
Omar Polo
f890c8c54d use a helper to handle no-body replies 2021-01-22 13:58:54 +00:00
Omar Polo
36162ed86d rename goodbye -> close_conn 2021-01-22 13:45:27 +00:00
Omar Polo
f77a8c867e add ends_with 2021-01-21 22:45:49 +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
33ac26a0e5 fix prototypes 2021-01-21 14:49:11 +00:00
Omar Polo
12042ad700 add a configure script and some compat
tested on openbsd, alpine and void
2021-01-21 11:57:46 +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
2debfe2b1f drop useless field
was probably added to distinguish between AF_INET and AF_INET6, to use
different functions for logging.  But it wasn't really used, and now
we use getnameinfo anyway.
2021-01-19 18:49:36 +00:00
Omar Polo
6119e13e8a moving "default type" from global options to server options 2021-01-19 11:28:41 +00:00
Omar Polo
05c23a54ea add "lang" server option 2021-01-19 10:58:29 +00:00
Omar Polo
a010b0ddc5 move mimes into the struct config 2021-01-18 18:48:37 +00:00
Omar Polo
982069a120 add "mime" and "default type" option for the configuration 2021-01-18 18:43:47 +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
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