server: Don't allow read-only files to be replaced by File{Rename,Link}Information{,Ex}.

Signed-off-by: Joel Holdsworth <joel@airwebreathe.org.uk>
This commit is contained in:
Joel Holdsworth 2023-08-07 11:30:31 +01:00 committed by Alexandre Julliard
parent 08ca54b494
commit a8489d12eb
2 changed files with 15 additions and 8 deletions

View file

@ -2226,9 +2226,9 @@ static void test_file_rename_information_ex(void)
}
todo_wine ok( io.Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %lx\n", io.Status );
todo_wine ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %lx\n", res );
ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %lx\n", res );
fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
todo_wine ok( !fileDeleted, "file should exist\n" );
ok( !fileDeleted, "file should exist\n" );
fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
ok( !fileDeleted, "file should exist\n" );
@ -2259,10 +2259,10 @@ static void test_file_rename_information_ex(void)
io.Status = 0xdeadbeef;
res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformationEx );
ok( io.Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %lx\n", io.Status );
ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %lx\n", res );
todo_wine ok( io.Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %lx\n", io.Status );
todo_wine ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %lx\n", res );
fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
ok( fileDeleted, "file should not exist\n" );
todo_wine ok( fileDeleted, "file should not exist\n" );
fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
ok( !fileDeleted, "file should exist\n" );
@ -3076,7 +3076,7 @@ static void test_file_link_information_ex(void)
return;
}
todo_wine ok( io.Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %lx\n", io.Status );
ok( io.Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %lx\n", io.Status );
todo_wine ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %lx\n", res );
fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
ok( !fileDeleted, "file should exist\n" );
@ -3110,8 +3110,8 @@ static void test_file_link_information_ex(void)
io.Status = 0xdeadbeef;
res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformationEx );
ok( io.Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %lx\n", io.Status );
ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %lx\n", res );
todo_wine ok( io.Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %lx\n", io.Status );
todo_wine ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %lx\n", res );
fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
ok( !fileDeleted, "file should exist\n" );
fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;

View file

@ -2600,6 +2600,13 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr, da
goto failed;
}
/* read-only files cannot be replaced */
if (!(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
{
set_error( STATUS_ACCESS_DENIED );
goto failed;
}
/* can't replace an opened file */
if ((inode = get_inode( st.st_dev, st.st_ino, -1 )))
{