Commit Graph

20 Commits

Author SHA1 Message Date
Xavier Del Campo Romero b3ef22ac2a
Define _POSIX_C_SOURCE
This allows using the default compiler defined by make(1) (i.e.,
c99(1)), thus improving POSIX compatibility.
2023-03-24 02:49:11 +01:00
Xavier Del Campo Romero d9bb874591
Send response on quota exceeded
So far, slcl would just close the connection with a client when the
Content-Length of an incoming request exceeded the user quota, without
any meaningful information given back to the user.

Now, slcl responds with a HTML file with meaningful information about
the error.

Limitations:

- While this commits has been successfully tested on ungoogled-chromium,
LibreWolf (and I assume Firefox and any other derivates too) does not
seem to receive the response from the server.
    - However, this issue only occurred during local testing, but not
on remote instances.
2023-03-20 10:57:20 +01:00
Xavier Del Campo Romero 66bc98275f
main.c: Fix double free(3) and refactor form handling
- When a non-empty username and an empty password was given, slcl would
crash due to a double free(3). This happened because append_form would
grow the form list before sanitizing the input and, since the output
pointer was not updated to the caller function, the latter would attempt
to free a now-old pointer.
- Additionally, some compilers such as clang complained about the
potential use of an uninitialized variable when calling forms_free.
- Also, it was a good opportunity to refactor get_forms and its caller
functions, as get_forms was not differentiate fatal errors from user
input errors.
2023-03-19 23:58:03 +01:00
Xavier Del Campo Romero 9624e81144
main.c: Fix undefined value for cur
As otherwise reported by clang 14.0.0:

main.c:679:14: warning: variable 'cur' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
    else if (available && quota_current(a, username, &cur))

This was a minor issue after all, as pq was not used unless available
were set.
2023-03-16 02:23:05 +01:00
Xavier Del Campo Romero 7e2e37d40a
main.c: Ensure essential directories on startup
So far, slcl failed with poorly described error messages when any of the
essential directories were missing. Now, these are created automatically
so that the initial setup is easier.
2023-03-16 01:46:49 +01:00
Xavier Del Campo Romero d18243c019
main.c: Call form_free instead of repeating code 2023-03-09 02:04:52 +01:00
Xavier Del Campo Romero 2e1b131396
Implement public file sharing
An HTML form is now added next to each regular file, that generates a
POST request. Then, slcl replies with a HTML document with a link to the
public resource (which are implemented as symlinks).

Limitations:

- For now, only regular files can be shared i.e., sharing directories is
not possible. While feasible, it still requires a larger refactor to
list_dir and resource_layout, so that read-only access to the directory
is provided to anonymous users.
2023-03-09 02:02:40 +01:00
Xavier Del Campo Romero a4c12e7ccc
Translate whitespace to '+' in append_form
Otherwise, every function calling get_forms must implement this.
2023-03-09 01:17:37 +01:00
Xavier Del Campo Romero f4c16b8e56
main.c: Always append trailing slash to directories
Otherwise, slcl would fail to generate the URLs for the elements inside
a directory, because of how cust_dirname worked, which also turned out
to be redundant.
2023-03-08 18:50:15 +01:00
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 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 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 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 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 d26f046fc9
Initial commit 2023-02-28 01:43:56 +01:00