dovecot-1.2: zlib: If gz/bz2 support isn't compiled in but we de...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jul 10 20:10:36 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/9369c0190ef0
changeset: 7989:9369c0190ef0
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jul 10 22:38:31 2008 +0530
description:
zlib: If gz/bz2 support isn't compiled in but we detect a mail with gz/bz2
compression, log an error and fail to read the mail.

diffstat:

1 file changed, 24 insertions(+), 16 deletions(-)
src/plugins/zlib/zlib-plugin.c |   40 ++++++++++++++++++++++++----------------

diffs (87 lines):

diff -r e069e4c221e1 -r 9369c0190ef0 src/plugins/zlib/zlib-plugin.c
--- a/src/plugins/zlib/zlib-plugin.c	Wed Jul 09 20:13:05 2008 +0530
+++ b/src/plugins/zlib/zlib-plugin.c	Thu Jul 10 22:38:31 2008 +0530
@@ -17,7 +17,15 @@
 #define ZLIB_MAIL_CONTEXT(obj) \
 	MODULE_CONTEXT(obj, zlib_mail_module)
 
+#ifndef HAVE_ZLIB
+#  define i_stream_create_zlib NULL
+#endif
+#ifndef HAVE_BZLIB
+#  define i_stream_create_bzlib NULL
+#endif
+
 struct zlib_handler {
+	const char *name;
 	bool (*is_compressed)(struct istream *input);
 	struct istream *(*create_istream)(int fd);
 };
@@ -31,7 +39,6 @@ static MODULE_CONTEXT_DEFINE_INIT(zlib_s
 				  &mail_storage_module_register);
 static MODULE_CONTEXT_DEFINE_INIT(zlib_mail_module, &mail_module_register);
 
-#ifdef HAVE_ZLIB
 static bool is_compressed_zlib(struct istream *input)
 {
 	const unsigned char *data;
@@ -47,9 +54,7 @@ static bool is_compressed_zlib(struct is
 
 	return data[0] == 31 && data[1] == 139;
 }
-#endif
-
-#ifdef HAVE_ZLIB
+
 static bool is_compressed_bzlib(struct istream *input)
 {
 	const unsigned char *data;
@@ -65,23 +70,17 @@ static bool is_compressed_bzlib(struct i
 		return FALSE;
 	return memcmp(data + 4, "\x31\x41\x59\x26\x53\x59", 6) == 0;
 }
-#endif
 
 static struct zlib_handler zlib_handlers[] = {
-#ifdef HAVE_ZLIB
-	{ is_compressed_zlib, i_stream_create_zlib },
-#endif
-#ifdef HAVE_BZLIB
-	{ is_compressed_bzlib, i_stream_create_bzlib },
-#endif
-	{ NULL, NULL }
+	{ "zlib", is_compressed_zlib, i_stream_create_zlib },
+	{ "bzlib", is_compressed_bzlib, i_stream_create_bzlib }
 };
 
 static struct zlib_handler *zlib_get_zlib_handler(struct istream *input)
 {
 	unsigned int i;
 
-	for (i = 0; i < N_ELEMENTS(zlib_handlers)-1; i++) {
+	for (i = 0; i < N_ELEMENTS(zlib_handlers); i++) {
 		if (zlib_handlers[i].is_compressed(input))
 			return &zlib_handlers[i];
 	}
@@ -111,9 +110,18 @@ static int zlib_maildir_get_stream(struc
 
 	handler = zlib_get_zlib_handler(imail->data.stream);
 	if (handler != NULL) {
-		fd = dup(i_stream_get_fd(imail->data.stream));
-		if (fd == -1)
-			i_error("zlib plugin: dup() failed: %m");
+		if (handler->create_istream == NULL) {
+			mail_storage_set_critical(_mail->box->storage,
+				"zlib plugin: Detected %s "
+				"but support not compiled in", handler->name);
+			fd = -1;
+		} else {
+			fd = dup(i_stream_get_fd(imail->data.stream));
+			if (fd == -1) {
+				mail_storage_set_critical(_mail->box->storage,
+					"zlib plugin: dup() failed: %m");
+			}
+		}
 
 		imail->data.destroying_stream = TRUE;
 		i_stream_unref(&imail->data.stream);


More information about the dovecot-cvs mailing list