|
|
|
|
@ -317,6 +317,12 @@ static struct store_upload* store_upload_find(struct mf_storage* s, uint64_t gro
|
|
|
|
|
|
|
|
|
|
static int store_begin(struct mf_storage* s, uint64_t group, uint64_t peer, const char* path, const struct mf_message* q) { |
|
|
|
|
if (q->size > INT64_MAX || mf_zero(q->upload, 16)) return MF_INVALID_RANGE; |
|
|
|
|
if (!strncmp(q->path, "avatars/", 8)) { |
|
|
|
|
if (!mf_avatar_file_valid(q->path + 8) || !q->size || q->size > MF_AVATAR_MAX_BYTES) return MF_INVALID_RANGE; |
|
|
|
|
if (!mf_zero(q->version, 16)) return MF_EXISTS; |
|
|
|
|
char hash[65]; for (unsigned i = 0; i < 32; i++) snprintf(hash + i * 2, 3, "%02x", q->hash[i]); |
|
|
|
|
if (strncmp(q->path + 8, hash, 64)) return MF_HASH_MISMATCH; |
|
|
|
|
} |
|
|
|
|
struct store_upload* u = store_upload_find(s, group, peer, q->upload); |
|
|
|
|
if (u) { |
|
|
|
|
if (strcmp(u->path, path) || u->size != q->size || memcmp(u->hash, q->hash, 32) || memcmp(u->expected, q->version, 16)) |
|
|
|
|
@ -377,6 +383,8 @@ static int store_begin(struct mf_storage* s, uint64_t group, uint64_t peer, cons
|
|
|
|
|
static int store_command(struct mf_storage* s, uint64_t group, uint64_t peer, const struct mf_message* q, struct mf_message* r) { |
|
|
|
|
if (!mf_path_valid(q->path, q->command == MF_LIST || q->command == MF_STAT || q->command == MF_QUOTA) || |
|
|
|
|
(q->command == MF_RENAME && !mf_path_valid(q->target, 0))) return MF_INVALID_PATH; |
|
|
|
|
if (q->command == MF_RENAME && (!strcmp(q->path, "avatars") || !strncmp(q->path, "avatars/", 8) || |
|
|
|
|
!strcmp(q->target, "avatars") || !strncmp(q->target, "avatars/", 8))) return MF_INVALID_PATH; |
|
|
|
|
char path[MF_PATH_MAX + 80]; |
|
|
|
|
snprintf(path, sizeof(path), "%llu/%llu%s%s", (unsigned long long)group, (unsigned long long)q->owner, *q->path ? "/" : "", q->path); |
|
|
|
|
struct mf_disk_info info = {0}; |
|
|
|
|
|