Commit graph

89 commits

Author SHA1 Message Date
sin
7a587cfa36 Simplify config.mk
A separate INCS/LIBS is not really necessary here and confuses
the common case.
2014-12-01 18:18:58 +01:00
sin
5b089b98a6 Undef MIN() because it screams on OpenBSD 2014-12-01 17:36:45 +01:00
sin
2a83d925d7 Only set SO_REUSEADDR on the listening fd 2014-12-01 17:36:34 +01:00
Hiltjo Posthuma
b017f90846 bind: re-use address, setsockopt SO_REUSEADDR 2014-11-30 23:35:59 +01:00
Hiltjo Posthuma
70359ae2e9 config: add some more common mime-types 2014-11-30 23:35:48 +01:00
Hiltjo Posthuma
192f44046c code-style fixes 2014-11-30 23:35:37 +01:00
Ivan Delalande
e42bb27846 change the behavior of docroot
Change the behavior of docroot, which is now used as a prefix path for
all file operations related to static files. And add chrootdir, which is
just the old docroot behavior and allows to control the path into which
quark will chroot.

Not having properly distinct configuration variables for chroot,
document root and CGI root was specially annoying since commit 2822488
which allowed users to retrieve the CGI script or binary by just
guessing its path, since quark was chrooting into docroot before
anything else, and thus the CGI script/binary was in the user accessible
path.

This is implemented by moving the reqbuf buffer in the middle of a
bigger buffer, reqpath. That buffer contains the value of docroot at its
beginning and reqbuf simply points to the first byte after this value.
2014-11-30 23:35:10 +01:00
FRIGN
4674ccde50 Revert "request: ignore empty request in log"
This reverts commit 68f51ac37a.

The idea is good, but we just didn't yet get the right format
for the reading-cycle, which effectively keeps offset at 0
when it's all done in one read.

Let's call it a day and get back to the drawing-boards
tomorrow.
2014-08-25 00:59:57 +02:00
FRIGN
a86c7f10e3 Revert "always null-terminate reqbuf buffer"
This reverts commit 73d8b456eb.
2014-08-25 00:53:10 +02:00
Hiltjo Posthuma
68f51ac37a request: ignore empty request in log 2014-08-25 00:34:24 +02:00
FRIGN
73d8b456eb always null-terminate reqbuf buffer
thanks Hiltjo for the patch
2014-08-25 00:33:00 +02:00
sin
29c8cfa201 Rename fd to listenfd for readability
Avoid confusion in functions that use 'fd' and shadow the
global fd.
2014-08-22 11:55:36 +02:00
sin
de74d9b8fe Set up process limits and socket timeouts
(Until we have non-blocking sockets + poll())
2014-08-22 11:55:33 +02:00
sin
4f18d89f22 No need to do a socket release here
1s is too hardcore and impacts performance.
2014-08-22 11:55:26 +02:00
sin
293eb4489d Fix off-by-one 2014-08-22 11:55:22 +02:00
FRIGN
5dac8de322 Allow dir-listing to be a configurable option 2014-08-20 20:47:29 +02:00
FRIGN
ca2c107f30 Remove whitespace from manual 2014-08-20 20:44:13 +02:00
Hiltjo Posthuma
c00949d37d quark.1: add manpage
quark.c: alphabeticly sort options, like in the manpage.
Makefile: add manpage rule to Makefile and fix make dist.
2014-08-20 20:42:58 +02:00
Hiltjo Posthuma
43c4400a77 update README 2014-08-20 20:42:54 +02:00
Hiltjo Posthuma
9fd46fd50e read header until \r\n\r\n or \n\n 2014-08-20 20:42:50 +02:00
Hiltjo Posthuma
19fbedc39a add option -l to enable dirlisting, now disabled by default...
... alphasort direntries using scandir().
2014-08-20 20:42:46 +02:00
Hiltjo Posthuma
fa113f8b47 cgi: parse Status: header
CGI applications can specify a HTTP status to output with the Status:
header. For simplicity the CGI application must use this header on the
first line. With this change cloning git repositories over HTTP with
cgit works.

in config.mk specify _GNU_SOURCE and _POSIX_C_SOURCE instead of
_GNU_SOURCE, this is for getline().
2014-08-20 12:58:10 +02:00
FRIGN
8b6bdd39ff Remove "@strip $@" from the Makefile
LDFLAGS -s already strips.
Thanks, Hiltjo!
2014-08-16 22:05:43 +02:00
sin
7ecf520b30 Fix potentially uninitialized vars 2014-08-16 12:09:00 +02:00
sin
df8437d4f6 Do not indent switch cases
There's only one way to format switch statements.

http://cm.bell-labs.com/cm/cs/who/dmr/ctut.pdf - page 16
2014-08-15 19:51:44 +02:00
Hiltjo Posthuma
2822488312 improve CGI support
- set some more environment variables (PATH_INFO for example is used by
  cgit). Also set REMOTE_ADDR, SERVER_PORT, SERVER_SOFTWARE.
- when a file is requested in cgi mode serve it, if it doesn't exist,
  pass it to the CGI script (needed for cgit image/CSS).
2014-08-14 17:57:03 +02:00
Hiltjo Posthuma
159cdb3e0b small style and CGI message fix 2014-08-14 17:51:32 +02:00
FRIGN
bd9d7e3493 Fortify the sanity-checks
Hiltjo made a good start, but we need to check both the pointers
and the first value to make sure that a NULL-pointer is not
passed to the functions.
2014-08-14 17:48:37 +02:00
Hiltjo Posthuma
8aa3e3f48f config: allow to set options as application arguments 2014-08-14 17:43:46 +02:00
FRIGN
3962978bdd Increase clarity of the len-check 2014-08-14 14:18:40 +02:00
FRIGN
67750f916f check for len(reqbuf) = 0
Probably never the case, but we want to cleanly catch this error
instead of bringing up a segfault with reqbuf[-1].
2014-08-14 13:58:36 +02:00
FRIGN
72d02aa5b1 Ignore EPIPE while writing file to socket
If the client decides not to listen, it's not that much of a problem.
Don't flood the logs with "Broken pipe"-messages by silently letting
this "error" pass.
2014-08-14 13:14:08 +02:00
sin
8fdfa36914 Ignore SIGPIPE
If there's no reading end (client closed connection) and quark
tries to write to the socket, it will get a SIGPIPE.  Just ignore it.
2014-08-14 09:57:03 +02:00
sin
5d20e3dc27 No need for MAXBUFLEN+1
Return -1 if writedata() fails.
2014-08-14 09:56:23 +02:00
sin
21ec61991f Ensure mod is properly initialized
Fixes a segfault.
2014-08-14 09:54:37 +02:00
FRIGN
a1fa707eec Fix streaming errors
Streaming a file (through mplayer for instance), the socket would
block, because mplayer fills its buffer sequentially.
We would've never gotten to a write(.., n) == n.

Instead, do it like we read from files and accept the fact clients
can accept data chunk-wise, too.

The reason why this error went unnoticed is that I added a faulty
printf-directive (%ls for ssize_t), which silently produced
no output.
Thanks to sin for fixing the %ls -> %zd error, as it made me look
at the code again.
2014-08-14 09:47:23 +02:00
FRIGN
a0a2b864a6 Don't let r be uninitialized
Restore the functionality before the do-while-loop was removed.
2014-08-13 21:05:53 +02:00
FRIGN
411705dfc0 set host[0] = 0 at the beginning for more safety 2014-08-13 19:37:36 +02:00
FRIGN
8001703f50 Fortify error-cases
We don't want to play with our luck here.
2014-08-12 19:17:19 +02:00
FRIGN
390b5855f5 Streamline the code 2014-08-12 10:34:06 +02:00
FRIGN
ef51cd3355 HTTP 401 -> 403
When the client requests a hidden file, we forbid access.
401 is mostly used when a login is required and hasn't been provided.
Thus, given we don't offer a login-prompt to access hidden and bogus
files but categorically reject them, 403 makes more sense here.
2014-08-11 16:59:27 +02:00
FRIGN
9e2662c5e9 Get rid of getnameinfo and use inet_ntop instead
Compiling quark against musl slowed down request-times considerably.
After further analysis, I found out that the library does a DNS-
request on each address passed to getnameinfo.
Given we chroot into a folder, the /etc/resolv.conf was missing,
which led to the really long response-times (~3-5s).
After hardlinking the /etc/resolv.conf inside the chroot, the
times dropped to ~200ms, as now the library knew which NS to
contact directly.

This obviously isn't fast enough.

Thanks to Hiltjo's useful tips I rewrote the section using
inet_ntop (POSIX 2001).
Now the response-times are back to 1-2ms and we don't need
to copy /etc/resolv.conf everywhere we go.

FYI: This is not a bug in musl, but rather different behaviour.
2014-08-11 16:16:37 +02:00
FRIGN
55912e14bf Change tstamp() to allow passing time_t
then use this to remove duplicate code in the last-modified-section.
2014-08-11 15:37:45 +02:00
FRIGN
54a95cd229 Rectify error-handling 2014-08-11 15:23:48 +02:00
FRIGN
00e2aa8da6 Change HTTP-status-codes to defines
Doesn't change binary-size, but allows using them inside the
error-page-generation-routines.
2014-08-11 13:48:37 +02:00
FRIGN
d5af6424f1 Reordering function-prototypes and functions and size_t-correctness 2014-08-11 13:29:29 +02:00
FRIGN
b00fc1454f Add strftime to modified-date-check 2014-08-11 13:12:53 +02:00
FRIGN
5c7155255c Use gmtime() instead of localtime()
%Z is a GNU extension, so we avoid it here by these means.

Thanks Hiltjo!
2014-08-09 22:33:11 +02:00
FRIGN
34b584e2cb Fix mime-handling with default mime
Now it should work. It doesn't make much sense to tweak the default
mime-type, given octet-stream is the default and there are
no real alternatives which would make sense.

Thanks Hiltjo and sin!
2014-08-09 22:29:08 +02:00
FRIGN
dc82dd9705 Fix mime-check
For "" to actually go through, strcmp should only check for the length
of the extension string.
2014-08-09 21:42:31 +02:00