summaryrefslogtreecommitdiff
path: root/syscall.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-05-02 08:33:18 +0000
committerAndrew Tridgell <tridge@samba.org>2001-05-02 08:33:18 +0000
commitf62c17e3786ac6643981d9ec68a1cd130ffcf149 (patch)
treec4b5edbfb5515af62387d43a94baa737e4ed54e8 /syscall.c
parent0f621785808f8a5104259171c197fe5e384ab6d9 (diff)
downloadrsync-f62c17e3786ac6643981d9ec68a1cd130ffcf149.tar.gz
rsync-f62c17e3786ac6643981d9ec68a1cd130ffcf149.tar.bz2
rsync-f62c17e3786ac6643981d9ec68a1cd130ffcf149.zip
use mkstemp on systems where it is secure
Diffstat (limited to 'syscall.c')
-rw-r--r--syscall.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/syscall.c b/syscall.c
index 3780bac5..a56eb793 100644
--- a/syscall.c
+++ b/syscall.c
@@ -113,14 +113,27 @@ int do_mkdir(char *fname, mode_t mode)
return mkdir(fname, mode);
}
-char *do_mktemp(char *template)
-{
- if (dry_run) return NULL;
- if (read_only) {errno = EROFS; return NULL;}
-
- /* TODO: Replace this with a good builtin mkstemp, perhaps
- * from OpenBSD. Some glibc versions are buggy. */
- return mktemp(template);
+/* like mkstemp but forces permissions */
+int do_mkstemp(char *template, mode_t perms)
+{
+ if (dry_run) return -1;
+ if (read_only) {errno = EROFS; return -1;}
+
+#if defined(HAVE_SECURE_MKSTEMP) && defined(HAVE_FCHMOD)
+ {
+ int fd = mkstemp(template);
+ if (fd == -1) return -1;
+ if (fchmod(fd, perms) != 0) {
+ close(fd);
+ unlink(template);
+ return -1;
+ }
+ return fd;
+ }
+#else
+ if (!mktemp(template)) return -1;
+ return open(template, O_RDWR|O_EXCL|O_CREAT, perms);
+#endif
}
int do_stat(const char *fname, STRUCT_STAT *st)