From 892240b316adf42c968eccc231a35876158d27f3 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan.bosch@open-xchange.com> Date: Sun, 29 Sep 2024 00:52:50 +0200 Subject: [PATCH] plugins: imapsieve: imap-sieve-settings - Properly check imapsieve_url setting for Sieve URL validity --- src/plugins/imapsieve/Makefile.am | 4 +++- src/plugins/imapsieve/imap-sieve-settings.c | 11 ++++++++--- src/plugins/settings/Makefile.am | 7 +++++-- src/plugins/settings/settings-get.pl | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/plugins/imapsieve/Makefile.am b/src/plugins/imapsieve/Makefile.am index 6a22cd15c..2f595eb2d 100644 --- a/src/plugins/imapsieve/Makefile.am +++ b/src/plugins/imapsieve/Makefile.am @@ -11,6 +11,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib-sieve \ -I$(top_srcdir)/src/lib-sieve/util \ -I$(top_srcdir)/src/lib-sieve/plugins/environment \ + -I$(top_srcdir)/src/lib-managesieve \ $(LIBDOVECOT_IMAP_INCLUDE) \ $(LIBDOVECOT_LDA_INCLUDE) \ $(LIBDOVECOT_INCLUDE) \ @@ -24,7 +25,8 @@ lib95_imap_sieve_plugin_la_SOURCES = \ imap-sieve-storage.c \ imap-sieve-plugin.c lib95_imap_sieve_plugin_la_LIBADD = \ - $(top_builddir)/src/lib-sieve/libdovecot-sieve.la + $(top_builddir)/src/lib-sieve/libdovecot-sieve.la \ + $(top_builddir)/src/lib-managesieve/libdovecot-managesieve.la lib90_sieve_imapsieve_plugin_la_SOURCES = \ ext-imapsieve.c \ diff --git a/src/plugins/imapsieve/imap-sieve-settings.c b/src/plugins/imapsieve/imap-sieve-settings.c index 19ca54042..2291cf277 100644 --- a/src/plugins/imapsieve/imap-sieve-settings.c +++ b/src/plugins/imapsieve/imap-sieve-settings.c @@ -6,6 +6,7 @@ #include "settings.h" #include "settings-parser.h" +#include "managesieve-url.h" #include "imap-sieve-settings.h" #undef DEF @@ -48,10 +49,14 @@ imap_sieve_settings_check(void *_set, pool_t pool ATTR_UNUSED, const char **error_r) { struct imap_sieve_settings *set = _set; + const char *error; - if (*set->url != '\0' && !str_begins_icase_with(set->url, "sieve:")) { - *error_r = "Invalid URL for imapsieve_url setting: " - "Not a Sieve URL"; + if (*set->url != '\0' && + managesieve_url_parse(set->url, 0, pool_datastack_create(), + NULL, &error) < 0) { + *error_r = t_strdup_printf( + "Invalid URL for imapsieve_url setting: %s", + set->url); return FALSE; } diff --git a/src/plugins/settings/Makefile.am b/src/plugins/settings/Makefile.am index 4f6c810e7..b55bb834e 100644 --- a/src/plugins/settings/Makefile.am +++ b/src/plugins/settings/Makefile.am @@ -4,6 +4,7 @@ AM_CPPFLAGS = \ $(LIBDOVECOT_INCLUDE) \ -I$(top_srcdir) \ -I$(top_srcdir)/src/lib-sieve \ + -I$(top_srcdir)/src/lib-managesieve \ -DSETTINGS_PLUGIN libpigeonhole_settings_la_LDFLAGS = -module -avoid-version @@ -15,9 +16,11 @@ libpigeonhole_settings_la_SOURCES = \ pigeonhole-settings-dynamic.c \ pigeonhole-settings.c libpigeonhole_settings_la_LIBADD = \ - $(top_builddir)/src/lib-sieve/libdovecot-sieve.la + $(top_builddir)/src/lib-sieve/libdovecot-sieve.la \ + $(top_builddir)/src/lib-managesieve/libdovecot-managesieve.la libpigeonhole_settings_la_DEPENDENCIES = \ - $(top_builddir)/src/lib-sieve/libdovecot-sieve.la + $(top_builddir)/src/lib-sieve/libdovecot-sieve.la \ + $(top_builddir)/src/lib-managesieve/libdovecot-managesieve.la noinst_HEADERS = \ pigeonhole-settings.h diff --git a/src/plugins/settings/settings-get.pl b/src/plugins/settings/settings-get.pl index d8b0fb8a3..edf7e8aa2 100755 --- a/src/plugins/settings/settings-get.pl +++ b/src/plugins/settings/settings-get.pl @@ -26,6 +26,7 @@ print '#include "message-header-parser.h"'."\n"; print '#include "sieve-common.h"'."\n"; print '#include "sieve-limits.h"'."\n"; print '#include "sieve-address-source.h"'."\n"; +print '#include "managesieve-url.h"'."\n"; print '#include "pigeonhole-settings.h"'."\n"; print '#include <unistd.h>'."\n"; print '#define CONFIG_BINARY'."\n"; -- GitLab