Sophie

Sophie

distrib > Mandriva > cs4.0 > i586 > by-pkgid > e21f77e5abeaa9d7a2ac16f1e6817f1f > files > 4

postfix-2.2.11-1mlcs4.src.rpm

diff -u -r postfix-2.2.4/src/cleanup/cleanup.h postfix-2.2.4-patch/src/cleanup/cleanup.h
--- postfix-2.2.4/src/cleanup/cleanup.h	2005-02-12 23:53:25.000000000 +0100
+++ postfix-2.2.4-patch/src/cleanup/cleanup.h	2005-07-16 11:41:17.000000000 +0200
@@ -93,6 +93,13 @@
 extern MAPS *cleanup_send_bcc_maps;
 extern MAPS *cleanup_rcpt_bcc_maps;
 
+/* chars which will cause message reject or which will be stripped from message */
+
+extern VSTRING *reject_chars;
+extern VSTRING *strip_chars;
+
+
+
  /*
   * Address canonicalization fine control.
   */
diff -u -r postfix-2.2.4/src/cleanup/cleanup_init.c postfix-2.2.4-patch/src/cleanup/cleanup_init.c
--- postfix-2.2.4/src/cleanup/cleanup_init.c	2004-10-25 22:59:02.000000000 +0200
+++ postfix-2.2.4-patch/src/cleanup/cleanup_init.c	2005-07-16 11:41:17.000000000 +0200
@@ -188,6 +188,12 @@
 MAPS   *cleanup_send_bcc_maps;
 MAPS   *cleanup_rcpt_bcc_maps;
 
+/* chars which will cause message reject or which will be stripped from message */
+
+VSTRING *reject_chars;
+VSTRING *strip_chars;
+
+
  /*
   * Address extension propagation restrictions.
   */
@@ -310,4 +316,14 @@
      */
     cleanup_ext_prop_mask =
 	ext_prop_mask(VAR_PROP_EXTENSION, var_prop_extension);
+
+    /*
+     * setup the VSTRINGs which are used to check for disallowed chars 
+     * which cause message to be rejected or which are stripped out.
+     */
+	reject_chars = vstring_alloc(10);
+	unescape(reject_chars,var_msg_reject_chars);
+	strip_chars = vstring_alloc(10);
+	unescape(strip_chars,var_msg_strip_chars);
+
 }
diff -u -r postfix-2.2.4/src/cleanup/cleanup_message.c postfix-2.2.4-patch/src/cleanup/cleanup_message.c
--- postfix-2.2.4/src/cleanup/cleanup_message.c	2005-03-30 16:21:31.000000000 +0200
+++ postfix-2.2.4-patch/src/cleanup/cleanup_message.c	2005-07-16 11:46:21.000000000 +0200
@@ -292,6 +292,7 @@
 
 #define CLEANUP_ACT_CTXT_HEADER	"header"
 #define CLEANUP_ACT_CTXT_BODY	"body"
+#define CLEANUP_ACT_CTXT_MSG	"message"
 
 /* cleanup_act - act upon a header/body match */
 
@@ -689,6 +690,36 @@
 				               const char *buf, int len)
 {
     char   *myname = "cleanup_message_headerbody";
+	unsigned char *cp;
+	unsigned int offset = 0;
+
+	/* if buffer contains chars from message_reject_characters
+	   then reject message */
+
+	if ((state->flags & CLEANUP_FLAG_FILTER) && var_msg_reject_chars) {
+		for (cp = (char * ) buf; cp < buf + len; cp++) {
+			if (vstring_instr(reject_chars, *cp)) {
+				cleanup_act(state, CLEANUP_ACT_CTXT_MSG,
+				buf, "REJECT disallowed character", "");
+				return;
+			}
+		}
+	}
+
+	/* if buffer contains chars from message_strip_characters
+	   then strip from buffer */
+
+	if (var_msg_strip_chars) {
+		for (cp = (char *) buf; cp < buf + len; cp++) {
+			if (!vstring_instr(strip_chars, *cp)) {
+				*(cp-offset) = *cp;
+			}
+			else {
+				offset++;
+			}
+		}
+		len -= offset;
+	}
 
     /*
      * Copy text record to the output.
diff -u -r postfix-2.2.4/src/global/mail_params.c postfix-2.2.4-patch/src/global/mail_params.c
--- postfix-2.2.4/src/global/mail_params.c	2005-01-19 02:22:02.000000000 +0100
+++ postfix-2.2.4-patch/src/global/mail_params.c	2005-07-16 11:41:17.000000000 +0200
@@ -104,7 +104,8 @@
 /*	int     var_strict_encoding;
 /*	int     var_verify_neg_cache;
 /*	int	var_oldlog_compat;
-/*
+/*	char	*var_msg_reject_chars;
+/*	char	*var_msg_strip_chars;/*
 /*	void	mail_params_init()
 /* DESCRIPTION
 /*	This module (actually the associated include file) define the names
@@ -293,6 +294,8 @@
 int     var_strict_encoding;
 int     var_verify_neg_cache;
 int     var_oldlog_compat;
+char    *var_msg_reject_chars;
+char    *var_msg_strip_chars;
 
 /* check_myhostname - lookup hostname and validate */
 
@@ -510,6 +513,8 @@
 	VAR_FLUSH_SERVICE, DEF_FLUSH_SERVICE, &var_flush_service, 1, 0,
 	VAR_VERIFY_SERVICE, DEF_VERIFY_SERVICE, &var_verify_service, 1, 0,
 	VAR_TRACE_SERVICE, DEF_TRACE_SERVICE, &var_trace_service, 1, 0,
+	VAR_MSG_REJECT_CHARS, DEF_MSG_REJECT_CHARS, &var_msg_reject_chars, 0, 0,
+	VAR_MSG_STRIP_CHARS, DEF_MSG_STRIP_CHARS, &var_msg_strip_chars, 0, 0,
 #ifdef USE_TLS
 	VAR_TLS_RAND_EXCH_NAME, DEF_TLS_RAND_EXCH_NAME, &var_tls_rand_exch_name, 0, 0,
 	VAR_SMTPD_TLS_CERT_FILE, DEF_SMTPD_TLS_CERT_FILE, &var_smtpd_tls_cert_file, 0, 0,
diff -u -r postfix-2.2.4/src/global/mail_params.h postfix-2.2.4-patch/src/global/mail_params.h
--- postfix-2.2.4/src/global/mail_params.h	2005-02-27 16:06:07.000000000 +0100
+++ postfix-2.2.4-patch/src/global/mail_params.h	2005-07-16 11:41:17.000000000 +0200
@@ -2346,6 +2346,18 @@
 #define DEF_SMTP_EHLO_DIS_MAPS		""
 extern char *var_smtp_ehlo_dis_maps;
 
+ /*
+  * chars which cause reject or which are stripped
+  */
+
+#define VAR_MSG_REJECT_CHARS	"message_reject_characters"
+#define DEF_MSG_REJECT_CHARS	""
+extern char * var_msg_reject_chars;
+
+#define VAR_MSG_STRIP_CHARS		"message_strip_characters"
+#define DEF_MSG_STRIP_CHARS		""
+extern char * var_msg_strip_chars;
+
 /* LICENSE
 /* .ad
 /* .fi
diff -u -r postfix-2.2.4/src/util/vstring.c postfix-2.2.4-patch/src/util/vstring.c
--- postfix-2.2.4/src/util/vstring.c	2005-01-19 02:22:20.000000000 +0100
+++ postfix-2.2.4-patch/src/util/vstring.c	2005-07-16 11:41:17.000000000 +0200
@@ -508,6 +508,17 @@
     return (vp);
 }
 
+/* vstring_instr - returns 1 if needle is found in vp else 0 */
+
+int vstring_instr(VSTRING *vp, char needle)
+{
+	unsigned char * cp;
+	for (cp = vp->vbuf.data; cp < vp->vbuf.ptr; cp++) {
+		if ( *cp == needle) return 1;
+	}
+	return 0;
+}
+
 #ifdef TEST
 
  /*
diff -u -r postfix-2.2.4/src/util/vstring.h postfix-2.2.4-patch/src/util/vstring.h
--- postfix-2.2.4/src/util/vstring.h	2001-07-06 20:32:30.000000000 +0200
+++ postfix-2.2.4-patch/src/util/vstring.h	2005-07-16 11:41:17.000000000 +0200
@@ -44,6 +44,7 @@
 extern VSTRING *PRINTFLIKE(2, 3) vstring_sprintf_append(VSTRING *, const char *,...);
 extern char *vstring_export(VSTRING *);
 extern VSTRING *vstring_import(char *);
+extern int vstring_instr(VSTRING *vp, char needle);
 
 #define VSTRING_CTL_MAXLEN	1
 #define VSTRING_CTL_END		0