From 534f2111ab41ed63024d811a3d8f5b81256d83a9 Mon Sep 17 00:00:00 2001 From: Jon Robertson Date: Tue, 27 Jul 2010 12:40:12 -0700 Subject: 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. --- client/file.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'client/file.c') 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 -- cgit v1.2.3