From 3a2f97bce980de72f52aaf1f08787f25b73ba755 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 23 Aug 1999 05:02:50 +0000 Subject: The Single UNIX Specification doesn't say that "mkstemp()" creates the temporary file with mode rw-------, so we won't assume that all UNIXes will do so; instead, we set the umask to 0077 to take away all group and other permissions, attempt to create the file, and then put the umask back (puts into "try_tempfile()", called by "create_tempfile()" to create temporary files, the "umask()" calls that Gilbert put into "capture.c" to deal with the same problem). svn path=/trunk/; revision=553 --- util.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index a747ee7ae2..0ecfaa0a35 100644 --- a/util.c +++ b/util.c @@ -1,7 +1,7 @@ /* util.c * Utility routines * - * $Id: util.c,v 1.18 1999/08/18 15:29:06 gram Exp $ + * $Id: util.c,v 1.19 1999/08/23 05:02:50 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -45,6 +45,14 @@ #include #endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef HAVE_SYS_STAT_H +#include +#endif + #ifdef NEED_SNPRINTF_H # ifdef HAVE_STDARG_H # include @@ -201,6 +209,8 @@ try_tempfile(char *namebuf, int namebuflen, const char *dir, const char *pfx) { static const char suffix[] = "XXXXXXXXXX"; int namelen = strlen(namebuf) + strlen(pfx) + sizeof suffix; + mode_t old_umask; + int tmp_fd; if (namebuflen < namelen) { errno = ENAMETOOLONG; @@ -209,7 +219,17 @@ try_tempfile(char *namebuf, int namebuflen, const char *dir, const char *pfx) strcpy(namebuf, dir); strcat(namebuf, pfx); strcat(namebuf, suffix); - return mkstemp(namebuf); + + /* The Single UNIX Specification doesn't say that "mkstemp()" + creates the temporary file with mode rw-------, so we + won't assume that all UNIXes will do so; instead, we set + the umask to 0077 to take away all group and other + permissions, attempt to create the file, and then put + the umask back. */ + old_umask = umask(0077); + tmp_fd = mkstemp(namebuf); + umask(old_umask); + return tmp_fd; } static char *tmpdir = NULL; -- cgit v1.2.3