mirror of
https://github.com/reactos/wine.git
synced 2024-11-29 06:30:37 +00:00
server: Do not permit FileDispositionInformation to delete a file without write access.
This commit is contained in:
parent
0fabfe7d6b
commit
6955a298f4
@ -1505,6 +1505,20 @@ static void test_file_disposition_information(void)
|
||||
ok( fileDeleted, "File should have been deleted\n" );
|
||||
DeleteFileA( buffer );
|
||||
|
||||
/* cannot set disposition on readonly file */
|
||||
GetTempFileNameA( tmp_path, "dis", 0, buffer );
|
||||
DeleteFileA( buffer );
|
||||
handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_READONLY, 0);
|
||||
ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
|
||||
fdi.DoDeleteFile = TRUE;
|
||||
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
|
||||
ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
|
||||
CloseHandle( handle );
|
||||
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
|
||||
ok( !fileDeleted, "File shouldn't have been deleted\n" );
|
||||
SetFileAttributesA( buffer, FILE_ATTRIBUTE_NORMAL );
|
||||
DeleteFileA( buffer );
|
||||
|
||||
/* cannot set disposition on readonly file */
|
||||
GetTempFileNameA( tmp_path, "dis", 0, buffer );
|
||||
handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_READONLY, 0);
|
||||
|
@ -2244,6 +2244,13 @@ static void set_fd_disposition( struct fd *fd, int unlink )
|
||||
return;
|
||||
}
|
||||
|
||||
/* can't unlink files we don't have permission to access */
|
||||
if (unlink && !(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
|
||||
{
|
||||
set_error( STATUS_CANNOT_DELETE );
|
||||
return;
|
||||
}
|
||||
|
||||
fd->closed->unlink = unlink || (fd->options & FILE_DELETE_ON_CLOSE);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user