krb5: Allow rename of empty FILE ccaches

This commit is contained in:
Nicolas Williams
2020-03-14 11:25:46 -05:00
parent d725f28384
commit 4c736cbeec

View File

@@ -1543,8 +1543,23 @@ fcc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
{
krb5_error_code ret = 0;
if ((ret = rk_rename(FILENAME(from), FILENAME(to))))
if (TMPFILENAME(from)) {
/*
* If `from' has a temp file and we haven't renamed it into place yet,
* then we should rename TMPFILENAME(from) to FILENAME(to).
*
* This can only happen if we're moving a ccache where only cc config
* entries, or no entries, have been written. That's not likely.
*/
if (rk_rename(TMPFILENAME(from), FILENAME(to))) {
ret = errno;
} else {
free(TMPFILENAME(from));
TMPFILENAME(from) = NULL;
}
} else if ((ret = rk_rename(FILENAME(from), FILENAME(to)))) {
ret = errno;
}
/*
* We need only close from -- we can't destroy it since the rename
* succeeded, which "destroyed" it at its old name.