aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssh/openbsd-compat/mktemp.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/openbsd-compat/mktemp.c')
-rw-r--r--crypto/openssh/openbsd-compat/mktemp.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/crypto/openssh/openbsd-compat/mktemp.c b/crypto/openssh/openbsd-compat/mktemp.c
index 4eb52f421b72..cca956a51f65 100644
--- a/crypto/openssh/openbsd-compat/mktemp.c
+++ b/crypto/openssh/openbsd-compat/mktemp.c
@@ -34,7 +34,30 @@
#include <ctype.h>
#include <unistd.h>
-#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
+#ifdef mkstemp
+#undef mkstemp
+#endif
+int mkstemp(char *);
+
+/*
+ * From glibc man page: 'In glibc versions 2.06 and earlier, the file is
+ * created with permissions 0666, that is, read and write for all users.'
+ * Provide a wrapper to make sure the mask is reasonable (POSIX requires
+ * mode 0600, so mask off any other bits).
+ */
+int
+_ssh_mkstemp(char *template)
+{
+ mode_t mask;
+ int ret;
+
+ mask = umask(0177);
+ ret = mkstemp(template);
+ (void)umask(mask);
+ return ret;
+}
+
+#if !defined(HAVE_MKDTEMP)
#define MKTEMP_NAME 0
#define MKTEMP_FILE 1
@@ -138,4 +161,4 @@ mkdtemp(char *path)
return(error ? NULL : path);
}
-#endif /* !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) */
+#endif /* !defined(HAVE_MKDTEMP) */