Commit Graph

938 Commits

Author SHA1 Message Date
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
Omar Polo 6c6c7a0ed7
rename cgi_setpoll_on_* to cgi_poll_on_* 2020-12-28 18:01:06 +01:00
Omar Polo b3deee7b38
initialize error string to avoid returning garbage 2020-12-28 17:50:26 +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 5a40216f37
fix CGI with new IRI parser
With new IRI, parser the old assumption of path starting with ./
is no longer valid.
2020-12-28 09:52:39 +01:00
Omar Polo 6d91731552
fmt 2020-12-27 13:27:15 +01:00
Omar Polo f722f3c5aa
typos 2020-12-26 11:22:07 +01:00
Omar Polo 60ff035518
mention IRI in changelong 2020-12-26 10:15:16 +01:00
Omar Polo 00781742c5
reject %00 2020-12-26 00:37:43 +01:00
Omar Polo df6ca41da3
IRI support
This extends the URI parser so it supports full IRI (Internationalized
Resource Identifiers, RFC3987).  Some areas of it can/may be improved,
but here's a start.

Note: we assume UTF-8 encoded IRI.
2020-12-26 00:33:11 +01:00
Omar Polo 043acc97b1
mention the %2F caveat 2020-12-25 13:15: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
Omar Polo 83000e2dd4
improve wording
"concurrently" means at the same time, which can be confusing when we
say that it's single-threaded on a single process.
2020-12-21 15:51:09 +01:00
Omar Polo 51d876f030
always check absolutify_path return 2020-12-21 15:42:06 +01:00
Omar Polo 4f12842dfe
mention change in changelog file 2020-12-21 14:40:04 +01:00
Omar Polo 231bfcdc03
make -d handle correctly non-absolute paths
before the -d option only accepted absolute paths, and this wasn't
documented.  Even more, with the default value of "docs" it won't
work.  Now it transforms all relative paths to absolute paths before
going on.
2020-12-21 14:38:31 +01:00
Omar Polo dd3e110a70
reorder & fmt 2020-12-20 20:03:55 +01:00
Omar Polo d7802bb44a
logging reworked and daemonize by default
The -l option was removed: now it logs on syslog if -f (foreground) is
not passed.
2020-12-02 21:18:01 +01:00
Omar Polo 677afbd3f8
clients certs support for CGI
internally, gmid doesn’t care if the client issued a certificate, but
now we pass that information to the CGI script in some new environment
variables.
2020-12-02 15:17:19 +01:00
Omar Polo c603f1260d
fix bug introduced in last version regarding full URLs
gemini://example.com was incorrectly parsed.
2020-11-18 09:45:28 +01:00
Omar Polo dd3895586f
mention the bugfix and tag 1.3.1 2020-11-18 09:36:18 +01:00
Omar Polo 7cd6880b84
correctly handle also non absolute URLs 2020-11-18 09:34:42 +01:00
Omar Polo ae2ad03ec0
handle //example.com urls 2020-11-18 09:32:07 +01:00
Omar Polo 721e232529
make port number configurable 2020-11-18 09:12:27 +01:00
Omar Polo d431188c66
fixed changelog format for old entries 2020-11-10 18:14:07 +01:00
Omar Polo a5d310bc0d
[cgi] added support for path parameters
enhance the CGI scripting support so that script can take path
parameters.  That is, a script at /cgi/foo is called when the request
path is /cgi/foo/bar/...

This commit also introduce some backward incompatible changes as the
default env variables set for the CGI script changed.
2020-11-10 14:07:36 +01:00