]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
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)
committerKarolin Seeger <kseeger@samba.org>
Wed, 1 Jun 2016 09:41:23 +0000 (11:41 +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

(cherry picked from commit f198abcbb3f6e8b26c697d3ded2caa1076ae018b)

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 e201710895d295455d353dc91f1edcce816e4f3b..beb3dab444574e427042d2666f59c89d4734e04f 100644 (file)
@@ -92,7 +92,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')