From 3a37ba6534d588685d1dbd2eb28f753c06815b0f Mon Sep 17 00:00:00 2001 From: Malcolm Date: Wed, 26 Jan 2022 12:00:28 -0800 Subject: [PATCH] Inherit ACLs from parent after rename --- src/wfcopy.c | 22 ++++++++++++++++++++-- src/winfile.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/wfcopy.c b/src/wfcopy.c index 82c63a5e..2a55aa1f 100644 --- a/src/wfcopy.c +++ b/src/wfcopy.c @@ -3348,10 +3348,28 @@ FileMove(LPTSTR pFrom, LPTSTR pTo, PBOOL pbErrorOnDest, BOOL bSilent) *pbErrorOnDest = FALSE; TryAgain: - if (MoveFile((LPTSTR)pFrom, (LPTSTR)pTo)) + if (MoveFile((LPTSTR)pFrom, (LPTSTR)pTo)) { + ACL EmptyAcl; result = 0; - else + + // + // Enable ACL inheritance, updating the ACL on the file from its new + // parent. Note this requires Windows 2000 and above. There's not + // much we can do if it fails, since the rename already occurred. + // + + InitializeAcl(&EmptyAcl, sizeof(EmptyAcl), ACL_REVISION); + SetNamedSecurityInfo((LPTSTR)pTo, + SE_FILE_OBJECT, + DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, + NULL, + NULL, + &EmptyAcl, + NULL); + + } else { result = GetLastError(); + } // try to create the destination if it is not there diff --git a/src/winfile.h b/src/winfile.h index 1568d8ed..8a495fed 100644 --- a/src/winfile.h +++ b/src/winfile.h @@ -27,6 +27,7 @@ #include "fmifs.h" #include #include +#include #include #include "suggest.h" #include "numfmt.h"