[PATCH 4/4] kernel32: Open replaced file without GENERIC_WRITE in ReplaceFileW().

Zhiyi Zhang zzhang at codeweavers.com
Tue Apr 9 09:09:37 CDT 2019



On 4/9/19 9:41 PM, Dmitry Timoshkov wrote:
> Zhiyi Zhang <zzhang at codeweavers.com> wrote:
>
>> And then we also need to check if the replaced file has readonly attributes
>> now that GENERIC_WRITE is gone. It seems fine to add a check in kernel32,
>> otherwise we need add an extra server call to rename files and checking
>> the attribute in wineserver.
> I'd guess that NtOpenFile(DELETE) should fail for read-only files making
> this check on client side redundant.
>
NtOpenFile(DELETE) fails for read-only files only when FILE_DELETE_ON_CLOSE is used together.
We can't use FILE_DELETE_ON_CLOSE when opening the replaced file because we need to
keep the file if there is any error.

We also can't use NtOpenFile to open the replaced file first without checking for readonly and later
use NtOpenFile(DELETE) with FILE_DELETE_ON_CLOSE to delete the file. Because such a way will
allow a backup to be created when replaced is readonly and then ReplaceFileW fail. I tested this behavior
but I didn't include it in the tests.



More information about the wine-devel mailing list