From 4857f95803bc23a17c2d1d284701a74140d3e005 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Wed, 11 Nov 2015 01:21:41 +0100 Subject: [PATCH] server: Return STATUS_CANNOT_DELETE when trying to open readonly file with FILE_DELETE_ON_CLOSE. Signed-off-by: Sebastian Lackner Signed-off-by: Alexandre Julliard --- dlls/kernel32/tests/file.c | 4 ---- server/fd.c | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 643054f6284..91abb03854a 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -361,16 +361,12 @@ static void test__lcreat( void ) status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 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 ); - if (!status) CloseHandle( file ); status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 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 ); - if (!status) CloseHandle( file ); status = NtCreateFile( &file, DELETE, &attr, &io, NULL, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, diff --git a/server/fd.c b/server/fd.c index fe778f11eff..e3fe292adef 100644 --- a/server/fd.c +++ b/server/fd.c @@ -1850,6 +1850,15 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode, set_error( err ); 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; if (flags & O_TRUNC) { -- 2.11.4.GIT