From 538c8bc5e8c1e97021d38a7b95e35cef43c9aa80 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 8 Dec 2009 12:19:05 +0100 Subject: [PATCH] ntdll/tests: Add tests for open directories with NtCreateFile and strange options. --- dlls/ntdll/tests/file.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c index 39e71a55847..dff5d9f7dbe 100644 --- a/dlls/ntdll/tests/file.c +++ b/dlls/ntdll/tests/file.c @@ -50,6 +50,7 @@ static NTSTATUS (WINAPI *pRtlWow64EnableFsRedirectionEx)( ULONG, ULONG * ); static NTSTATUS (WINAPI *pNtCreateMailslotFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK, ULONG, ULONG, ULONG, PLARGE_INTEGER ); +static NTSTATUS (WINAPI *pNtCreateFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,PLARGE_INTEGER,ULONG,ULONG,ULONG,ULONG,PVOID,ULONG); static NTSTATUS (WINAPI *pNtOpenFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,ULONG,ULONG); static NTSTATUS (WINAPI *pNtDeleteFile)(POBJECT_ATTRIBUTES ObjectAttributes); static NTSTATUS (WINAPI *pNtReadFile)(HANDLE hFile, HANDLE hEvent, @@ -152,6 +153,84 @@ static void WINAPI apc( void *arg, IO_STATUS_BLOCK *iosb, ULONG reserved ) ok( !reserved, "reserved is not 0: %x\n", reserved ); } +static void create_file_test(void) +{ + NTSTATUS status; + HANDLE dir; + WCHAR path[MAX_PATH]; + OBJECT_ATTRIBUTES attr; + IO_STATUS_BLOCK io; + UNICODE_STRING nameW; + UINT len; + + len = GetCurrentDirectoryW( MAX_PATH, path ); + pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL ); + attr.Length = sizeof(attr); + attr.RootDirectory = 0; + attr.ObjectName = &nameW; + attr.Attributes = OBJ_CASE_INSENSITIVE; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + + /* try various open modes and options on directories */ + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_OPEN, FILE_DIRECTORY_FILE, NULL, 0 ); + ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + CloseHandle( dir ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_CREATE, FILE_DIRECTORY_FILE, NULL, 0 ); + ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED, + "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_OPEN_IF, FILE_DIRECTORY_FILE, NULL, 0 ); + ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + CloseHandle( dir ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_SUPERSEDE, FILE_DIRECTORY_FILE, NULL, 0 ); + ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_OVERWRITE, FILE_DIRECTORY_FILE, NULL, 0 ); + ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_OVERWRITE_IF, FILE_DIRECTORY_FILE, NULL, 0 ); + ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_OPEN, 0, NULL, 0 ); + ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + CloseHandle( dir ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_CREATE, 0, NULL, 0 ); + ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED, + "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_OPEN_IF, 0, NULL, 0 ); + ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + CloseHandle( dir ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_SUPERSEDE, 0, NULL, 0 ); + ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED, + "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_OVERWRITE, 0, NULL, 0 ); + ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED, + "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); + + status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + FILE_OVERWRITE_IF, 0, NULL, 0 ); + ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED, + "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status ); +} + static void open_file_test(void) { NTSTATUS status; @@ -1344,6 +1423,7 @@ START_TEST(file) pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U"); pRtlWow64EnableFsRedirectionEx = (void *)GetProcAddress(hntdll, "RtlWow64EnableFsRedirectionEx"); pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile"); + pNtCreateFile = (void *)GetProcAddress(hntdll, "NtCreateFile"); pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile"); pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile"); pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile"); @@ -1360,6 +1440,7 @@ START_TEST(file) pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile"); pNtQueryDirectoryFile = (void *)GetProcAddress(hntdll, "NtQueryDirectoryFile"); + create_file_test(); open_file_test(); delete_file_test(); read_file_test(); -- 2.11.4.GIT