On FreeBSD 10.3 samba 4.3.8 build fails with:
../source3/client/smbspool_krb5_wrapper.c:198:2: error: implicit declaration of function 'clearenv' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
../source3/client/smbspool_krb5_wrapper.c:198:2: note: did you mean 'clearerr'?
/usr/include/stdio.h:237:7: note: 'clearerr' declared here
void clearerr(FILE *);
Well, compiler trues to be too smart, but basically it points out that clearenv() function doesn't exist on FreeBSD.
Manpage for clearenv() says:
The clearenv() function clears the environment of all name-value pairs and sets the value of the external variable environ to NULL.
The clearenv() function returns zero on success, and a nonzero value on failure.
Not in libc4, libc5. In glibc since glibc 2.0.
Various UNIX variants (DG/UX, HP-UX, QNX, ...). POSIX.9 (bindings for FORTRAN77). POSIX.1-1996 did not accept clearenv() and putenv(3), but changed its
mind and scheduled these functions for some later issue of this standard (cf. B.4.6.1). However, POSIX.1-2001 only adds putenv(3), and rejected clearenv().
Used in security-conscious applications. If it is unavailable the assignment
environ = NULL;
will probably do.
The DG/UX and Tru64 man pages write: If environ has been modified by anything other than the putenv(3), getenv(3), or clearenv() functions, then clearenv()
will return an error and the process environment will remain unchanged.
Which again points that it's not fully portable.
Please, consider either proper test for it in the WAF, or add it to the libreplace or just replace with environ = NULL;
This also affects OpenBSD. To work around this I currently use something akin to the attached patch (against master). A rationale for using calloc can be found in the commit message.
But instead of clearing the environment, adding a few selected environment variables and then calling exec*(), one could just use execve(2) which allows passing an environment parameter. execve(2) is specified by POSIX. If there is interest I can cook such a patch for smbspool_krb5_wrapper.
Created attachment 12030 [details]
Replace clearenv with direct manipulation of environ
Oh and, it also affects 4.4.2.
(In reply to Jérémie Courrèges-Anglas from comment #2)
That patch looks fine to me. Can you post it to samba-technical so it can get 2+ team member review and get integrated to master and then back-ported ?
(In reply to Jeremy Allison from comment #4)
Looks like Volker beat me to it!
Any chance to see this land in v4-4? The commits in master are f198abc and e0d8c6b. I can prepare a diff on v4-4-test, if deemed useful.
Created attachment 12117 [details]
patch for 4.4
Comment on attachment 12117 [details]
patch for 4.4
Karolin, please add to 4.4.x.
Thanks. Note that Timur Bakeyev reported this problem on samba-4.3.8, maybe a backport to v4-3-test could be useful too.
(In reply to Guenther Deschner from comment #9)
Pushed to autobuild-v4-4-test.
(In reply to Jérémie Courrèges-Anglas from comment #10)
Patches apply cleanly on current v4-3-test branch.
Could someone please ack the patches for 4.3, please?
Günther, Jeremy, Volker, if someone would comment that the patch is correct for 4.3 also (applies cleanly), it can be included in the upcoming 4.3 maintenance release.
(In reply to Karolin Seeger from comment #11)
Pushed to v4-4-test.
(In reply to Karolin Seeger from comment #13)
> Günther, Jeremy, Volker, if someone would comment that the patch is correct
> for 4.3 also (applies cleanly), it can be included in the upcoming 4.3
> maintenance release.
Yes, the patch makes sense in 4.3 too.
(In reply to Volker Lendecke from comment #15)
Pushed to autobuild-v4-3-test.
(In reply to Karolin Seeger from comment #17)
Pushed to v4-3-test.
Closing out bug report.