Provide fallback code for non-portable clearenv(3)
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>
Wed, 27 Apr 2016 16:01:51 +0000 (18:01 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 28 Apr 2016 22:12:02 +0000 (00:12 +0200)
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@wxcvbn.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Fri Apr 29 00:12:02 CEST 2016 on sn-devel-144

source3/client/smbspool_krb5_wrapper.c
source3/wscript

index e19fd92dc5ba31bdab3125c44c7d9a4665264cf3..89db5e056178c63d9c64eb6a8e2e880761fc5bf6 100644 (file)
@@ -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);
index 3118e28dc64b53e114f311c9390af38536e6b2be..3b6f8a49e42e97651c2c94fd4d2dad8d12955383 100644 (file)
@@ -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')