aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-02-12 18:04:48 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2026-02-13 07:55:07 +0100
commit8479f8e7797b4b26230d50bde981ff4e3f520603 (patch)
tree4340475b7be344b05d50890059840210d80d58e3
parentdd1ceb550c13d433cd26191ec3176eca0e2d70a1 (diff)
Bump libweb
libweb has introduced several breaking changes: - Add optional expiration date to http_cookie_create - Replace Makefile with configure script
-rw-r--r--auth.c23
-rwxr-xr-xconfigure9
m---------libweb0
-rw-r--r--main.c21
4 files changed, 41 insertions, 12 deletions
diff --git a/auth.c b/auth.c
index 8ff23fd..08d049c 100644
--- a/auth.c
+++ b/auth.c
@@ -1,3 +1,5 @@
+#define _POSIX_C_SOURCE 200809L
+
#include "auth.h"
#include "crealpath.h"
#include "hex.h"
@@ -13,6 +15,7 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -171,8 +174,24 @@ static int generate_cookie(const char *const name, const char *const key,
unsigned char dkey[KEYLEN];
int ret = -1;
char *jwt = NULL;
+ time_t t = time(NULL);
+
+ if (t == (time_t)-1)
+ {
+ fprintf(stderr, "%s: time(3): %s\n", __func__, strerror(errno));
+ goto end;
+ }
- if (hex_decode(key, dkey, sizeof dkey))
+ t += 365 * 24 * 60 * 60;
+
+ struct tm tm;
+
+ if (!localtime_r(&t, &tm))
+ {
+ fprintf(stderr, "%s: localtime_r(3): %s\n", __func__, strerror(errno));
+ goto end;
+ }
+ else if (hex_decode(key, dkey, sizeof dkey))
{
fprintf(stderr, "%s: hex_decode failed\n", __func__);
goto end;
@@ -182,7 +201,7 @@ static int generate_cookie(const char *const name, const char *const key,
fprintf(stderr, "%s: jwt_encode failed\n", __func__);
goto end;
}
- else if (!(*cookie = http_cookie_create(name, jwt)))
+ else if (!(*cookie = http_cookie_create(name, jwt, &tm)))
{
fprintf(stderr, "%s: http_cookie_create failed\n", __func__);
goto end;
diff --git a/configure b/configure
index 9786004..79dcc1a 100755
--- a/configure
+++ b/configure
@@ -168,9 +168,12 @@ fi
if [ $in_tree_libweb -ne 0 ]
then
cat <<"EOF" >> $F
+LIBWEB_MK = libweb/Makefile
+$(LIBWEB_MK):
+ cd libweb && ./configure --prefix=$(PREFIX)
LIBWEB = libweb/libweb.a
$(PROJECT): $(LIBWEB)
-$(LIBWEB): FORCE
+$(LIBWEB): $(LIBWEB_MK) FORCE
+cd libweb && $(MAKE) CC=$(CC)
EOF
fi
@@ -210,7 +213,7 @@ fi
if [ $in_tree_libweb -ne 0 ]
then
cat <<"EOF" >> $F
- +cd libweb && $(MAKE) clean
+ +test -f $(LIBWEB_MK) && cd libweb && $(MAKE) clean || :
EOF
fi
@@ -232,7 +235,7 @@ EOF
if [ $in_tree_libweb -ne 0 ]
then
cat <<"EOF" >> $F
- +cd libweb && $(MAKE) distclean
+ +test -f $(LIBWEB_MK) && cd libweb && $(MAKE) distclean || :
EOF
fi
diff --git a/libweb b/libweb
-Subproject 953210bd1930e1734f1acde86eadd7a1997bb7c
+Subproject 62ee3ef1ca13872e1f9b07f6e4e53cea8b684d7
diff --git a/main.c b/main.c
index 440dca2..6ad0cf7 100644
--- a/main.c
+++ b/main.c
@@ -837,9 +837,9 @@ static int check_quota(const unsigned long long len,
return q->cur + len > q->max ? 1 : 0;
}
-static int check_length_step(const unsigned long long len,
- const struct http_cookie *const c, struct http_response *const r,
- void *const user, void *const args)
+static int check_length_step(const enum http_op op, const char *const res,
+ const unsigned long long len, const struct http_cookie *const c,
+ struct http_response *const r, void *const user, void *const args)
{
int ret = 0;
struct quota *const q = args;
@@ -867,9 +867,9 @@ failure:
return -1;
}
-static int check_length(const unsigned long long len,
- const struct http_cookie *const c, struct http_response *const r,
- void *const user)
+static int check_length(const enum http_op op, const char *const res,
+ const unsigned long long len, const struct http_cookie *const c,
+ struct http_response *const r, void *const user)
{
struct user_args *const ua = user;
const struct auth *const a = ua->a;
@@ -877,7 +877,14 @@ static int check_length(const unsigned long long len,
bool has_quota;
unsigned long long max;
- if (auth_cookie(a, c))
+ if (op != HTTP_OP_POST || strcmp(res, "/upload"))
+ {
+ if (page_bad_request(r))
+ return -1;
+
+ return 1;
+ }
+ else if (auth_cookie(a, c))
{
fprintf(stderr, "%s: auth_cookie failed\n", __func__);