mirror of https://git.sr.ht/~sircmpwn/gmnisrv synced 2024-07-20 14:24:16 -04:00
Commit Graph

82 Commits

Author SHA1 Message Date
Eyal Sawady
cb042d6263 CGI: Don't hang on directory with no index 2020-11-15 11:33:16 -05:00
Eyal Sawady
0646fd020c CGI: Fix paths which end in '/' 2020-11-15 10:55:48 -05:00
Eyal Sawady
05a71905f9 Fix typo in documentation for $GATEWAY_INTERFACE 2020-11-11 10:30:03 -05:00
Kenny Levinsen
9fd9eef9d7 Fix use of wrong index during pollfd refresh
The right side of the refresh ended up using the index of the deleted
client instead of the index from the loop, which happens to work when
the destroyed client is either last or second-last.
2020-11-10 08:06:37 -05:00
Kenny Levinsen
fdd27bb4c1 Update pollfd pointers when destroying a client
The client pollfd pointer would go stale when the server pollfd array
was moved to compensate for a destroyed client, which in turn led to
poll breakage.

Refresh the pollfd pointers after memmove.
2020-11-08 21:34:34 -05:00
Drew DeVault
74077b6f95 Prevent double free of client resources 2020-11-08 16:37:53 -05:00
Drew DeVault
ea2914efff Set CWD to cgi-bin when executing scripts 2020-11-08 12:16:59 -05:00
Drew DeVault
57f4fcdc41 Fix double free 2020-11-08 12:12:43 -05:00
René Wagner
02a386b568 check if file served as cgi is executable
if not, send a response 50 to the client
fixes ~sircmpwn/gmni#47
2020-11-08 10:59:35 -05:00
c145ac6a65 fix typo in GATEWAY_INTERFACE value 2020-11-08 09:38:52 -05:00
4b2c3afdb0 Set POLLOUT only when there's something to write 2020-11-08 09:38:17 -05:00
William Casarin
ea40fb5a53 tls: fix crash when opening priv key for writing
The open syscall will return a negative value if the call fails. Switch
the check to look for this instead of 0.


[gmnisrv] generating certificate for localhost
gmnisrv: src/tls.c:68: tls_host_gencert: Assertion `pf' failed.
abort (core dumped)  ./gmnisrv -C config.ini


[gmnisrv] generating certificate for localhost
[gmnisrv] opening private key for writing failed: No such file or directory
[gmnisrv] TLS initialization failed

Signed-off-by: William Casarin <jb55@jb55.com>
2020-11-08 09:38:04 -05:00
Tom Lebreux
7aedbed774 Don't memmove one past clients 2020-11-08 09:37:59 -05:00
Tom Lebreux
d20caf389b Fix not moving all fds 2020-11-08 09:37:55 -05:00
Tom Lebreux
4f12abfbc2 Fix memory leaks 2020-11-08 09:37:55 -05:00
William Casarin
d484ba0ab0 config/routing: fix maybe-uninitialized errors
Trivial fix to silence compilation errors on gcc 9.3.0:

  src/config.c: In function ‘conf_ini_handler’:
  src/config.c:154:23: error: ‘routing’ may be used uninitialized in this
  function [-Werror=maybe-uninitialized]
    154 |  enum gmnisrv_routing routing;
        |                       ^~~~~~~

  src/config.c:197:18: error: ‘spec’ may be used uninitialized in this
  function [-Werror=maybe-uninitialized]
    197 |    route->path = strdup(spec);
        |                  ^~~~~~~~~~~~

Signed-off-by: William Casarin <jb55@jb55.com>
2020-11-02 12:29:19 -05:00
Drew DeVault
b45ddd813b Add mailcap to dependencies 2020-11-01 14:24:31 -05:00
Drew DeVault
dc6e4e80c0 Implement URL rewrites with regex capture groups 2020-11-01 11:19:51 -05:00
Drew DeVault
953039e0b1 gmnisrv.ini(5): clarify tokens in route config 2020-11-01 10:34:41 -05:00
Drew DeVault
16e55c6262 Change meaning of root (backwards incompatible!)
This takes the nginx approach to the "root" directive, which is simpler
to implement and more consistent with more complex routing behaviors
like regexp.

The path component of the URL is now simply appended to the root to form
the path to the file which should be served to the client.
2020-11-01 10:32:44 -05:00
Drew DeVault
36e53f1f7f It's actually ECMAScript 2018 compatible 2020-11-01 10:21:45 -05:00
Drew DeVault
0ba984b841 regexp.c: ditch unused test code 2020-11-01 09:51:14 -05:00
Drew DeVault
4b6f5a1c61 Clarify regex details in gmnisrv.ini(5) 2020-11-01 09:48:10 -05:00
Drew DeVault
f15bea6583 Implement regex route matching 2020-11-01 09:43:46 -05:00
Drew DeVault
70fadc21b9 Drop most of the unicode tables 2020-10-29 23:30:49 -04:00
Drew DeVault
7e8a953794 Initial pass on regex routing support
All this does is parse the regexes out of the config file.

I've vendored libregexp from Bellard's quickjs project, because it's
reasonably small and self-contained, and POSIX regexes don't support
captures. We're eventually going to want captures for URL rewrites, so
this'll do for now.
2020-10-29 22:47:56 -04:00
Drew DeVault
a26573251b Fail gracefully if mime database is not present 2020-10-28 12:49:47 -04:00
Drew DeVault
077b96d3cc config: free more routing information on finish 2020-10-28 12:43:05 -04:00
Drew DeVault
becc4460b6 Implement MIME database support 2020-10-28 12:38:32 -04:00
Drew DeVault
ac6145ed6a server: handle write errors 2020-10-28 12:36:05 -04:00
Drew DeVault
da6f7e9f05 CGI: Fix SCRIPT_NAME variable 2020-10-26 18:16:05 -04:00
Drew DeVault
5d725ff4ee CGI: set PATH_INFO 2020-10-25 23:55:42 -04:00
Drew DeVault
cc1bd152e3 Initial support for CGI scripts 2020-10-25 23:16:50 -04:00
Drew DeVault
8baeb5a51c Initial implementation of a routing table 2020-10-25 21:46:01 -04:00
Drew DeVault
1fe107875b Overhaul network I/O to be async for real
Had to totally cut off OpenSSL from the network fd because obviously
OpenSSL is just going to wreck our shit
2020-10-25 14:50:07 -04:00
io mintz
a22bec5149 add a missing "/" to autoindex paths
With the following directory structure:

baz/  foo/




trying to access gemini://somesite/ with autoindex=on works,
but accessing /foo fails because it tries to stat /srv/gmni/foobar
instead of /srv/gmni/foo/bar. This commit fixes that by adding a trailing slash.
2020-10-15 15:44:45 -04:00
William Casarin
e77f354ca3 serve: fix gcc-9.3.0 error in serve_autoindex
gcc 9.3.0 catches an off-by-one error with strncat in serve_autoindex
where it might not write a 0 byte:

  In function ‘strncat’,
      inlined from ‘serve_autoindex’ at src/serve.c:60:3:
  error: ‘__builtin___strncat_chk’ specified bound 4097 equals destination size

Signed-off-by: William Casarin <jb55@jb55.com>
2020-10-15 12:06:19 -04:00
Chris Vittal
9d17ce46b0 return false on request_validate errors
This will report proper errors to clients rather than continuing on with
request processing.
2020-10-12 21:25:45 -04:00
Kevin Sangeelee
cff1f71f1a Change assert to 2-param version to comply with C11. 2020-09-29 18:04:12 -04:00
Drew DeVault
477bf5db81 Bubble up client disconnect state
This will fix the segfaults but won't fix slowlorris
2020-09-27 13:54:19 -04:00
Drew DeVault
a9ee61418f Break after processing polled client
Otherwise we might not grok it, ya jive
2020-09-27 12:11:11 -04:00
Drew DeVault
7fed84898b Only handle one client per poll iteration
This is a bit of a hack but it avoids some problems with invalid reads
when a client gets disconnected
2020-09-27 10:18:52 -04:00
Drew DeVault
1f229ba123 mime: add .xml -> text/xml 2020-09-27 00:46:38 -04:00
Drew DeVault
71bbd1b315 server.c: re-locate definitions to appropriate scope 2020-09-26 18:54:32 -04:00
Drew DeVault
f3075e4bbd README.md: update example config 2020-09-26 18:51:24 -04:00
Drew DeVault
57893ff09c Set SO_REUSEADDR 2020-09-26 18:24:32 -04:00
Drew DeVault
f6602ddd08 server.c: appease GCC's magic pixie bullshit 2020-09-26 18:13:11 -04:00
Drew DeVault
6d866ba3df server.c: import netinet/in.h 2020-09-26 17:54:40 -04:00
Drew DeVault
53bf5bc54f config.ini: change suggested root directory 2020-09-26 17:46:56 -04:00
Drew DeVault
534efe8e34 Fix size of in{,6}_addr 2020-09-26 17:33:13 -04:00