diff options
author | Russ Allbery <rra@stanford.edu> | 2008-01-19 01:14:16 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2008-01-19 01:14:16 +0000 |
commit | 1658725f8812ed0bafffd71a1b566706e91c5e85 (patch) | |
tree | d7876976e329d85bed76cf229c9a4cd658468656 /client/file.c | |
parent | aa57ab48cc9df24ab756b5651959b36a2d81cad3 (diff) |
If -f is used and the output file name with ".new" appended already
exists, unlink it first and then create it safely rather than
truncating it. This is much safer when creating files in a
world-writable directory.
Also add documentation for keytab merging.
Diffstat (limited to 'client/file.c')
-rw-r--r-- | client/file.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/client/file.c b/client/file.c index ce25ab5..17f0f23 100644 --- a/client/file.c +++ b/client/file.c @@ -26,7 +26,10 @@ overwrite_file(const char *name, const void *data, size_t length) int fd; ssize_t status; - fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (access(name, F_OK) == 0) + if (unlink(name) < 0) + sysdie("unable to delete existing file %s", name); + fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd < 0) sysdie("open of %s failed", name); status = write(fd, data, length); |