From: Marco Bettini Date: Tue, 28 Feb 2023 12:05:44 +0000 (+0000) Subject: dbox: dbox_cleanup_temp_files() - Fuzz scan interval adding 0..+30% based on username... X-Git-Tag: 2.3.21~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b67507e97c3ccc38e3f5dbe72ddf80d3d2c3174;p=thirdparty%2Fdovecot%2Fcore.git dbox: dbox_cleanup_temp_files() - Fuzz scan interval adding 0..+30% based on username hash --- diff --git a/src/lib-storage/index/dbox-common/dbox-storage.c b/src/lib-storage/index/dbox-common/dbox-storage.c index dc9a99efd2..fccf4a2648 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.c +++ b/src/lib-storage/index/dbox-common/dbox-storage.c @@ -1,6 +1,7 @@ /* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "crc32.h" #include "path-util.h" #include "ioloop.h" #include "fs-api.h" @@ -171,19 +172,32 @@ void dbox_notify_changes(struct mailbox *box) } } +static time_t cleanup_interval(struct mailbox_list *list) +{ + time_t interval = list->mail_set->mail_temp_scan_interval; + + const char *username = list->ns->storage->user->username; + /* No need for a cryptographic-quality hash here. */ + unsigned int hash = crc32_str(username); + + /* spread from 0.00 to to 30.00% more than the base interval */ + unsigned int spread_factor = 100000 + hash % 30001; + return (interval * spread_factor) / 100000; +} + static bool dbox_cleanup_temp_files(struct mailbox_list *list, const char *path, time_t last_scan_time, time_t last_change_time) { - unsigned int interval = list->mail_set->mail_temp_scan_interval; - /* check once in a while if there are temp files to clean up */ + time_t interval = cleanup_interval(list); if (interval == 0) { /* disabled */ return FALSE; } - if (last_scan_time >= ioloop_time - (time_t)interval) { + time_t deadline = ioloop_time - interval; + if (last_scan_time >= deadline) { /* not the time to scan it yet */ return FALSE; }