diff --git a/src/lib-sieve/sieve-script.c b/src/lib-sieve/sieve-script.c index f78fb4328da98dc0cb1c26e8b8cd5f86446fc44e..6009642a31783666b30f06ea86402161c44feafc 100644 --- a/src/lib-sieve/sieve-script.c +++ b/src/lib-sieve/sieve-script.c @@ -170,7 +170,6 @@ int sieve_script_open if ( script->open ) return 0; - script->location = NULL; if ( script->v.open(script, error_r) < 0 ) return -1; diff --git a/src/lib-sieve/storage/dict/sieve-dict-script.c b/src/lib-sieve/storage/dict/sieve-dict-script.c index 52e2d9170853f15aead2b357159586f7b4949515..40ee831e50d6cfe37f778253549cf5054bd6f30f 100644 --- a/src/lib-sieve/storage/dict/sieve-dict-script.c +++ b/src/lib-sieve/storage/dict/sieve-dict-script.c @@ -35,13 +35,19 @@ struct sieve_dict_script *sieve_dict_script_init { struct sieve_storage *storage = &dstorage->storage; struct sieve_dict_script *dscript = NULL; + const char *location; - if ( name == NULL ) + if ( name == NULL ) { name = SIEVE_DICT_SCRIPT_DEFAULT; + location = storage->location; + } else { + location = t_strconcat + (storage->location, ";name=", name, NULL); + } dscript = sieve_dict_script_alloc(); sieve_script_init(&dscript->script, - storage, &sieve_dict_script, storage->location, name); + storage, &sieve_dict_script, location, name); return dscript; } @@ -70,7 +76,7 @@ static int sieve_dict_script_open if ( sieve_dict_storage_get_dict (dstorage, &dscript->dict, error_r) < 0 ) return -1; - + path = t_strconcat (DICT_SIEVE_NAME_PATH, dict_escape_string(name), NULL); @@ -92,15 +98,6 @@ static int sieve_dict_script_open return -1; } - if ( strcmp(name, SIEVE_DICT_SCRIPT_DEFAULT) == 0 ) { - script->location = p_strconcat(script->pool, - SIEVE_DICT_STORAGE_DRIVER_NAME, ":", storage->location, NULL); - } else { - script->location = p_strconcat(script->pool, - SIEVE_DICT_STORAGE_DRIVER_NAME, ":", storage->location, - ";name=", name, NULL); - } - return 0; } diff --git a/src/lib-sieve/storage/dict/sieve-dict-storage.c b/src/lib-sieve/storage/dict/sieve-dict-storage.c index 976eb3dfe65fe80a9d245ac054afc558433ce3e2..395016337b926093ebf4f6c9891b3d8b67932094 100644 --- a/src/lib-sieve/storage/dict/sieve-dict-storage.c +++ b/src/lib-sieve/storage/dict/sieve-dict-storage.c @@ -33,7 +33,7 @@ static int sieve_dict_storage_init struct sieve_dict_storage *dstorage = (struct sieve_dict_storage *)storage; struct sieve_instance *svinst = storage->svinst; - const char *username = NULL; + const char *uri = storage->location, *username = NULL; if ( options != NULL ) { while ( *options != NULL ) { @@ -70,9 +70,15 @@ static int sieve_dict_storage_init } sieve_storage_sys_debug(storage, - "user=%s, uri=%s", username, storage->location); + "user=%s, uri=%s", username, uri); + dstorage->uri = p_strdup(storage->pool, uri); dstorage->username = p_strdup(storage->pool, username); + + storage->location = p_strconcat(storage->pool, + SIEVE_DICT_STORAGE_DRIVER_NAME, ":", storage->location, + ";user=", username, NULL); + return 0; } @@ -86,12 +92,12 @@ int sieve_dict_storage_get_dict int ret; if ( dstorage->dict == NULL ) { - ret = dict_init(storage->location, DICT_DATA_TYPE_STRING, + ret = dict_init(dstorage->uri, DICT_DATA_TYPE_STRING, dstorage->username, svinst->base_dir, &dstorage->dict, &error); if ( ret < 0 ) { sieve_storage_set_critical(storage, "Failed to initialize dict with data `%s' for user `%s': %s", - storage->location, dstorage->username, error); + dstorage->uri, dstorage->username, error); *error_r = SIEVE_ERROR_TEMP_FAILURE; return -1; } diff --git a/src/lib-sieve/storage/dict/sieve-dict-storage.h b/src/lib-sieve/storage/dict/sieve-dict-storage.h index 35979e29b9886a9a87f58b883c4d89a0f65da572..a9198bc4bbb09bd290ba5678f8d74cc834b479d9 100644 --- a/src/lib-sieve/storage/dict/sieve-dict-storage.h +++ b/src/lib-sieve/storage/dict/sieve-dict-storage.h @@ -22,6 +22,7 @@ struct sieve_dict_storage { struct sieve_storage storage; const char *username; + const char *uri; struct dict *dict; }; diff --git a/src/lib-sieve/storage/file/Makefile.am b/src/lib-sieve/storage/file/Makefile.am index a6fda424fa10e69827efe1e17d0b6fc67f5234a5..b401fa8b752ba940ddad8fbdb4bbb874db14a72e 100644 --- a/src/lib-sieve/storage/file/Makefile.am +++ b/src/lib-sieve/storage/file/Makefile.am @@ -3,7 +3,8 @@ noinst_LTLIBRARIES = libsieve_storage_file.la AM_CPPFLAGS = \ $(LIBDOVECOT_INCLUDE) \ -I$(top_srcdir) \ - -I$(top_srcdir)/src/lib-sieve + -I$(top_srcdir)/src/lib-sieve \ + -I$(top_srcdir)/src/lib-sieve/util libsieve_storage_file_la_SOURCES = \ sieve-file-script.c \ diff --git a/src/lib-sieve/storage/file/sieve-file-script.c b/src/lib-sieve/storage/file/sieve-file-script.c index 007da4e3bb6f43ee66fd1decbbd3267898ca6aea..fb30f38f0b4507f56bc241ced7602518cec1f878 100644 --- a/src/lib-sieve/storage/file/sieve-file-script.c +++ b/src/lib-sieve/storage/file/sieve-file-script.c @@ -409,12 +409,7 @@ static int sieve_file_script_open fscript->binpath = p_strdup(pool, binpath); fscript->binprefix = p_strdup(pool, binprefix); - if ( fscript->script.name == NULL || *fscript->script.name == '\0' || - strcmp(fscript->script.name, basename) == 0 ) - fscript->script.location = fscript->path; - else - fscript->script.location = p_strconcat - (pool, fscript->path, ";name=", fscript->script.name, NULL); + fscript->script.location = fscript->path; if ( fscript->script.name == NULL ) fscript->script.name = p_strdup(pool, basename); diff --git a/src/lib-sieve/storage/file/sieve-file-storage.c b/src/lib-sieve/storage/file/sieve-file-storage.c index 981ad24b803f1f61083f6ab5891c0b97aa7f7f86..3e1f438a0203e167e0d5ba8ab37106d3efcf53c1 100644 --- a/src/lib-sieve/storage/file/sieve-file-storage.c +++ b/src/lib-sieve/storage/file/sieve-file-storage.c @@ -10,6 +10,8 @@ #include "unlink-old-files.h" #include "mail-storage-private.h" +#include "realpath.h" + #include "sieve.h" #include "sieve-common.h" #include "sieve-settings.h" @@ -308,10 +310,14 @@ static int sieve_file_storage_init_common active_fname = NULL; if ( active_path != NULL && *active_path != '\0' ) { + const char *active_dir; + active_fname = strrchr(active_path, '/'); if ( active_fname == NULL ) { active_fname = active_path; + active_dir = ""; } else { + active_dir = t_strdup_until(active_path, active_fname); active_fname++; } @@ -325,6 +331,15 @@ static int sieve_file_storage_init_common return -1; } + if (t_realpath(active_dir, &active_dir) < 0) { + sieve_storage_sys_error(storage, + "Failed to normalize active script directory (path=%s): %m", + active_dir); + *error_r = SIEVE_ERROR_TEMP_FAILURE; + return -1; + } + active_path = t_abspath_to(active_fname, active_dir); + sieve_storage_sys_debug(storage, "Using %sSieve script path: %s", ( storage_path != NULL ? "active " : "" ), @@ -337,6 +352,14 @@ static int sieve_file_storage_init_common /* Determine storage path */ if (storage_path != NULL && *storage_path != '\0') { + if (t_realpath(storage_path, &storage_path) < 0) { + sieve_storage_sys_error(storage, + "Failed to normalize storage path (path=%s): %m", + active_path); + *error_r = SIEVE_ERROR_TEMP_FAILURE; + return -1; + } + sieve_storage_sys_debug(storage, "Using script storage path: %s", storage_path); @@ -440,8 +463,7 @@ static int sieve_file_storage_init_common (fstorage, fstorage->path, error_r) < 0 ) return -1; - if (storage->location == NULL) - storage->location = p_strdup(storage->pool, storage_path); + storage->location = fstorage->path; return 0; } diff --git a/src/lib-sieve/storage/ldap/sieve-ldap-script.c b/src/lib-sieve/storage/ldap/sieve-ldap-script.c index 8634deae3be5b28b974cc11b3f48b3f6866e4645..30cc5207f06e1cb8e5fcbcb4a26ebb69d941aaa4 100644 --- a/src/lib-sieve/storage/ldap/sieve-ldap-script.c +++ b/src/lib-sieve/storage/ldap/sieve-ldap-script.c @@ -36,13 +36,19 @@ struct sieve_ldap_script *sieve_ldap_script_init { struct sieve_storage *storage = &lstorage->storage; struct sieve_ldap_script *lscript = NULL; + const char *location; - if ( name == NULL ) + if ( name == NULL ) { name = SIEVE_LDAP_SCRIPT_DEFAULT; + location = storage->location; + } else { + location = t_strconcat + (storage->location, ";name=", name, NULL); + } lscript = sieve_ldap_script_alloc(); sieve_script_init(&lscript->script, - storage, &sieve_ldap_script, storage->location, name); + storage, &sieve_ldap_script, location, name); return lscript; } @@ -54,7 +60,6 @@ static int sieve_ldap_script_open struct sieve_storage *storage = script->storage; struct sieve_ldap_storage *lstorage = (struct sieve_ldap_storage *)storage; - const char *name = script->name; int ret; if ( sieve_ldap_db_connect(lstorage->conn) < 0 ) { @@ -78,15 +83,6 @@ static int sieve_ldap_script_open return -1; } - if ( strcmp(name, SIEVE_LDAP_SCRIPT_DEFAULT) == 0 ) { - script->location = p_strconcat(script->pool, - SIEVE_LDAP_STORAGE_DRIVER_NAME, ":", storage->location, NULL); - } else { - script->location = p_strconcat(script->pool, - SIEVE_LDAP_STORAGE_DRIVER_NAME, ":", storage->location, - ";name=", name, NULL); - } - return 0; } @@ -238,7 +234,7 @@ static bool sieve_ldap_script_equals if ( strcmp(storage->location, sother->location) != 0 ) return FALSE; - + i_assert( script->name != NULL && other->name != NULL ); return ( strcmp(script->name, other->name) == 0 ); diff --git a/src/lib-sieve/storage/ldap/sieve-ldap-storage.c b/src/lib-sieve/storage/ldap/sieve-ldap-storage.c index eac7821909914030f5121726cdad08fa644f5bd1..4d18ae0e0f191fbc98b39692819a26b9cd29bfb8 100644 --- a/src/lib-sieve/storage/ldap/sieve-ldap-storage.c +++ b/src/lib-sieve/storage/ldap/sieve-ldap-storage.c @@ -82,9 +82,12 @@ static int sieve_ldap_storage_init return -1; lstorage->username = p_strdup(storage->pool, username); - lstorage->conn = sieve_ldap_db_init(lstorage); + storage->location = p_strconcat(storage->pool, + SIEVE_LDAP_STORAGE_DRIVER_NAME, ":", storage->location, + ";user=", username, NULL); + return 0; }