From 98506d5b3af0e996d1f8644a8200989ffea86ac1 Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Wed, 2 Sep 2020 11:13:55 +0200 Subject: [PATCH] Introduced the consolidated_store variable Signed-off-by: Janos SUTO --- etc/example.conf | 8 ++++++++ src/archive.c | 22 +++++++++++----------- src/cfg.c | 1 + src/cfg.h | 2 ++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/etc/example.conf b/etc/example.conf index c002a15d..853d8b58 100644 --- a/etc/example.conf +++ b/etc/example.conf @@ -34,6 +34,14 @@ default_retention_days=2557 ; which will cause problems. encrypt_messages=1 +; If the previous 3 letter store top directories, eg. /var/piler/store/00/5f4 +; are consolidated (1) to a single zip file or not (0). +; Eg. cd /var/piler/store/00 +; zip -r -0 5f3.zip 5f3 +; After the consolidation (ie. zipping the given directory) piler tries to +; read the given file from the appropriate zip file. +consolidated_store=0 + ; number of worker processes, ie. the number of simultaneous smtp connections to piler. ; This value should be the number of cpus + 1, ie. 2 for a single cpu host number_of_worker_processes=2 diff --git a/src/archive.c b/src/archive.c index 237ae756..45d894d3 100644 --- a/src/archive.c +++ b/src/archive.c @@ -300,12 +300,14 @@ void assemble_filename(char *filename, int len, char *s, struct config *cfg){ char zipfilename[SMALLBUFSIZE]; struct stat st; - /* - * If the zip file exists, then fix the filename to be ' ' - */ snprintf(zipfilename, sizeof(zipfilename)-1, "%s/%02x/%c%c%c.zip", cfg->queuedir, cfg->server_id, s[8], s[9], s[10]); - if(stat(zipfilename, &st)){ + if(cfg->consolidated_store == 1 && stat(zipfilename, &st) == 0){ + // If the zip file exists, then fix the filename to be ' ' + snprintf(filename, len-1, "%s %c%c%c/%c%c/%c%c/%s.m", + zipfilename, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s); + } + else { snprintf(filename, len-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.m", cfg->queuedir, cfg->server_id, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s); #ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT @@ -314,9 +316,6 @@ void assemble_filename(char *filename, int len, char *s, struct config *cfg){ cfg->queuedir, cfg->server_id, s[RND_STR_LEN-6], s[RND_STR_LEN-5], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s); } #endif - } else { - snprintf(filename, len-1, "%s %c%c%c/%c%c/%c%c/%s.m", - zipfilename, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s); } } @@ -327,7 +326,11 @@ void assemble_attachment_filename(char *filename, int len, char *s, int attachme snprintf(zipfilename, sizeof(zipfilename)-1, "%s/%02x/%c%c%c.zip", cfg->queuedir, cfg->server_id, s[8], s[9], s[10]); - if(stat(zipfilename, &st)){ + if(cfg->consolidated_store == 1 && stat(zipfilename, &st) == 0){ + snprintf(filename, len-1, "%s %c%c%c/%c%c/%c%c/%s.a%d", + zipfilename, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s, attachment_id); + } + else { snprintf(filename, len-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, cfg->server_id, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s, attachment_id); #ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT @@ -336,9 +339,6 @@ void assemble_attachment_filename(char *filename, int len, char *s, int attachme cfg->queuedir, cfg->server_id, s[RND_STR_LEN-6], s[RND_STR_LEN-5], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s, attachment_id); } #endif - } else { - snprintf(filename, len-1, "%s %c%c%c/%c%c/%c%c/%s.a%d", - zipfilename, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s, attachment_id); } } diff --git a/src/cfg.c b/src/cfg.c index 0c40b705..8143abff 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -48,6 +48,7 @@ struct _parse_rule config_parse_rules[] = { "clamd_addr", "string", (void*) string_parser, offsetof(struct config, clamd_addr), "", MAXVAL-1}, { "clamd_port", "integer", (void*) int_parser, offsetof(struct config, clamd_port), "0", sizeof(int)}, { "clamd_socket", "string", (void*) string_parser, offsetof(struct config, clamd_socket), CLAMD_SOCKET, MAXVAL-1}, + { "consolidated_store", "integer", (void*) int_parser, offsetof(struct config, consolidated_store), "0", sizeof(int)}, { "debug", "integer", (void*) int_parser, offsetof(struct config, debug), "0", sizeof(int)}, { "default_retention_days", "integer", (void*) int_parser, offsetof(struct config, default_retention_days), "2557", sizeof(int)}, { "enable_chunking", "integer", (void*) int_parser, offsetof(struct config, enable_chunking), "0", sizeof(int)}, diff --git a/src/cfg.h b/src/cfg.h index 03ea7d12..4019b83e 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -23,6 +23,8 @@ struct config { int clamd_port; char clamd_socket[MAXVAL]; + int consolidated_store; + int encrypt_messages; int enable_chunking;