Commit Graph

39 Commits

Author SHA1 Message Date
Omar Polo 6084a9a5ba prefer sizeof(x) instead of datalen 2022-03-27 12:52:58 +00:00
Omar Polo 72b033ef18 add ability to proxy requests
Add to gmid the ability to forwad a request to another gemini server and
thus acting like a reverse proxy.  The current syntax for the config
file is

	server "example.com" {
		...
		proxy relay-to host:port
	}

Further options (like the use of custom certificates) are planned.

cf. github issue #7
2021-12-29 20:36:54 +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 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 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 2e2e189b01 PF_UNIX is not a valid protocol for socketpair
OpenBSD accept it, but FreeBSD disallows it.  PF_UNSPEC (or 0) should
be used instead.  The FastCGI bit in the regress suite still doesn't
work on FreeBSD, but at least now it starts.
2021-07-08 10:09:24 +00:00
Omar Polo e7c6502bf3 don't leak a file descriptor
make sure we always close every fd in every possible code path; while
there, also add a log_err if fork(2) failed.
2021-07-08 09:40:23 +00:00
Omar Polo ea976e8743 don't let CGI scripts inherit our stderr
our stderr could have been sent to the logger process, so it may be
invalid.  Furthermore, in the future we may want to capture also the
stderr of the processes.
2021-07-06 10:48:59 +00:00
Omar Polo ce2c9edbc2 define and use GMID_VERSION 2021-05-15 11:11:56 +00:00
Omar Polo 1feaf2a618 use the correct document root
pass the correct loc_off to the executor, so the various variables
that depends on the matched location (like DOCUMENT_ROOT) are computed
correctly.
2021-05-15 10:31:43 +00:00
Omar Polo 8ad1c57024 fastcgi: a first implementation
Not production-ready yet, but it's a start.

This adds a third ``backend'' for gmid: until now there it served
local files or CGI scripts, now FastCGI applications too.

FastCGI is meant to be an improvement over CGI: instead of exec'ing a
script for every request, it allows to open a single connection to an
``application'' and send the requests/receive the responses over that
socket using a simple binary protocol.

At the moment gmid supports three different methods of opening a
fastcgi connection:

 - local unix sockets, with: fastcgi "/path/to/sock"
 - network sockets, with: fastcgi tcp "host" [port]
   port defaults to 9000 and can be either a string or a number
 - subprocess, with: fastcgi spawn "/path/to/program"
   the fastcgi protocol is done over the executed program stdin

of these, the last is only for testing and may be removed in the
future.

P.S.: the fastcgi rule is per-location of course :)
2021-05-09 18:23:36 +00:00
Omar Polo fdea6aa0bc allow ``root'' rule to be specified per-location block 2021-04-30 17:16:34 +00:00
Omar Polo 9cc630aa63 added ``env'' option to define environment vars for CGI scripts 2021-04-28 12:43:17 +00:00
Omar Polo 3841a36930 restore signal handlers before exec'ing CGI scripts 2021-04-20 09:53:03 +00:00
Omar Polo 89541eeec0 define TLS_VERSION, TLS_CIPHER and TLS_CIPHER_STRENGTH for CGI scripts 2021-04-13 06:59:54 +00:00
Omar Polo b8e64ccd44 list instead of fixed-size array for vhosts and locations
saves some bytes of memory and removes the limit on the maximum number
of vhosts and location blocks.
2021-03-31 16:32:18 +00:00
Omar Polo c8249bada3 gmid v1.6 -- "Stargazers" 2021-03-20 12:04:23 +00:00
Omar Polo 62e001b067 move all sandbox-related code to sandbox.c
while there, add capsicum for the logger process
2021-03-20 08:42:08 +00:00
Omar Polo bc99d868bc refactoring: imsg everywhere
use imsg to handle ALL kinds of IPC in gmid.  This simplifies and shorten the
code, and  makes everything more uniform too.
2021-03-19 19:21:29 +00:00
Omar Polo 1fbac5ba7c handle SIGHUP gracefully
i.e. don't print scary messages with LOG_CRIT priority!
2021-03-03 17:52:13 +00:00
Omar Polo 2c3e53dac6 give each server process its own socket for the executor
this fixes a bug introduced with the prefork mechanics: every server
process shared the same socket, and this would cause a race condition
when multiple server processes asked for a script cgi being executed.

This gives each server process its own socket to talk to the executor,
so the race cannot happen.
2021-03-03 17:22:01 +00:00
Omar Polo 52418c8d82 fix various compilation errors
Include gmid.h as first header in every file, as it then includes
config.h (that defines _GNU_SOURCE for instance).

Fix also a warning about unsigned vs signed const char pointers in
openssl.
2021-02-12 12:47:20 +00:00
Omar Polo b63e30ff44 define TLS_CLIENT_NOT_BEFORE/NOT_AFTER in CGI scripts 2021-02-07 21:47:01 +00:00
Omar Polo 9f006a2127 [cgi] split the query in words if needed and add them to the argv 2021-02-07 18:55:04 +00:00
Omar Polo a64959c99a use log_err instead of fprintf 2021-02-07 16:09:49 +00:00
Omar Polo 52053e1a61 ensure CGI stdout it's blocking 2021-02-06 09:56:34 +00:00
Omar Polo ca21e10043 reload configuration on SIGHUP 2021-02-04 13:23:15 +00:00
Omar Polo 4e2e2ab1d3 refactor executor_main
now it's symmetrical to listener_main().
2021-02-03 16:37:53 +00:00
Omar Polo 3e5418099f [cgi] always set some variables 2021-02-01 13:48:23 +00:00
Omar Polo 67528c1f82 don't add the query to argv
FRC3875 says that if the query does not contain any unecnoded "="
characters, we SHOULD treat the query string as a "search-string",
split in on "+" and add every word to the CGI argv.

In launch_cgi it's too late because iri->query is the *decoded* query!

I have in mind some refactoring around how we decode things, so this
is postponed.
2021-02-01 12:28:30 +00:00
Omar Polo 2fafa2d23e bring the CGI implementation in par with GLV-1.12556 2021-02-01 11:11:43 +00:00
Omar Polo 7808978667 fix computed offset
Oh my, this is such a stupid mistake.  It went undiscovered only
because I always used CGI scripts on the first vhost (and hence the
offset would be 0) and never on the others.
2021-02-01 08:38:48 +00:00
Omar Polo 1078229283 unveil x the vhosts directories 2021-01-25 15:02:55 +00:00
Omar Polo 28ec617809 sync the CGI environment with the manpage
while there also add SERVER_PROTOCOL
2021-01-24 10:06:48 +00:00
Omar Polo 0baf6bed2a pass the fd, not the path! 2021-01-24 09:53:54 +00:00
Omar Polo 05748e49fe chdir to the vhost root before exec'ing the CGI script 2021-01-24 09:15:05 +00:00
Omar Polo 710a71b2bb don't leak file descriptors 2021-01-19 18:16:09 +00:00
Omar Polo 568a09c220 fix requri construction
when we switched from one process to two, I introduced a small
optimisation: empty string are not send, so we receive NULL.
Constructing requri we need to make sure that relpath is not null.
2021-01-18 15:25:49 +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