Commit 6955a298 authored by Erich E. Hoover's avatar Erich E. Hoover Committed by Alexandre Julliard

server: Do not permit FileDispositionInformation to delete a file without write access.

parent 0fabfe7d
......@@ -1507,6 +1507,20 @@ static void test_file_disposition_information(void)
/* 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);
ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
fdi.DoDeleteFile = TRUE;
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment