Commit 4857f958 authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

server: Return STATUS_CANNOT_DELETE when trying to open readonly file with FILE_DELETE_ON_CLOSE.

parent c74bb13d
...@@ -361,16 +361,12 @@ static void test__lcreat( void ) ...@@ -361,16 +361,12 @@ static void test__lcreat( void )
status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0, status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_OPEN, FILE_DELETE_ON_CLOSE | FILE_NON_DIRECTORY_FILE, NULL, 0 ); FILE_OPEN, FILE_DELETE_ON_CLOSE | FILE_NON_DIRECTORY_FILE, NULL, 0 );
todo_wine
ok( status == STATUS_CANNOT_DELETE, "expected STATUS_CANNOT_DELETE, got %08x\n", status ); ok( status == STATUS_CANNOT_DELETE, "expected STATUS_CANNOT_DELETE, got %08x\n", status );
if (!status) CloseHandle( file );
status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0, status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_OPEN, FILE_DELETE_ON_CLOSE | FILE_DIRECTORY_FILE, NULL, 0 ); FILE_OPEN, FILE_DELETE_ON_CLOSE | FILE_DIRECTORY_FILE, NULL, 0 );
todo_wine
ok( status == STATUS_NOT_A_DIRECTORY, "expected STATUS_NOT_A_DIRECTORY, got %08x\n", status ); ok( status == STATUS_NOT_A_DIRECTORY, "expected STATUS_NOT_A_DIRECTORY, got %08x\n", status );
if (!status) CloseHandle( file );
status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0, status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
......
...@@ -1850,6 +1850,15 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode, ...@@ -1850,6 +1850,15 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode,
set_error( err ); set_error( err );
goto error; goto error;
} }
/* can't unlink files if we don't have permission to access */
if ((options & FILE_DELETE_ON_CLOSE) && !(flags & O_CREAT) &&
!(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
{
set_error( STATUS_CANNOT_DELETE );
goto error;
}
fd->closed->unlink = (options & FILE_DELETE_ON_CLOSE) != 0; fd->closed->unlink = (options & FILE_DELETE_ON_CLOSE) != 0;
if (flags & O_TRUNC) if (flags & O_TRUNC)
{ {
......
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