From fcef3b99b86312aaeb9e1cae88179abbfda90dff Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 9 Sep 2023 00:47:14 +0200 Subject: Check directory on uploads For historical reasons, slweb used to check for a name called "dir" on multipart/form-data POST requests. However, stricly speaking this is application logic, so it has been now moved from slweb to slcl. This has resulted in a couple of breaking changes in slweb that had to be updated on slcl. --- main.c | 19 ++++++++++++++++--- slweb | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 16d1878..48c6617 100644 --- a/main.c +++ b/main.c @@ -1139,12 +1139,25 @@ end: return ret; } +static const char *get_upload_dir(const struct http_post *const po) +{ + for (size_t i = 0; i < po->npairs; i++) + { + const struct http_post_pair *p = &po->pairs[i]; + + if (!strcmp(p->name, "dir")) + return p->value; + } + + return NULL; +} + static int upload_files(const struct http_payload *const p, struct http_response *const r, const struct auth *const a) { const struct http_post *const po = &p->u.post; const char *const root = auth_dir(a), *const user = p->cookie.field, - *const dir = po->dir; + *const dir = get_upload_dir(po); if (!po->files) { @@ -1181,9 +1194,9 @@ static int upload_files(const struct http_payload *const p, return page_bad_request(r); } - for (size_t i = 0; i < po->n; i++) + for (size_t i = 0; i < po->nfiles; i++) { - if (upload_file(&po->files[i], user, root, po->dir)) + if (upload_file(&po->files[i], user, root, dir)) { fprintf(stderr, "%s: upload_file failed\n", __func__); return -1; diff --git a/slweb b/slweb index 6c7faa7..34d7160 160000 --- a/slweb +++ b/slweb @@ -1 +1 @@ -Subproject commit 6c7faa7f9063aca15345c9aeb95d651a5fe983f9 +Subproject commit 34d716082a0136056373f3d0c6ed7abce45484b3 -- cgit v1.2.3