Commit Graph

938 Commits

Author SHA1 Message Date
Omar Polo 92e66347ed
regen readme 2020-11-06 18:12:57 +01:00
Omar Polo 0ed5656795
documentation improvements 2020-11-06 18:11:45 +01:00
Omar Polo 72f653b652
[cgi] execute cgi scripts only inside a specific directory
change the meaning of the -x flag: now it takes a string and executes
CGI scripts only if they are inside a directory with the given name,
relatively to the document root.
2020-11-06 18:05:44 +01:00
Omar Polo f65ed01841
[cgi] set QUERY_STRING only if there is a query string 2020-11-06 18:02:41 +01:00
Omar Polo 120381c93d
[debug] print number of connected clients on SIGINFO
or SIGUSR2 for poor peoples
2020-11-06 17:09:30 +01:00
Omar Polo aff8d19010
handle CGI concurrently
don’t stop-the-world-until-cgi-end, but rather poll on the script, so
we can handle other requests in the meantime.
2020-11-06 17:09:14 +01:00
Omar Polo 60ba426e7e
[cgi] setenv instead of building an env + define more env variables 2020-11-06 15:07:33 +01:00
Omar Polo 75d233f00c
pass the query parameter to start_cgi 2020-11-06 15:06:50 +01:00
Omar Polo aa0fe0cf24
extract query parameters from the URL 2020-11-06 15:04:16 +01:00
Omar Polo 3c19febb01
ensure the requested protocol is “gemini”
…and not something else that happens to be 6-bytes long.
2020-11-06 14:24:25 +01:00
Omar Polo e8cac16e03
mark every open file as close-on-exec 2020-11-06 14:18:17 +01:00
Omar Polo 72342dc960
implementing CGI – NOT READY YET!
This is a first try at implementing CGI scripting.  The idea is that,
if CGI is explicitly enabled by the user, when a user requires an
executable file instead of serving it to the client, that file will be
executed and its output fed to the client.

There are various pieces that are still lacking, the firsts that comes
to mind are:

 - performance: the handle_cgi just loops ignoring the
   WANT_POLLIN/POLLOUT and blocking if the child process hasn’t
   outputted anything.
 - we don’t parse query variable (yet)
 - we need to set more variables in the child environment
   side question: it’s better to set the variables using setenv() or
   by providing an explicit environment?
 - document what environment the CGI script will get
 - improve the horrible unveil/pledge(cgi ? …)

but now I can serve “hello-world”-tier script from gmid!
2020-11-06 13:01:31 +01:00
Omar Polo 2c3a40faf8
added option to log to a file 2020-11-06 10:58:30 +01:00
Omar Polo 932b001a3f
typo 2020-11-06 10:45:06 +01:00
Omar Polo 20f688381a
doc: point out that we can handle multiple clients concurrently 2020-11-05 17:06:12 +01:00
Omar Polo dd080e1f75
define a MIME type for xml files 2020-11-05 17:05:28 +01:00
Omar Polo 19f68393e6
update the changelog and tag 1.2 2020-11-03 15:51:13 +01:00
Omar Polo 0cf902af62
ignore SIGPIPE
bad clients can shutdown the socket and we will exit due to a SIGPIPE.
it ain’t fun.
2020-11-03 15:48:26 +01:00
Omar Polo 9468027ba7
initial work for ipv6
make_socket can now return an ipv6 socket, and everything else still
works.  ipv4 is still hardcoded tho.
2020-10-15 13:45:57 +02:00
Omar Polo 4f6eb772cb
new release: 1.1 2020-10-14 10:17:27 +02:00
Omar Polo 2b897a2cea
added a changelog file 2020-10-14 10:14:11 +02:00
Omar Polo f28f931139
switching to mmap() based file handling 2020-10-14 10:09:06 +02:00
Omar Polo 9c56b0a78a
style 2020-10-14 10:09:00 +02:00
Omar Polo 10fed44c79
improve make error message if etags is not found
the ‘|| true’ idiom leads to better make error.  Now the ‘-’ becomes a
bit redundant tho…
2020-10-07 17:59:55 +02:00
Omar Polo 09a1b97896
put back the missing lseek, and change variables name
(I know, changing variables names AND introducing changes is better
done in more commits, but…)

Added back an lseek that was missing.  If TLS_WANT_POLL{IN,OUT}, we
need to re-send that block, but we need also to rewind the file, in
order to read(2) that chunk again.  This doesn’t solve the corruption
in transferring big files, but reduces them.  I still haven’t tracked
down the corruption :/
2020-10-07 17:59:31 +02:00
Omar Polo cc68fe70fc
added support for mime types (by looking at file extension)
At the moment there is an hardcoded table that maps mime types to
extensions.  For the time being this can be OK, as I don’t even
currently serve all those types of file, but in the future I’d like to
let user pass a file with the mapping, like /usr/share/misc/mime.types
on OpenBSD, to map.  However, even in this case, we should hardcode
text/gemini IMHO, since most mime.types listing doesn’t have it yet.
2020-10-07 14:41:32 +02:00
Omar Polo 592fd62453
rewrote the main loop to use poll
We can handle up to MAX_USERS (64 by default) concurrently.

Now, given that we don’t support CGI, it’s not a big deal.  Gemini
requests are small (up to 1024 bytes), and also the replies from the
server are small (one line plus the document — if any), all over TLS
obviously. (but even there, it’s lighter than HTTP because we don’t
need to send the whole chain for the certificate — see TOFU).

Given all the above, this doesn’t really improve the performance in
the real world, but it’s nice to have.  The main use case for this is
to disallow slow clients to stop fast clients.
2020-10-07 14:41:17 +02:00
Omar Polo d95b77a092
fmt 2020-10-07 13:56:41 +02:00
Omar Polo 67328d238c
correct the ../ removal function
was copying BEFORE and not AFTER the ../.
2020-10-03 18:25:53 +02:00
Omar Polo 4d4f0e19ac
improving style: no functional changes 2020-10-03 18:25:31 +02:00
Omar Polo fab952e1d7
minor documentation edits 2020-10-03 17:49:09 +02:00
Omar Polo 30bc2ea9f4
extend installation notes 2020-10-03 14:13:55 +02:00
Omar Polo b55de91633
remame sendfile to send_file and senddir to send_dir
apparently, on some systems there is a sendfile(2), so to avoid a name
clash we rename it to send_file and send_dir.
2020-10-03 12:43:34 +02:00
Omar Polo 0d8ca45a28
explicitly require TLS 1.2 or 1.3
it's the default, but just in case (since gemini spec explicitly talks
about 1.3 as "default" and 1.2 for ease of implementation)
2020-10-03 12:24:14 +02:00
Omar Polo 3e45af4d4f
added license 2020-10-02 19:54:59 +02:00
Omar Polo 4984f974cd
fixed quoting in Makefile 2020-10-02 19:46:46 +02:00
Omar Polo 6980aad6d7
fix errors in manpage
man -Tlint -l gmid.1

helped a lot
2020-10-02 19:44:32 +02:00
Omar Polo 3e4749f7f9
initial commit 2020-10-02 19:39:00 +02:00