Commit Graph

180 Commits

Author SHA1 Message Date
Xavier Del Campo Romero 7176bd3c94
Call page_forbidden on invalid auth 2023-03-08 18:48:58 +01:00
Xavier Del Campo Romero e37a0248e8
Remove(3) f->tmpname from ctx_free
Until now, f->tmpname was removed by move_file when the move
operation succeeded. However, since a HTTP operation can fail before
move_file is called, the temporary file must also be removed.
2023-03-08 18:17:32 +01:00
Xavier Del Campo Romero 6cbab96869
Update dynstr 2023-03-08 01:22:51 +01:00
Xavier Del Campo Romero 5e100ff3c1
server.c: Fix wrong size for memcpy(3) 2023-03-08 01:17:34 +01:00
Xavier Del Campo Romero 76664d2006
main.c: Avoid leaking forms 2023-03-08 00:38:03 +01:00
Xavier Del Campo Romero 4e1a0484e5
main.c: Print error message only on errno != EEXIST 2023-03-08 00:37:28 +01:00
Xavier Del Campo Romero 0471658177
page.c: Show units for user quota 2023-03-08 00:33:55 +01:00
Xavier Del Campo Romero ba612d6621
page.c: Sort elements alphabetically 2023-03-08 00:33:20 +01:00
Xavier Del Campo Romero ee75d8e3e5
html.c: Allow empty strings on html_encode 2023-03-08 00:26:31 +01:00
Xavier Del Campo Romero 0954abcf09
server.c: Minor const-correctness improvement 2023-03-07 12:41:03 +01:00
Xavier Del Campo Romero 0ca8ea19bc
main.c: Replace + with whitespace for directories 2023-03-07 12:40:30 +01:00
Xavier Del Campo Romero 42c23ec1a5
main.c: Fix memory leak if append_form fails 2023-03-07 12:38:59 +01:00
Xavier Del Campo Romero bd3d2aabc3
main.c: Simplify code a bit 2023-03-07 12:38:32 +01:00
Xavier Del Campo Romero f33e1c9053
cftw.c: Add missing call to closedir(2) 2023-03-07 12:36:27 +01:00
Xavier Del Campo Romero 61dc4f42b3
Perform some minor optimizations 2023-03-06 05:51:53 +01:00
Xavier Del Campo Romero ff8da797a1
Implement user quota
This feature allows admins to set a specific quota for each user, in
MiB. This feature is particularly useful for shared instances, where
unlimited user storage might be unfeasible or even dangerous for the
server.

Also, a nice HTML5 <progress> element has been added to the site that
shows how much of the quota has been consumed.

If no quota is set, slcl falls back to the default behaviour i.e.,
assume unlimited storage.

Limitations:

- While HTTP does specify a Content-Length, which determines the length
of the whole request, it does not specify how many files are involved
or their individual sizes.
- Because of this, if multiple files are uploaded simultaneously, the
whole request would be dropped if user quota is exceeded, even if not
all files exceeded it.
- Also, Content-Length adds the length of some HTTP boilerplate
(e.g.: boundaries), but slcl must rely on this before accepting the
whole request. In other words, this means some requests might be
rejected by slcl because of the extra bytes caused by such boilerplate.
- When the quota is exceeded, slcl must close the connection so that
the rest of the transfer is cancelled. Unfortunately, this means no
HTML can be sent back to the customer to inform about the situation.
2023-03-06 05:51:49 +01:00
Xavier Del Campo Romero 804b8841f3
Add cftw
POSIX functions ftw(3) and nftw(3) do not allow passing an opaque
pointer to the callback they call, so it forces the use of statically
allocated data.

ctfw (from "custom ftw") is a custom implementation that solves this,
while also removing unneeded stuff.

This function will be used by future commits.
2023-03-06 05:06:30 +01:00
Xavier Del Campo Romero 3e95727e27
README.md: Fix broken link to usergen 2023-03-06 02:27:38 +01:00
Xavier Del Campo Romero 4cd577afa9
Perform some minor optimizations 2023-03-06 00:59:07 +01:00
Xavier Del Campo Romero 8bc191d08a
main.c: Simplify failed login response
- Location seems to have no effect on 401 HTTP responses.
- Content-Type is already set by page_failed_login.
2023-03-06 00:56:48 +01:00
Xavier Del Campo Romero 8319dfe58b
http.c: Compare headers as case-insensitive
Web browsers such as lynx send "Content-length" instead of
"Content-Length" (as done by LibreWolf and Chromium).
2023-03-04 04:04:09 +01:00
Xavier Del Campo Romero fff6ed4e0a
http.c: Use persistent cookies
Cookies without "Expires" are considered non-persistent and thus can be
removed by the web browser. Instead, slcl now sets persistent cookies
that last for 1 year.
2023-03-04 04:02:14 +01:00
Xavier Del Campo Romero c033b3006c
http.c: Improve error detection for strotull(3)
set_length relies on user input to determine Content-Length, so it
should be considered unreliable.
2023-03-04 03:03:22 +01:00
Xavier Del Campo Romero 62bdf9f72f
Fix memory leak on failed realloc(3)
According to C99 §7.20.3.4:

If memory for the new object cannot be allocated, the old object is not
deallocated and its value is unchanged.

Therefore, a temporary pointer must be used to ensure the original
object can still be deallocated should realloc(3) return a null pointer.
2023-03-04 03:03:15 +01:00
Xavier Del Campo Romero d83e8ad1ba
Add man page 2023-02-28 01:43:59 +01:00
Xavier Del Campo Romero 08a38aea94
Add usergen
This script takes a username and password from standard input and
generates a JSON object that can be appended to the "users" object in
db.json.
2023-02-28 01:43:59 +01:00
Xavier Del Campo Romero 1b990951f5
Add Makefile 2023-02-28 01:43:59 +01:00
Xavier Del Campo Romero 1b2aff6c5a
Add .gitignore 2023-02-28 01:43:59 +01:00
Xavier Del Campo Romero 9be793e62d
Import dynstr 2023-02-28 01:43:59 +01:00
Xavier Del Campo Romero d26f046fc9
Initial commit 2023-02-28 01:43:56 +01:00