diff --git a/src/cf/functions.m4 b/src/cf/functions.m4 index ac4f5d9375..442f759f14 100644 --- a/src/cf/functions.m4 +++ b/src/cf/functions.m4 @@ -12,6 +12,7 @@ AC_CHECK_FUNCS([ \ getuid \ getrlimit \ issetugid \ + mkdtemp \ mkstemp \ openlog \ poll \ diff --git a/tests/auth/writekeyfile.c b/tests/auth/writekeyfile.c index 2387da062f..a622ce0ad3 100644 --- a/tests/auth/writekeyfile.c +++ b/tests/auth/writekeyfile.c @@ -24,7 +24,7 @@ main(int argc, char **argv) int code; snprintf(buffer, sizeof(buffer), "%s/afs_XXXXXX", gettmpdir()); - mkdtemp(buffer); + afstest_mkdtemp(buffer); dirEnd = buffer + strlen(buffer); /* Create a CellServDB file */ diff --git a/tests/common/common.h b/tests/common/common.h index e1a407c9da..88bd745aab 100644 --- a/tests/common/common.h +++ b/tests/common/common.h @@ -25,6 +25,7 @@ /* config.c */ extern char *afstest_BuildTestConfig(void); extern void afstest_UnlinkTestConfig(char *); +extern char *afstest_mkdtemp(char *template); struct afsconf_dir; extern int afstest_AddDESKeyFile(struct afsconf_dir *dir); diff --git a/tests/common/config.c b/tests/common/config.c index 6a0e3e1ef2..debd71e390 100644 --- a/tests/common/config.c +++ b/tests/common/config.c @@ -61,6 +61,30 @@ unlinkConfigFile(char *dirname, char *filename) { } } +/*! + * Wrapper for mkdtemp + */ + +char * +afstest_mkdtemp(char *template) +{ +#if defined(HAVE_MKDTEMP) + return mkdtemp(template); +#else + /* + * Note that using the following is not a robust replacement + * for mkdtemp as there is a possible race condition between + * creating the name and creating the directory itself. The + * use of this routine is limited to running tests. + */ + if (mktemp(template) == NULL) + return NULL; + if (mkdir(template, 0700)) + return NULL; + return template; +#endif +} + /*! * Build a test configuration directory, containing a CellServDB and ThisCell * file for the "example.org" cell @@ -82,7 +106,7 @@ afstest_BuildTestConfig(void) { if (asprintf(&dir, "%s/afs_XXXXXX", gettmpdir()) == -1) goto fail; - if (mkdtemp(dir) == NULL) + if (afstest_mkdtemp(dir) == NULL) goto fail; /* Work out which IP address to use in our CellServDB. We figure this out