Skip to content
Snippets Groups Projects
Commit d2a75724 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

lib-sieve: Added sieve_enabled setting that defaults to "yes".

This allows completely disabling Sieve processing for a particular user.
parent 28b1d41f
No related branches found
No related tags found
No related merge requests found
...@@ -378,7 +378,7 @@ static struct sieve_storage *sieve_storage_do_create_main ...@@ -378,7 +378,7 @@ static struct sieve_storage *sieve_storage_do_create_main
/* disabled */ /* disabled */
if ( debug ) { if ( debug ) {
sieve_sys_debug(svinst, "storage: " sieve_sys_debug(svinst, "storage: "
"Sieve is disabled (sieve=\"\")"); "Personal storage is disabled (sieve=\"\")");
} }
*error_r = SIEVE_ERROR_NOT_FOUND; *error_r = SIEVE_ERROR_NOT_FOUND;
return NULL; return NULL;
...@@ -478,7 +478,8 @@ struct sieve_storage *sieve_storage_create_main ...@@ -478,7 +478,8 @@ struct sieve_storage *sieve_storage_create_main
enum sieve_storage_flags flags, enum sieve_error *error_r) enum sieve_storage_flags flags, enum sieve_error *error_r)
{ {
struct sieve_storage *storage; struct sieve_storage *storage;
const char *set_default, *set_default_name; const char *set_enabled, *set_default, *set_default_name;
bool debug = svinst->debug;
enum sieve_error error; enum sieve_error error;
if ( error_r != NULL ) if ( error_r != NULL )
...@@ -486,6 +487,18 @@ struct sieve_storage *sieve_storage_create_main ...@@ -486,6 +487,18 @@ struct sieve_storage *sieve_storage_create_main
else else
error_r = &error; error_r = &error;
/* Check whether Sieve is disabled for this user */
if ( (set_enabled=sieve_setting_get
(svinst, "sieve_enabled")) != NULL &&
strcasecmp(set_enabled, "no") == 0) {
if ( debug ) {
sieve_sys_debug(svinst,
"Sieve is disabled for this user");
}
*error_r = SIEVE_ERROR_NOT_POSSIBLE;
return NULL;
}
/* Determine location for default script */ /* Determine location for default script */
set_default = set_default =
sieve_setting_get(svinst, "sieve_default"); sieve_setting_get(svinst, "sieve_default");
...@@ -527,21 +540,27 @@ struct sieve_storage *sieve_storage_create_main ...@@ -527,21 +540,27 @@ struct sieve_storage *sieve_storage_create_main
/* Failed; try using default script location /* Failed; try using default script location
(not for temporary failures, read/write access, or dsync) */ (not for temporary failures, read/write access, or dsync) */
if ( set_default == NULL ) { if ( set_default == NULL ) {
sieve_sys_debug(svinst, "storage: " if ( debug ) {
"No default script location configured"); sieve_sys_debug(svinst, "storage: "
"No default script location configured");
}
} else { } else {
sieve_sys_debug(svinst, "storage: " if ( debug ) {
"Trying default script location `%s'", sieve_sys_debug(svinst, "storage: "
set_default); "Trying default script location `%s'",
set_default);
}
storage = sieve_storage_create storage = sieve_storage_create
(svinst, set_default, 0, error_r); (svinst, set_default, 0, error_r);
if ( storage == NULL ) { if ( storage == NULL ) {
switch ( *error_r ) { switch ( *error_r ) {
case SIEVE_ERROR_NOT_FOUND: case SIEVE_ERROR_NOT_FOUND:
sieve_sys_debug(svinst, "storage: " if ( debug ) {
"Default script location `%s' not found", sieve_sys_debug(svinst, "storage: "
set_default); "Default script location `%s' not found",
set_default);
}
break; break;
case SIEVE_ERROR_TEMP_FAILURE: case SIEVE_ERROR_TEMP_FAILURE:
sieve_sys_error(svinst, "storage: " sieve_sys_error(svinst, "storage: "
......
...@@ -64,14 +64,23 @@ static struct sieve_storage *client_get_storage ...@@ -64,14 +64,23 @@ static struct sieve_storage *client_get_storage
struct sieve_storage *storage; struct sieve_storage *storage;
enum sieve_error error; enum sieve_error error;
/* Open personal script storage */
storage = sieve_storage_create_main storage = sieve_storage_create_main
(svinst, user, SIEVE_STORAGE_FLAG_READWRITE, &error); (svinst, user, SIEVE_STORAGE_FLAG_READWRITE, &error);
if (storage == NULL) { if (storage == NULL) {
switch (error) { switch (error) {
case SIEVE_ERROR_NOT_POSSIBLE:
printf("BYE \"Sieve processing is disabled for this user.\"\n");
i_fatal("Failed to open Sieve storage: "
"Sieve is disabled for this user.");
break;
case SIEVE_ERROR_NOT_FOUND: case SIEVE_ERROR_NOT_FOUND:
printf("BYE \"Sieve filtering is disabled for this user.\"\n"); printf("BYE \"This user cannot manage personal Sieve scripts.\"\n");
i_fatal("Failed to open Sieve storage: Sieve disabled for user"); i_fatal("Failed to open Sieve storage: "
"Personal script storage disabled or not found.");
break; break;
default: default:
{ {
......
...@@ -181,6 +181,7 @@ static int lda_sieve_get_personal_storage ...@@ -181,6 +181,7 @@ static int lda_sieve_get_personal_storage
*storage_r = sieve_storage_create_main(svinst, user, 0, &error); *storage_r = sieve_storage_create_main(svinst, user, 0, &error);
if (*storage_r == NULL) { if (*storage_r == NULL) {
switch (error) { switch (error) {
case SIEVE_ERROR_NOT_POSSIBLE:
case SIEVE_ERROR_NOT_FOUND: case SIEVE_ERROR_NOT_FOUND:
break; break;
case SIEVE_ERROR_TEMP_FAILURE: case SIEVE_ERROR_TEMP_FAILURE:
...@@ -640,6 +641,8 @@ static int lda_sieve_find_scripts(struct lda_sieve_run_context *srctx) ...@@ -640,6 +641,8 @@ static int lda_sieve_find_scripts(struct lda_sieve_run_context *srctx)
ret = lda_sieve_get_personal_storage ret = lda_sieve_get_personal_storage
(svinst, mdctx->dest_user, &main_storage); (svinst, mdctx->dest_user, &main_storage);
if ( ret == 0 && error == SIEVE_ERROR_NOT_POSSIBLE )
return 0;
if ( ret > 0 ) { if ( ret > 0 ) {
srctx->main_script = srctx->main_script =
sieve_storage_active_script_open(main_storage, &error); sieve_storage_active_script_open(main_storage, &error);
...@@ -920,11 +923,14 @@ static int lda_sieve_deliver_mail ...@@ -920,11 +923,14 @@ static int lda_sieve_deliver_mail
T_BEGIN { T_BEGIN {
if (lda_sieve_find_scripts(&srctx) < 0) if (lda_sieve_find_scripts(&srctx) < 0)
ret = -1; ret = -1;
else else if ( srctx.scripts == NULL )
ret = 0;
else {
ret = lda_sieve_execute(&srctx, storage_r); ret = lda_sieve_execute(&srctx, storage_r);
for ( i = 0; i < srctx.script_count; i++ ) for ( i = 0; i < srctx.script_count; i++ )
sieve_script_unref(&srctx.scripts[i]); sieve_script_unref(&srctx.scripts[i]);
}
} T_END; } T_END;
/* Clean up */ /* Clean up */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.