[PATCH] for clearenv

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Apr 28 10:57:02 UTC 2016


Hi!

Attached find your patch from bug 11864 with my reviewed-by. To
complete the bureaucracy, I've added your Signed-off-by.

Jeremy, feel free to push :-)

Volker

P.S: Isn't this something we might want in libreplace?

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 1439d4d72f72d1f8eb486d07bcfd4dff3263dcdf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= <jca at wxcvbn.org>
Date: Wed, 27 Apr 2016 18:01:51 +0200
Subject: [PATCH] Provide fallback code for non-portable clearenv(3)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

clearenv(3) is a GNU extension that was rejected twice by POSIX,
without an easy, portable alternative.

As the dovecot project notes,
"""
environ = NULL crashes on OSX - and OpenBSD < 6.0
*environ = NULL doesn't work on FreeBSD 7.0
environ = emptyenv doesn't work on Haiku OS
environ = calloc should work everywhere
"""
(source: http://hg.dovecot.org/dovecot-2.0/file/48f90e7e92dc/src/lib/env-util.c)

Bug: https://bugzilla.samba.org/show_bug.cgi?id=11864
Signed-off-by: Jérémie Courrèges-Anglas <jca at wxcvbn.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
---
 source3/client/smbspool_krb5_wrapper.c |    6 ++++++
 source3/wscript                        |    2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/source3/client/smbspool_krb5_wrapper.c b/source3/client/smbspool_krb5_wrapper.c
index e19fd92..89db5e0 100644
--- a/source3/client/smbspool_krb5_wrapper.c
+++ b/source3/client/smbspool_krb5_wrapper.c
@@ -24,6 +24,7 @@
 #include "system/passwd.h"
 
 #include <errno.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <cups/backend.h>
@@ -195,7 +196,12 @@ int main(int argc, char *argv[])
 	 * Make sure we do not have LD_PRELOAD or other security relevant
 	 * environment variables set.
 	 */
+#ifdef HAVE_CLEARENV
 	clearenv();
+#else
+	extern char **environ;
+	environ = calloc(1, sizeof(*environ));
+#endif
 
 	CUPS_SMB_DEBUG("Setting KRB5CCNAME to '%s'", gen_cc);
 	setenv("KRB5CCNAME", gen_cc, 1);
diff --git a/source3/wscript b/source3/wscript
index 3118e28..3b6f8a4 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -110,7 +110,7 @@ def configure(conf):
     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
     conf.CHECK_FUNCS('fdopendir')
     conf.CHECK_FUNCS('fstatat')
-    conf.CHECK_FUNCS('getpwent_r setenv strcasecmp fcvt fcvtl')
+    conf.CHECK_FUNCS('getpwent_r setenv clearenv strcasecmp fcvt fcvtl')
     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
-- 
1.7.9.5



More information about the samba-technical mailing list