Alexandre Julliard : ntdll: Return a correct name also for file objects in NtQueryObject.
Alexandre Julliard
julliard at winehq.org
Fri Jan 8 10:28:57 CST 2010
Module: wine
Branch: master
Commit: 574eace36eaf555d568216c0a01ecdbcc204f532
URL: http://source.winehq.org/git/wine.git/?a=commit;h=574eace36eaf555d568216c0a01ecdbcc204f532
Author: Alexandre Julliard <julliard at winehq.org>
Date: Fri Jan 8 13:16:57 2010 +0100
ntdll: Return a correct name also for file objects in NtQueryObject.
---
dlls/ntdll/file.c | 2 +-
dlls/ntdll/ntdll_misc.h | 1 +
dlls/ntdll/om.c | 28 ++++++++++++++++++++++++++++
dlls/ntdll/tests/om.c | 13 +++++++++++++
4 files changed, 43 insertions(+), 1 deletions(-)
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index b81d38c..741395d 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -1633,7 +1633,7 @@ NTSTATUS fill_stat_info( const struct stat *st, void *ptr, FILE_INFORMATION_CLAS
return STATUS_SUCCESS;
}
-static NTSTATUS server_get_unix_name( HANDLE handle, ANSI_STRING *unix_name )
+NTSTATUS server_get_unix_name( HANDLE handle, ANSI_STRING *unix_name )
{
data_size_t size = 1024;
NTSTATUS ret;
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index e1e67ea..32966b7 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -142,6 +142,7 @@ extern NTSTATUS TAPE_DeviceIoControl(HANDLE hDevice,
struct stat;
extern NTSTATUS FILE_GetNtStatus(void);
extern NTSTATUS fill_stat_info( const struct stat *st, void *ptr, FILE_INFORMATION_CLASS class );
+extern NTSTATUS server_get_unix_name( HANDLE handle, ANSI_STRING *unix_name );
extern void DIR_init_windows_dir( const WCHAR *windir, const WCHAR *sysdir );
extern BOOL DIR_is_hidden_file( const UNICODE_STRING *name );
extern NTSTATUS DIR_unmount_device( HANDLE handle );
diff --git a/dlls/ntdll/om.c b/dlls/ntdll/om.c
index e9677d0..c5d9b84 100644
--- a/dlls/ntdll/om.c
+++ b/dlls/ntdll/om.c
@@ -88,6 +88,34 @@ NTSTATUS WINAPI NtQueryObject(IN HANDLE handle,
case ObjectNameInformation:
{
OBJECT_NAME_INFORMATION* p = ptr;
+ ANSI_STRING unix_name;
+
+ /* first try as a file object */
+
+ if (!(status = server_get_unix_name( handle, &unix_name )))
+ {
+ UNICODE_STRING nt_name;
+ NTSTATUS status;
+
+ if (!(status = wine_unix_to_nt_file_name( &unix_name, &nt_name )))
+ {
+ if (sizeof(*p) + nt_name.MaximumLength <= len)
+ {
+ p->Name.Buffer = (WCHAR *)(p + 1);
+ p->Name.Length = nt_name.Length;
+ p->Name.MaximumLength = nt_name.MaximumLength;
+ memcpy( p->Name.Buffer, nt_name.Buffer, nt_name.MaximumLength );
+ }
+ else status = STATUS_INFO_LENGTH_MISMATCH;
+ if (used_len) *used_len = sizeof(*p) + nt_name.MaximumLength;
+ RtlFreeUnicodeString( &nt_name );
+ }
+ RtlFreeAnsiString( &unix_name );
+ break;
+ }
+ else if (status != STATUS_OBJECT_TYPE_MISMATCH) break;
+
+ /* not a file, treat as a generic object */
SERVER_START_REQ( get_object_info )
{
diff --git a/dlls/ntdll/tests/om.c b/dlls/ntdll/tests/om.c
index cf9a1a5..1bab21d 100644
--- a/dlls/ntdll/tests/om.c
+++ b/dlls/ntdll/tests/om.c
@@ -627,6 +627,7 @@ static void test_query_object(void)
NTSTATUS status;
ULONG len;
UNICODE_STRING *str;
+ char dir[MAX_PATH];
handle = CreateEventA( NULL, FALSE, FALSE, "test_event" );
@@ -667,6 +668,18 @@ static void test_query_object(void)
ok( str->Length == 0, "unexpected len %u\n", len );
ok( str->Buffer == NULL, "unexpected ptr %p\n", str->Buffer );
pNtClose( handle );
+
+ GetWindowsDirectoryA( dir, MAX_PATH );
+ handle = CreateFileA( dir, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS, 0 );
+ len = 0;
+ status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
+ ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
+ ok( len > sizeof(UNICODE_STRING), "unexpected len %u\n", len );
+ str = (UNICODE_STRING *)buffer;
+ ok( sizeof(UNICODE_STRING) + str->Length + sizeof(WCHAR) == len, "unexpected len %u\n", len );
+ trace( "got %s len %u\n", wine_dbgstr_w(str->Buffer), len );
+ pNtClose( handle );
}
START_TEST(om)
More information about the wine-cvs
mailing list