static krb5_error_code fcc_destroy(krb5_context context, krb5_ccache id) { _krb5_erase_file(context, FILENAME(id)); return 0; }
static krb5_error_code KRB5_CALLCONV fkt_destroy(krb5_context context, krb5_keytab id) { struct fkt_data *d = id->data; _krb5_erase_file(context, d->filename); return 0; }
static krb5_error_code fcc_move(krb5_context context, krb5_ccache from, krb5_ccache to) { krb5_error_code ret = 0; ret = rename(FILENAME(from), FILENAME(to)); if (ret && errno != EXDEV) { ret = errno; krb5_set_error_message(context, ret, N_("Rename of file from %s " "to %s failed: %s", ""), FILENAME(from), FILENAME(to), strerror(ret)); return ret; } else if (ret && errno == EXDEV) { /* make a copy and delete the orignal */ krb5_ssize_t sz1, sz2; int fd1, fd2; char buf[BUFSIZ]; ret = fcc_open(context, from, &fd1, O_RDONLY | O_BINARY | O_CLOEXEC, 0); if(ret) return ret; unlink(FILENAME(to)); ret = fcc_open(context, to, &fd2, O_WRONLY | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC, 0600); if(ret) goto out1; while((sz1 = read(fd1, buf, sizeof(buf))) > 0) { sz2 = write(fd2, buf, sz1); if (sz1 != sz2) { ret = EIO; krb5_set_error_message(context, ret, N_("Failed to write data from one file " "credential cache to the other", "")); goto out2; } } if (sz1 < 0) { ret = EIO; krb5_set_error_message(context, ret, N_("Failed to read data from one file " "credential cache to the other", "")); goto out2; } out2: fcc_unlock(context, fd2); close(fd2); out1: fcc_unlock(context, fd1); close(fd1); _krb5_erase_file(context, FILENAME(from)); if (ret) { _krb5_erase_file(context, FILENAME(to)); return ret; } } /* make sure ->version is uptodate */ { krb5_storage *sp; int fd; ret = init_fcc (context, to, &sp, &fd); if (sp) krb5_storage_free(sp); fcc_unlock(context, fd); close(fd); } fcc_destroy(context, from); return ret; }