aboutsummaryrefslogtreecommitdiff
path: root/client/file.c
diff options
context:
space:
mode:
authorJon Robertson <jonrober@stanford.edu>2010-07-27 12:40:12 -0700
committerJon Robertson <jonrober@stanford.edu>2010-07-27 12:40:12 -0700
commit534f2111ab41ed63024d811a3d8f5b81256d83a9 (patch)
tree7419aed995a22abee9a4418c8287b1551b693051 /client/file.c
parentc75eb196a37ce8ca1acd791267cfb36ee30fdcdb (diff)
Adding wallet rekey capability -- work in progress, testing
First, testing version of wallet rekey code, committed in order to get feedback from Russ. This code will eventually take an existing keytab file, and for every principal belonging to our default realm in it, get new versions of that keytab and merge them into the file. This allows for quietly rekeying principals automatically.
Diffstat (limited to 'client/file.c')
-rw-r--r--client/file.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/client/file.c b/client/file.c
index 66d5f63..f24d3ca 100644
--- a/client/file.c
+++ b/client/file.c
@@ -46,6 +46,32 @@ overwrite_file(const char *name, const void *data, size_t length)
sysdie("close of %s failed (file probably truncated)", name);
}
+/*
+ * Given a filename, some data, and a length, write that data to the given
+ * file safely, but overwrite any existing file by that name.
+ */
+void
+append_file(const char *name, const void *data, size_t length)
+{
+ int fd;
+ ssize_t status;
+
+ if (access(name, F_OK) == 0)
+ if (unlink(name) < 0)
+ sysdie("unable to delete existing file %s", name);
+ fd = open(name, O_WRONLY | O_APPEND);
+ if (fd < 0)
+ sysdie("open of %s failed", name);
+ if (length > 0) {
+ status = write(fd, data, length);
+ if (status < 0)
+ sysdie("write to %s failed", name);
+ else if (status != (ssize_t) length)
+ die("write to %s truncated", name);
+ }
+ if (close(fd) < 0)
+ sysdie("close of %s failed (file probably truncated)", name);
+}
/*
* Given a filename, some data, and a length, write that data to the given