Commit Graph

116 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 5f564d23e9 mention libretls 2021-01-17 13:53:08 +00:00
Omar Polo 65fba1d570 [seccomp] allow also poll
on the latest fedora we glibc uses poll.  On the other linux distro I
tried (void), musl is probably providing poll as a ppoll wrapper.
2021-01-17 13:51:09 +00:00
Omar Polo 771d8f281b build docs + install and static targets 2021-01-17 12:12:37 +00:00
Omar Polo 0170ba023f re-enable daemon mode
with the split into two process, the call to daemon was lost
2021-01-17 11:56:50 +00:00
Omar Polo b3927be446 fix runtime test on linux 2021-01-17 11:49:32 +00:00
Omar Polo 364f10dbcd add runtime tests for the server 2021-01-17 11:34:06 +00:00
Omar Polo 76fd55f437 grammar 2021-01-17 10:06:52 +00:00
Omar Polo 7a11e8a5d3 sync changes 2021-01-17 09:43:29 +00:00
Omar Polo ea58dab1a7 update readme 2021-01-17 09:42:10 +00:00
Omar Polo c2e39fcfed we don't need to check for CGI anymore 2021-01-17 09:37:44 +00:00
Omar Polo 71b7eb2f8c initial seccomp support 2021-01-17 09:34:27 +00:00
Omar Polo 7146dd552f missing break 2021-01-17 09:34:06 +00:00
Omar Polo d939d0f09e switch to getcwd 2021-01-17 09:33:45 +00:00
Omar Polo 881dc835d0 wording 2021-01-16 20:14:02 +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 bd726b55be set SERVER_NAME to the vhost when executing CGI scripts 2021-01-15 19:23:43 +00:00
Omar Polo 98c8f038ac drop inet_ntop leftovers
we switched to getnameinfo some time ago, but that call to inet_ntop
remained.  Fortunately, it doesn't harm, since what i wrote is
overwritten by getnameinfo and the provided buffer should be large
enough.
2021-01-15 19:15:13 +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 8696c5ea24 sync changes 2021-01-15 18:24:58 +00:00
Omar Polo b777bf4b2b check also that the port number matches 2021-01-15 18:24:24 +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 4ad11931ec update README 2021-01-15 09:35:06 +00:00
Omar Polo 6214c12719 added sample configuration 2021-01-15 09:31:52 +00:00
Omar Polo e4d82becb7 normalize host name when parsing the IRI
RFC3986 3.2.2 "Host" says that

> Although host is case-insensitive, producers and normalizers should
> use lowercase for registered names and hexadecimal addresses for the
> sake of uniformity, while only using uppercase letters for
> percent-encodings.

so we cope with that.
2021-01-15 09:27:42 +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 4d2ec6d705 typo 2021-01-13 19:06:51 +00:00
Omar Polo 9939ddcf9d sync changes 2021-01-13 19:03:21 +00:00
Omar Polo de428fff65 normalize schema when parsing the IRI
RFC3986 in section 3.1 "Scheme" says that

> Although schemes are case-insensitive, the canonical form is
> lowercase and documents that specify schemes must do so with
> lowercase letters.  An implementation should accept uppercase
> letters as equivalent to lowercase in scheme names (e.g., allow
> "HTTP" as well as "http") for the sake of robustness but should only
> produce lowercase scheme names for consistency.

so we cope with that.  The other possibility would have been to use
strcasecmp instead of strcmp when checking on the protocol, but since
the "case" version, although popular, is not part of any standard
AFAIK I prefer downcasing while parsing and be done with it.
2021-01-13 19:00:53 +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 6a9ae70773 remove infinite loop 2021-01-11 14:26:43 +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 b9220ca4de new README + wording in manpage 2021-01-11 12:51:25 +00:00
Omar Polo 85dff1f9c3 fix remote_user for CGI and add -6 flag to enable ipv6 2021-01-11 12:08:50 +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 80bbcad5f2 make FATAL and LOG inline functions
other functions that aren't macros anymore.  LOG went under a rename
to logs because log is a builtin (the math function), or so gcc says.
2021-01-10 15:50:27 +00:00
Omar Polo 945d22d1f2 inline should be before type, gcc says
clang doesn't seem to care.
2021-01-10 15:47:13 +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 579e21b35a switch some macros to inline functions
they expanded multiple times their argument, since inline is standard
(and works on GCC 4 too!) why don't use it?
2021-01-09 20:38:26 +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 578ba2d81b remove leftovers from debugging 2021-01-08 17:01:42 +00:00
Omar Polo 16ace04d45 simplify loop
todo was initially there for an optimization: don't loop to MAX_USERS
when you know the upper limit is todo.
2021-01-08 16:59:50 +00:00
Omar Polo 4c4167393a
simplify unveil/pledge calls 2021-01-01 13:03:04 +01:00