[dovecot-cvs] dovecot/src/deliver smtp-client.c,1.1.2.1,1.1.2.2

tss at dovecot.org tss at dovecot.org
Tue Mar 6 18:57:18 EET 2007


Update of /var/lib/cvs/dovecot/src/deliver
In directory talvi:/tmp/cvs-serv11477

Modified Files:
      Tag: branch_1_0
	smtp-client.c 
Log Message:
Drop out DEBUG environment before calling sendmail binary.



Index: smtp-client.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/deliver/smtp-client.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -d -r1.1.2.1 -r1.1.2.2
--- smtp-client.c	11 Jun 2006 11:10:55 -0000	1.1.2.1
+++ smtp-client.c	6 Mar 2007 16:57:16 -0000	1.1.2.2
@@ -1,9 +1,12 @@
 /* Copyright (C) 2006 Timo Sirainen */
 
 #include "lib.h"
+#include "array.h"
+#include "env-util.h"
 #include "deliver.h"
 #include "smtp-client.h"
 
+#include <stdlib.h>
 #include <unistd.h>
 #include <sys/wait.h>
 
@@ -24,6 +27,28 @@
 	return client;
 }
 
+static void smtp_env_clean(void)
+{
+	extern char **environ;
+	char **p;
+	array_t ARRAY_DEFINE(new_env, char *);
+	unsigned int i, count;
+
+	/* copy the environment, but drop out the unwanted fields. */
+	ARRAY_CREATE(&new_env, pool_datastack_create(), char *, 128);
+	for (p = environ; *p != NULL; p++) {
+		if (strncmp(*p, "DEBUG=", 6) != 0)
+			array_append(&new_env, p, 1);
+	}
+
+	/* then recreate the environment */
+	env_clean();
+
+	p = array_get_modifyable(&new_env, &count);
+	for (i = 0; i < count; i++)
+		env_put(p[i]);
+}
+
 static void smtp_client_run_sendmail(const char *destination,
 				     const char *return_path, int fd)
 {
@@ -41,6 +66,14 @@
 	if (dup2(fd, STDIN_FILENO) < 0)
 		i_fatal("dup2() failed: %m");
 
+	if (getenv("DEBUG") != NULL) {
+		/* Postfix's sendmail binary uses DEBUG environment for its own
+		   purposes, which pretty much break things. Remove it before
+		   continuing. FIXME: Perhaps the whole environment could be
+		   cleaned? */
+		smtp_env_clean();
+	}
+
 	(void)execv(deliver_set->sendmail_path, (char **)argv);
 	i_fatal("execv(%s) failed: %m", deliver_set->sendmail_path);
 }



More information about the dovecot-cvs mailing list