dovecot-2.1-pigeonhole: lib-sieve: editheader: implemented confi...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Tue Nov 29 23:21:19 EET 2011
details: http://hg.rename-it.nl/dovecot-2.1-pigeonhole/rev/00c5cd8ca1d2
changeset: 1568:00c5cd8ca1d2
user: Stephan Bosch <stephan at rename-it.nl>
date: Tue Nov 29 22:21:13 2011 +0100
description:
lib-sieve: editheader: implemented configurable length limit.
diffstat:
TODO | 4 +-
src/lib-sieve/plugins/editheader/Makefile.am | 1 +
src/lib-sieve/plugins/editheader/cmd-addheader.c | 26 +++++-
src/lib-sieve/plugins/editheader/cmd-deleteheader.c | 6 +-
src/lib-sieve/plugins/editheader/ext-editheader-common.c | 32 ++++++++
src/lib-sieve/plugins/editheader/ext-editheader-common.h | 7 +
src/lib-sieve/plugins/editheader/ext-editheader-limits.h | 10 ++
tests/extensions/editheader/errors.svtest | 58 ++++++++++++++
tests/extensions/editheader/errors/size-limit-runtime.sieve | 46 +++++++++++
tests/extensions/editheader/errors/size-limit.sieve | 43 ++++++++++
10 files changed, 222 insertions(+), 11 deletions(-)
diffs (truncated from 372 to 300 lines):
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 TODO
--- a/TODO Tue Nov 29 01:10:32 2011 +0100
+++ b/TODO Tue Nov 29 22:21:13 2011 +0100
@@ -1,7 +1,7 @@
Current activities:
-* Implement editheader extension
- - Implement configurable limit on header value length
+* Finish editheader extension
+ - Document extension configuration
Parallel plugin-based efforts:
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 src/lib-sieve/plugins/editheader/Makefile.am
--- a/src/lib-sieve/plugins/editheader/Makefile.am Tue Nov 29 01:10:32 2011 +0100
+++ b/src/lib-sieve/plugins/editheader/Makefile.am Tue Nov 29 22:21:13 2011 +0100
@@ -14,4 +14,5 @@
ext-editheader-common.c
noinst_HEADERS = \
+ ext-editheader-limits.h \
ext-editheader-common.h
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 src/lib-sieve/plugins/editheader/cmd-addheader.c
--- a/src/lib-sieve/plugins/editheader/cmd-addheader.c Tue Nov 29 01:10:32 2011 +0100
+++ b/src/lib-sieve/plugins/editheader/cmd-addheader.c Tue Nov 29 22:21:13 2011 +0100
@@ -114,8 +114,8 @@
if ( ext_editheader_header_is_protected(cmd->ext, str_c(fname)) ) {
sieve_argument_validate_warning(valdtr, arg, "addheader command: "
- "specified header field `%s' is protected "
- "(modification will be denied)", str_sanitize(str_c(fname), 80));
+ "specified header field `%s' is protected; "
+ "modification will be denied", str_sanitize(str_c(fname), 80));
}
}
@@ -136,11 +136,18 @@
if ( !rfc2822_header_field_body_verify
(str_c(fvalue), str_len(fvalue), TRUE, TRUE) ) {
- sieve_argument_validate_error
- (valdtr, arg, "addheader command: specified value `%s' is invalid",
- str_sanitize(str_c(fvalue), 80));
+ sieve_argument_validate_error(valdtr, arg,
+ "addheader command: specified value `%s' is invalid",
+ str_sanitize(str_c(fvalue), 80));
return FALSE;
}
+
+ if ( ext_editheader_header_too_large(cmd->ext, str_len(fvalue)) ) {
+ sieve_argument_validate_error(valdtr, arg, "addheader command: "
+ "specified header value `%s' is too large (%"PRIuSIZE_T" bytes)",
+ str_sanitize(str_c(fvalue), 80), str_len(fvalue));
+ return SIEVE_EXEC_FAILURE;
+ }
}
return TRUE;
@@ -269,7 +276,7 @@
if ( ext_editheader_header_is_protected(this_ext, str_c(field_name)) ) {
sieve_runtime_warning(renv, NULL, "addheader action: "
- "specified header field `%s' is protected (modification denied)",
+ "specified header field `%s' is protected; modification denied",
str_sanitize(str_c(field_name), 80));
return SIEVE_EXEC_OK;
}
@@ -282,6 +289,13 @@
return SIEVE_EXEC_FAILURE;
}
+ if ( ext_editheader_header_too_large(this_ext, str_len(value)) ) {
+ sieve_runtime_error(renv, NULL, "addheader action: "
+ "specified header value `%s' is too large (%"PRIuSIZE_T" bytes)",
+ str_sanitize(str_c(value), 80), str_len(value));
+ return SIEVE_EXEC_FAILURE;
+ }
+
/*
* Perform operation
*/
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 src/lib-sieve/plugins/editheader/cmd-deleteheader.c
--- a/src/lib-sieve/plugins/editheader/cmd-deleteheader.c Tue Nov 29 01:10:32 2011 +0100
+++ b/src/lib-sieve/plugins/editheader/cmd-deleteheader.c Tue Nov 29 22:21:13 2011 +0100
@@ -261,8 +261,8 @@
if ( ext_editheader_header_is_protected(cmd->ext, str_c(fname)) ) {
sieve_argument_validate_warning(valdtr, arg, "deleteheader command: "
- "specified header field `%s' is protected "
- "(modification will be denied)", str_sanitize(str_c(fname), 80));
+ "specified header field `%s' is protected; "
+ "modification will be denied", str_sanitize(str_c(fname), 80));
}
}
@@ -446,7 +446,7 @@
if ( ext_editheader_header_is_protected(this_ext, str_c(field_name)) ) {
sieve_runtime_warning(renv, NULL, "deleteheader action: "
- "specified header field `%s' is protected (modification denied)",
+ "specified header field `%s' is protected; modification denied",
str_sanitize(str_c(field_name), 80));
return SIEVE_EXEC_OK;
}
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 src/lib-sieve/plugins/editheader/ext-editheader-common.c
--- a/src/lib-sieve/plugins/editheader/ext-editheader-common.c Tue Nov 29 01:10:32 2011 +0100
+++ b/src/lib-sieve/plugins/editheader/ext-editheader-common.c Tue Nov 29 22:21:13 2011 +0100
@@ -12,6 +12,7 @@
#include "sieve-settings.h"
#include "sieve-extensions.h"
+#include "ext-editheader-limits.h"
#include "ext-editheader-common.h"
/*
@@ -29,6 +30,8 @@
pool_t pool;
ARRAY_DEFINE(headers, struct ext_editheader_header);
+
+ size_t max_header_size;
};
static struct ext_editheader_header *ext_editheader_config_header_find
@@ -53,6 +56,7 @@
(struct ext_editheader_config *) *context;
struct sieve_instance *svinst = ext->svinst;
const char *protected;
+ size_t max_header_size;
pool_t pool;
if ( *context != NULL ) {
@@ -64,6 +68,7 @@
pool = pool_alloconly_create("editheader_config", 512);
ext_config = p_new(pool, struct ext_editheader_config, 1);
ext_config->pool = pool;
+ ext_config->max_header_size = EXT_EDITHEADER_DEFAULT_MAX_HEADER_SIZE;
p_array_init(&ext_config->headers, pool, 16);
@@ -92,6 +97,19 @@
headers++;
}
}
+
+ if ( sieve_setting_get_size_value
+ (svinst, "sieve_editheader_max_header_size", &max_header_size) ) {
+ if ( max_header_size < EXT_EDITHEADER_MINIMUM_MAX_HEADER_SIZE ) {
+ sieve_sys_warning(svinst,
+ "editheader: value of sieve_editheader_max_header_size setting "
+ "(=%"PRIuSIZE_T") is less than the minimum (=%"PRIuSIZE_T") "
+ "(ignored)", max_header_size,
+ (size_t) EXT_EDITHEADER_MINIMUM_MAX_HEADER_SIZE);
+ } else {
+ ext_config->max_header_size = max_header_size;
+ }
+ }
} T_END;
*context = (void *) ext_config;
@@ -133,3 +151,17 @@
return header->protected;
}
+
+/*
+ * Limits
+ */
+
+bool ext_editheader_header_too_large
+(const struct sieve_extension *ext, size_t size)
+{
+ struct ext_editheader_config *ext_config =
+ (struct ext_editheader_config *) ext->context;
+
+ return size > ext_config->max_header_size;
+}
+
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 src/lib-sieve/plugins/editheader/ext-editheader-common.h
--- a/src/lib-sieve/plugins/editheader/ext-editheader-common.h Tue Nov 29 01:10:32 2011 +0100
+++ b/src/lib-sieve/plugins/editheader/ext-editheader-common.h Tue Nov 29 22:21:13 2011 +0100
@@ -40,4 +40,11 @@
bool ext_editheader_header_is_protected
(const struct sieve_extension *ext, const char *header);
+/*
+ * Limits
+ */
+
+bool ext_editheader_header_too_large
+ (const struct sieve_extension *ext, size_t size);
+
#endif /* __EXT_EDITHEADER_COMMON_H */
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 src/lib-sieve/plugins/editheader/ext-editheader-limits.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/editheader/ext-editheader-limits.h Tue Nov 29 22:21:13 2011 +0100
@@ -0,0 +1,10 @@
+/* Copyright (c) 2002-2011 Pigeonhole authors, see the included COPYING file
+ */
+
+#ifndef __EXT_EDITHEADER_LIMITS_H
+#define __EXT_EDITHEADER_LIMITS_H
+
+#define EXT_EDITHEADER_MINIMUM_MAX_HEADER_SIZE 1024
+#define EXT_EDITHEADER_DEFAULT_MAX_HEADER_SIZE 2048
+
+#endif /* __EXT_EDITHEADER_LIMITS_H */
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 tests/extensions/editheader/errors.svtest
--- a/tests/extensions/editheader/errors.svtest Tue Nov 29 01:10:32 2011 +0100
+++ b/tests/extensions/editheader/errors.svtest Tue Nov 29 22:21:13 2011 +0100
@@ -76,6 +76,64 @@
}
}
+/*
+ * TEST - Size limit
+ */
+
+test "Size limit" {
+ if not test_script_compile "errors/size-limit.sieve" {
+ test_fail "compile should have succeeded";
+ }
+
+ test_config_set "sieve_editheader_max_header_size" "1024";
+ test_config_reload :extension "editheader";
+
+ if test_script_compile "errors/size-limit.sieve" {
+ test_fail "compile should have failed";
+ }
+
+ if not test_error :count "eq" :comparator "i;ascii-numeric" "2" {
+ test_fail "wrong number of errors reported";
+ }
+}
+
+
+/*
+ * TEST - Size limit at runtime
+ */
+
+test_config_set "sieve_editheader_max_header_size" "";
+test_config_reload :extension "editheader";
+
+test "Size limit at runtime" {
+ if not test_script_compile "errors/size-limit-runtime.sieve" {
+ test_fail "compile should have succeeded";
+ }
+
+ if not test_script_run {
+ test_fail "run failed";
+ }
+
+ test_config_set "sieve_editheader_max_header_size" "1024";
+ test_config_reload :extension "editheader";
+
+ if not test_script_compile "errors/size-limit-runtime.sieve" {
+ test_fail "compile should have succeeded";
+ }
+
+ if test_script_run {
+ test_fail "run should have failed";
+ }
+
+ if not test_error :count "eq" :comparator "i;ascii-numeric" "1" {
+ test_fail "wrong number of errors reported";
+ }
+}
+
+/*
+ * TEST - Implicit keep at runtime error
+ */
+
test_set "message" text:
From: stephan at example.com
To: tss at example.com
diff -r 3cacf01fbbab -r 00c5cd8ca1d2 tests/extensions/editheader/errors/size-limit-runtime.sieve
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/editheader/errors/size-limit-runtime.sieve Tue Nov 29 22:21:13 2011 +0100
@@ -0,0 +1,46 @@
+require "editheader";
+require "variables";
+
+set "blob" text:
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
More information about the dovecot-cvs
mailing list