From: YUBI LEE Date: Fri, 31 Oct 2025 11:26:05 +0000 (+0900) Subject: Make atomic ccache replacement work on Windows X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04816024aadbfd64b5306942e2dfbd757cb05f93;p=thirdparty%2Fkrb5.git Make atomic ccache replacement work on Windows Commit 371f09d4bf4ca0c7ba15c5ef909bc35307ed9cc3 relies on POSIX rename() semantics for atomic ccache replacement. Windows rename() fails if the destination file exists. Add a fallback to ReplaceFile() when this happens. We may be able to do better using FILE_RENAME_FLAG_POSIX_SEMANTICS (added in Windows 10 update 1067) but this should generally suffice. [ghudson@mit.edu: simplified code slightly; rewrote commit message] ticket: 9190 (new) tags: pullup target_version: 1.22-next --- diff --git a/src/lib/krb5/ccache/cc_file.c b/src/lib/krb5/ccache/cc_file.c index 198152a9ec..f34c0f1064 100644 --- a/src/lib/krb5/ccache/cc_file.c +++ b/src/lib/krb5/ccache/cc_file.c @@ -1311,6 +1311,14 @@ fcc_replace(krb5_context context, krb5_ccache id, krb5_principal princ, goto errno_cleanup; st = rename(tmpname, data->filename); +#ifdef _WIN32 + /* Windows cannot rename over an existing file under most circumstances. + * Try ReplaceFile() (which only works if the destination file exists). */ + if (st != 0) { + if (ReplaceFile(data->filename, tmpname, NULL, 0, NULL, NULL)) + st = 0; + } +#endif if (st != 0) goto errno_cleanup; tmpfile_exists = FALSE;