From: Andrew Bartlett Date: Sun, 23 Sep 2012 20:03:31 +0000 (+1000) Subject: lib/replace: Improve mkstemp test in autoconf and waf X-Git-Tag: talloc-2.0.8~183 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0727ad73212ff3cfe7e78249504b0209e082d7c4;p=thirdparty%2Fsamba.git lib/replace: Improve mkstemp test in autoconf and waf On the Sernet-solaris8 host, this test passed in the autoconf build, then failed in the recursive waf build. This newer test should probe the behaviour more closely, by checking we get two distinct, secure files. Andrew Bartlett --- diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4 index d298b9242b5..796069c8ca1 100644 --- a/lib/replace/libreplace.m4 +++ b/lib/replace/libreplace.m4 @@ -212,12 +212,27 @@ AC_TRY_RUN([#include #include main() { struct stat st; - char tpl[20]="/tmp/test.XXXXXX"; - int fd = mkstemp(tpl); - if (fd == -1) exit(1); + char tpl[20]="/tmp/test.XXXXXX"; + char tpl2[20]="/tmp/test.XXXXXX"; + int fd = mkstemp(tpl); + int fd2 = mkstemp(tpl2); + if (fd == -1) { + if (fd2 != -1) { + unlink(tpl2); + } + exit(1); + } + if (fd2 == -1) exit(1); unlink(tpl); + unlink(tpl2); if (fstat(fd, &st) != 0) exit(1); if ((st.st_mode & 0777) != 0600) exit(1); + if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) { + exit(1); + } + if (strcmp(tpl, tpl2) == 0) { + exit(1); + } exit(0); }], libreplace_cv_HAVE_SECURE_MKSTEMP=yes, diff --git a/lib/replace/wscript b/lib/replace/wscript index 2f632e18a7a..58053057d79 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -399,11 +399,26 @@ removeea setea conf.CHECK_CODE(''' struct stat st; char tpl[20]="/tmp/test.XXXXXX"; + char tpl2[20]="/tmp/test.XXXXXX"; int fd = mkstemp(tpl); - if (fd == -1) exit(1); + int fd2 = mkstemp(tpl2); + if (fd == -1) { + if (fd2 != -1) { + unlink(tpl2); + } + exit(1); + } + if (fd2 == -1) exit(1); unlink(tpl); + unlink(tpl2); if (fstat(fd, &st) != 0) exit(1); if ((st.st_mode & 0777) != 0600) exit(1); + if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) { + exit(1); + } + if (strcmp(tpl, tpl2) == 0) { + exit(1); + } exit(0); ''', define='HAVE_SECURE_MKSTEMP',