diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 1999-08-23 05:02:50 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 1999-08-23 05:02:50 +0000 |
commit | 60ccf8d72a19f453e51e83acee6f9f926fc7796d (patch) | |
tree | f63f269652505b9360375355016d261e0dfa8f5f /util.c | |
parent | 3358ec863380e39c3647b6a8578d7f9bea7b6b0e (diff) |
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).
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@553 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -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 <gerald@zing.org> @@ -45,6 +45,14 @@ #include <unistd.h> #endif +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif + #ifdef NEED_SNPRINTF_H # ifdef HAVE_STDARG_H # include <stdarg.h> @@ -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; |