dovecot-2.2-pigeonhole: Include: fixed namespace separation of :...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Fri Aug 10 00:01:48 EEST 2012


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/6a34eda7924e
changeset: 1643:6a34eda7924e
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Fri Aug 03 19:52:36 2012 +0200
description:
Include: fixed namespace separation of :global and :personal scripts.
Sieve script equality function implementation was wrong.

diffstat:

 src/lib-sieve/sieve-script-dict.c                        |  29 +++++++++++++--
 src/lib-sieve/sieve-script-file.c                        |   4 +-
 src/lib-sieve/sieve-script.c                             |  11 ++---
 tests/extensions/include/execute.svtest                  |  27 ++++++++++++++
 tests/extensions/include/included-global/namespace.sieve |   4 ++
 tests/extensions/include/included/namespace.sieve        |   4 ++
 6 files changed, 67 insertions(+), 12 deletions(-)

diffs (162 lines):

diff -r c52a0c561311 -r 6a34eda7924e src/lib-sieve/sieve-script-dict.c
--- a/src/lib-sieve/sieve-script-dict.c	Tue Jul 31 01:18:15 2012 +0200
+++ b/src/lib-sieve/sieve-script-dict.c	Fri Aug 03 19:52:36 2012 +0200
@@ -17,7 +17,8 @@
 	struct sieve_script script;
 
 	struct dict *dict;
-	
+	const char *dict_uri;
+
 	pool_t data_pool;
 	const char *data_id;
 	const char *data;
@@ -103,8 +104,9 @@
 			"user=%s, uri=%s, script=%s", username, data, name);
 	}
 
+	script->dict_uri = p_strdup(_script->pool, data);
 	script->dict = dict_init
-		(data, DICT_DATA_TYPE_STRING, username, svinst->base_dir);
+		(script->dict_uri, DICT_DATA_TYPE_STRING, username, svinst->base_dir);
 	if ( script->dict == NULL ) {
 		sieve_critical(svinst, ehandler, name, "failed to open sieve script",
 			"sieve dict backend: failed to initialize dict with data `%s' "
@@ -265,6 +267,24 @@
 	return sieve_binary_save(sbin, script->binpath, update, 0600, error_r);
 }
 
+static bool sieve_dict_script_equals
+(const struct sieve_script *_script, const struct sieve_script *_other)
+{
+        struct sieve_dict_script *script = (struct sieve_dict_script *)_script;
+        struct sieve_dict_script *other = (struct sieve_dict_script *)_other;
+
+        if ( script == NULL || other == NULL )
+                return FALSE;
+
+        if ( strcmp(script->dict_uri, other->dict_uri) != 0 )
+		return FALSE;
+
+	i_assert( _script->name != NULL && _other->name != NULL );
+
+        return ( strcmp(_script->name, _other->name) == 0 );
+}
+
+
 const struct sieve_script sieve_dict_script = {
 	.driver_name = SIEVE_DICT_SCRIPT_DRIVER_NAME,
 	.v = {
@@ -273,13 +293,14 @@
 		sieve_dict_script_destroy,
 
 		sieve_dict_script_open,
-		sieve_dict_script_close,	
+		sieve_dict_script_close,
 
 		sieve_dict_script_binary_read_metadata,
 		sieve_dict_script_binary_write_metadata,
 		sieve_dict_script_binary_load,
 		sieve_dict_script_binary_save,
 
-		NULL, NULL
+		NULL,
+		sieve_dict_script_equals
 	}
 };
diff -r c52a0c561311 -r 6a34eda7924e src/lib-sieve/sieve-script-file.c
--- a/src/lib-sieve/sieve-script-file.c	Tue Jul 31 01:18:15 2012 +0200
+++ b/src/lib-sieve/sieve-script-file.c	Fri Aug 03 19:52:36 2012 +0200
@@ -310,8 +310,8 @@
 	struct sieve_file_script *script = (struct sieve_file_script *)_script;
 	struct sieve_file_script *other = (struct sieve_file_script *)_other;
 
-	if ( script == NULL || other == NULL ) 
-		return -1;	
+	if ( script == NULL || other == NULL )
+		return FALSE;
 
 	return ( script->st.st_ino == other->st.st_ino );
 }
diff -r c52a0c561311 -r 6a34eda7924e src/lib-sieve/sieve-script.c
--- a/src/lib-sieve/sieve-script.c	Tue Jul 31 01:18:15 2012 +0200
+++ b/src/lib-sieve/sieve-script.c	Fri Aug 03 19:52:36 2012 +0200
@@ -414,18 +414,17 @@
 	if ( script->script_class != other->script_class )
 		return FALSE;
 
-	if ( script->name != NULL && other->name != NULL &&
-		strcmp(script->name, other->name) == 0 )
-		return TRUE;
+	if ( script->v.equals == NULL ) {
+		i_assert ( script->location != NULL && other->location != NULL);
 
-	if ( script->v.equals == NULL )
-		return FALSE;
+		return ( strcmp(script->location, other->location) == 0 );
+	}
 
 	return script->v.equals(script, other);
 }
 
 unsigned int sieve_script_hash(const struct sieve_script *script)
-{	
+{
 	return str_hash(script->name);
 }
 
diff -r c52a0c561311 -r 6a34eda7924e tests/extensions/include/execute.svtest
--- a/tests/extensions/include/execute.svtest	Tue Jul 31 01:18:15 2012 +0200
+++ b/tests/extensions/include/execute.svtest	Fri Aug 03 19:52:36 2012 +0200
@@ -1,4 +1,6 @@
 require "vnd.dovecot.testsuite";
+require "include";
+require "variables";
 
 test_set "message" text:
 From: idiot at example.com
@@ -40,3 +42,28 @@
 		test_fail "fileinto \"bbbb\" not executed.";
 	}	
 }
+
+test "Namespace" {
+	set "global.a" "none";
+	include :personal "namespace";
+
+	if string "${global.a}" "none" {
+		test_fail "global script not executed";
+	}
+
+	if not string "${global.a}" "personal" {
+		test_fail "executed global instead of personal script: ${global.a}";
+	}
+
+	set "global.a" "none";
+	include :global "namespace";
+
+	if string "{global.a}" "none" {
+		test_fail "global script not executed";
+	}
+
+	if not string "${global.a}" "global" {
+		test_fail "executed personal instead of global script: ${global.a}";
+	}
+}
+
diff -r c52a0c561311 -r 6a34eda7924e tests/extensions/include/included-global/namespace.sieve
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/include/included-global/namespace.sieve	Fri Aug 03 19:52:36 2012 +0200
@@ -0,0 +1,4 @@
+require "include";
+require "variables";
+
+set "global.a" "global";
diff -r c52a0c561311 -r 6a34eda7924e tests/extensions/include/included/namespace.sieve
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/include/included/namespace.sieve	Fri Aug 03 19:52:36 2012 +0200
@@ -0,0 +1,4 @@
+require "include";
+require "variables";
+
+set "global.a" "personal";


More information about the dovecot-cvs mailing list