2020-07-14 16:10:39 -07:00
|
|
|
From ee7a43bf36722acba4c870409fc15ea5bdf4a80b Mon Sep 17 00:00:00 2001
|
2017-05-27 09:47:06 -07:00
|
|
|
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
|
|
|
|
Date: Fri, 26 May 2017 05:17:17 +0200
|
2020-06-12 16:15:13 -07:00
|
|
|
Subject: [PATCH] ntdll: Implement opening files through nt device paths.
|
2017-05-27 09:47:06 -07:00
|
|
|
|
|
|
|
---
|
2020-04-01 16:08:55 -07:00
|
|
|
dlls/ntdll/tests/file.c | 25 +++++++-
|
2020-07-09 21:17:40 -07:00
|
|
|
dlls/ntdll/unix/file.c | 122 +++++++++++++++++++++++++++++++++++++++-
|
|
|
|
2 files changed, 145 insertions(+), 2 deletions(-)
|
2017-05-27 09:47:06 -07:00
|
|
|
|
2020-06-12 16:15:13 -07:00
|
|
|
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
|
2020-07-09 21:17:40 -07:00
|
|
|
index 6164b0c4bde..6610edbd042 100644
|
2020-06-12 16:15:13 -07:00
|
|
|
--- a/dlls/ntdll/tests/file.c
|
|
|
|
+++ b/dlls/ntdll/tests/file.c
|
|
|
|
@@ -135,18 +135,22 @@ static void WINAPI apc( void *arg, IO_STATUS_BLOCK *iosb, ULONG reserved )
|
|
|
|
|
|
|
|
static void create_file_test(void)
|
|
|
|
{
|
|
|
|
+ static const WCHAR notepadW[] = {'n','o','t','e','p','a','d','.','e','x','e',0};
|
|
|
|
static const WCHAR systemrootW[] = {'\\','S','y','s','t','e','m','R','o','o','t',
|
|
|
|
'\\','f','a','i','l','i','n','g',0};
|
|
|
|
+ static const WCHAR systemrootExplorerW[] = {'\\','S','y','s','t','e','m','R','o','o','t',
|
|
|
|
+ '\\','e','x','p','l','o','r','e','r','.','e','x','e',0};
|
|
|
|
static const WCHAR questionmarkInvalidNameW[] = {'a','f','i','l','e','?',0};
|
|
|
|
static const WCHAR pipeInvalidNameW[] = {'a','|','b',0};
|
|
|
|
static const WCHAR pathInvalidNtW[] = {'\\','\\','?','\\',0};
|
|
|
|
static const WCHAR pathInvalidNt2W[] = {'\\','?','?','\\',0};
|
|
|
|
static const WCHAR pathInvalidDosW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\',0};
|
|
|
|
static const char testdata[] = "Hello World";
|
|
|
|
+ static const WCHAR sepW[] = {'\\',0};
|
|
|
|
FILE_NETWORK_OPEN_INFORMATION info;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE dir, file;
|
|
|
|
- WCHAR path[MAX_PATH];
|
|
|
|
+ WCHAR path[MAX_PATH], temp[MAX_PATH];
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
@@ -327,6 +331,25 @@ static void create_file_test(void)
|
|
|
|
status = pNtQueryFullAttributesFile( &attr, &info );
|
|
|
|
ok( status == STATUS_OBJECT_NAME_INVALID,
|
|
|
|
"query %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
|
|
|
|
+
|
|
|
|
+ GetWindowsDirectoryW( path, MAX_PATH );
|
|
|
|
+ path[2] = 0;
|
|
|
|
+ ok( QueryDosDeviceW( path, temp, MAX_PATH ),
|
|
|
|
+ "QueryDosDeviceW failed with error %u\n", GetLastError() );
|
|
|
|
+ lstrcatW( temp, sepW );
|
|
|
|
+ lstrcatW( temp, path+3 );
|
|
|
|
+ lstrcatW( temp, sepW );
|
|
|
|
+ lstrcatW( temp, notepadW );
|
|
|
|
+
|
|
|
|
+ pRtlInitUnicodeString( &nameW, temp );
|
|
|
|
+ status = pNtQueryFullAttributesFile( &attr, &info );
|
|
|
|
+ ok( status == STATUS_SUCCESS,
|
|
|
|
+ "query %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
|
|
|
|
+
|
|
|
|
+ pRtlInitUnicodeString( &nameW, systemrootExplorerW );
|
|
|
|
+ status = pNtQueryFullAttributesFile( &attr, &info );
|
|
|
|
+ ok( status == STATUS_SUCCESS,
|
|
|
|
+ "query %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void open_file_test(void)
|
|
|
|
diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c
|
2020-07-14 16:10:39 -07:00
|
|
|
index b6529241739..74f3f707444 100644
|
2020-06-12 16:15:13 -07:00
|
|
|
--- a/dlls/ntdll/unix/file.c
|
|
|
|
+++ b/dlls/ntdll/unix/file.c
|
2020-07-14 16:10:39 -07:00
|
|
|
@@ -3250,7 +3250,7 @@ static NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, char *
|
2020-07-09 21:17:40 -07:00
|
|
|
* element doesn't have to exist; in that case STATUS_NO_SUCH_FILE is
|
|
|
|
* returned, but the unix name is still filled in properly.
|
2017-05-27 09:47:06 -07:00
|
|
|
*/
|
2020-07-09 21:17:40 -07:00
|
|
|
-NTSTATUS nt_to_unix_file_name( const UNICODE_STRING *nameW, char **unix_name_ret, UINT disposition )
|
|
|
|
+static NTSTATUS nt_to_unix_file_name_internal( const UNICODE_STRING *nameW, char **unix_name_ret, UINT disposition )
|
2017-05-27 09:47:06 -07:00
|
|
|
{
|
|
|
|
static const WCHAR unixW[] = {'u','n','i','x'};
|
|
|
|
static const WCHAR pipeW[] = {'p','i','p','e'};
|
2020-07-14 16:10:39 -07:00
|
|
|
@@ -3387,6 +3387,126 @@ NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, char *nam
|
2017-05-27 09:47:06 -07:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
+/* read the contents of an NT symlink object */
|
|
|
|
+static NTSTATUS read_nt_symlink( HANDLE root, UNICODE_STRING *name, WCHAR *target, size_t length )
|
|
|
|
+{
|
|
|
|
+ OBJECT_ATTRIBUTES attr;
|
|
|
|
+ UNICODE_STRING targetW;
|
|
|
|
+ NTSTATUS status;
|
|
|
|
+ HANDLE handle;
|
|
|
|
+
|
|
|
|
+ attr.Length = sizeof(attr);
|
|
|
|
+ attr.RootDirectory = root;
|
|
|
|
+ attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
+ attr.ObjectName = name;
|
|
|
|
+ attr.SecurityDescriptor = NULL;
|
|
|
|
+ attr.SecurityQualityOfService = NULL;
|
|
|
|
+
|
|
|
|
+ if (!(status = NtOpenSymbolicLinkObject( &handle, SYMBOLIC_LINK_QUERY, &attr )))
|
|
|
|
+ {
|
|
|
|
+ targetW.Buffer = target;
|
|
|
|
+ targetW.MaximumLength = (length - 1) * sizeof(WCHAR);
|
|
|
|
+ status = NtQuerySymbolicLinkObject( handle, &targetW, NULL );
|
|
|
|
+ NtClose( handle );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return status;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* try to find dos device based on nt device name */
|
|
|
|
+static NTSTATUS nt_to_dos_device( WCHAR *name, size_t length, WCHAR *device_ret )
|
|
|
|
+{
|
|
|
|
+ static const WCHAR dosdevicesW[] = {'\\','D','o','s','D','e','v','i','c','e','s',0};
|
2020-07-10 19:10:05 -07:00
|
|
|
+ UNICODE_STRING dosdevW = { sizeof(dosdevicesW) - sizeof(WCHAR), sizeof(dosdevicesW), (WCHAR *)dosdevicesW };
|
2017-05-28 02:20:01 -07:00
|
|
|
+ WCHAR symlinkW[MAX_DIR_ENTRY_LEN];
|
2017-05-27 09:47:06 -07:00
|
|
|
+ OBJECT_ATTRIBUTES attr;
|
|
|
|
+ NTSTATUS status;
|
|
|
|
+ char data[1024];
|
|
|
|
+ HANDLE handle;
|
|
|
|
+ ULONG ctx = 0;
|
|
|
|
+
|
|
|
|
+ DIRECTORY_BASIC_INFORMATION *info = (DIRECTORY_BASIC_INFORMATION *)data;
|
|
|
|
+
|
|
|
|
+ attr.Length = sizeof(attr);
|
|
|
|
+ attr.RootDirectory = 0;
|
|
|
|
+ attr.ObjectName = &dosdevW;
|
|
|
|
+ attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
+ attr.SecurityDescriptor = NULL;
|
|
|
|
+ attr.SecurityQualityOfService = NULL;
|
|
|
|
+
|
|
|
|
+ status = NtOpenDirectoryObject( &handle, FILE_LIST_DIRECTORY, &attr );
|
|
|
|
+ if (status) return STATUS_BAD_DEVICE_TYPE;
|
|
|
|
+
|
|
|
|
+ while (!NtQueryDirectoryObject( handle, info, sizeof(data), TRUE, FALSE, &ctx, NULL ))
|
|
|
|
+ {
|
2017-05-28 02:20:01 -07:00
|
|
|
+ if (read_nt_symlink( handle, &info->ObjectName, symlinkW, MAX_DIR_ENTRY_LEN )) continue;
|
2020-04-01 16:08:55 -07:00
|
|
|
+ if (wcsnicmp( symlinkW, name, length )) continue;
|
2017-05-27 09:47:06 -07:00
|
|
|
+ if (info->ObjectName.Length != 2 * sizeof(WCHAR) || info->ObjectName.Buffer[1] != ':') continue;
|
|
|
|
+
|
|
|
|
+ *device_ret = info->ObjectName.Buffer[0];
|
|
|
|
+ NtClose( handle );
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ NtClose( handle );
|
|
|
|
+ return STATUS_BAD_DEVICE_TYPE;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/******************************************************************************
|
2020-06-12 16:15:13 -07:00
|
|
|
+ * nt_to_unix_file_name (NTDLL.@) Not a Windows API
|
2017-05-27 09:47:06 -07:00
|
|
|
+ *
|
|
|
|
+ * Convert a file name from NT namespace to Unix namespace.
|
|
|
|
+ *
|
|
|
|
+ * If disposition is not FILE_OPEN or FILE_OVERWRITE, the last path
|
|
|
|
+ * element doesn't have to exist; in that case STATUS_NO_SUCH_FILE is
|
|
|
|
+ * returned, but the unix name is still filled in properly.
|
|
|
|
+ */
|
2020-07-11 08:21:36 -07:00
|
|
|
+NTSTATUS nt_to_unix_file_name( const UNICODE_STRING *nameW, char **unix_name_ret,
|
2020-07-07 15:59:50 -07:00
|
|
|
+ UINT disposition )
|
2017-05-27 09:47:06 -07:00
|
|
|
+{
|
2020-04-01 16:08:55 -07:00
|
|
|
+ static const WCHAR systemrootW[] = {'\\','S','y','s','t','e','m','R','o','o','t','\\',0};
|
2017-05-27 09:47:06 -07:00
|
|
|
+ static const WCHAR dosprefixW[] = {'\\','?','?','\\'};
|
2020-04-01 16:08:55 -07:00
|
|
|
+ static const WCHAR deviceW[] = {'\\','D','e','v','i','c','e','\\',0};
|
2017-05-27 09:47:06 -07:00
|
|
|
+ WCHAR *name, *ptr, *prefix, buffer[3] = {'c',':',0};
|
|
|
|
+ UNICODE_STRING dospathW;
|
|
|
|
+ size_t offset, name_len;
|
|
|
|
+ NTSTATUS status;
|
|
|
|
+
|
2020-04-01 16:08:55 -07:00
|
|
|
+ if (!wcsnicmp( nameW->Buffer, deviceW, nameW->Length / sizeof(WCHAR) ))
|
2017-05-27 09:47:06 -07:00
|
|
|
+ {
|
|
|
|
+ offset = sizeof(deviceW) / sizeof(WCHAR);
|
|
|
|
+ while (offset * sizeof(WCHAR) < nameW->Length && nameW->Buffer[ offset ] != '\\') offset++;
|
|
|
|
+ if ((status = nt_to_dos_device( nameW->Buffer, offset, buffer ))) return status;
|
|
|
|
+ prefix = buffer;
|
|
|
|
+ }
|
2020-04-01 16:08:55 -07:00
|
|
|
+ else if (!wcsnicmp( nameW->Buffer, systemrootW, nameW->Length / sizeof(WCHAR) ))
|
2017-05-27 09:47:06 -07:00
|
|
|
+ {
|
|
|
|
+ offset = (sizeof(systemrootW) - 1) / sizeof(WCHAR);
|
|
|
|
+ prefix = user_shared_data->NtSystemRoot;
|
|
|
|
+ }
|
|
|
|
+ else
|
2020-07-07 15:59:50 -07:00
|
|
|
+ return nt_to_unix_file_name_internal( nameW, unix_name_ret, disposition );
|
2017-05-27 09:47:06 -07:00
|
|
|
+
|
2020-03-31 23:08:26 -07:00
|
|
|
+ name_len = sizeof(dosprefixW) + wcslen(prefix) * sizeof(WCHAR) +
|
2017-05-27 09:47:06 -07:00
|
|
|
+ nameW->Length - offset * sizeof(WCHAR) + sizeof(WCHAR);
|
2020-07-14 16:10:39 -07:00
|
|
|
+ if (!(name = malloc( name_len )))
|
2017-05-27 09:47:06 -07:00
|
|
|
+ return STATUS_NO_MEMORY;
|
|
|
|
+
|
|
|
|
+ ptr = name;
|
|
|
|
+ memcpy( ptr, dosprefixW, sizeof(dosprefixW) );
|
|
|
|
+ ptr += sizeof(dosprefixW) / sizeof(WCHAR);
|
2020-03-31 23:08:26 -07:00
|
|
|
+ wcscpy( ptr, prefix );
|
|
|
|
+ ptr += wcslen(ptr);
|
2017-05-27 09:47:06 -07:00
|
|
|
+ memcpy( ptr, nameW->Buffer + offset, nameW->Length - offset * sizeof(WCHAR) );
|
|
|
|
+ ptr[ nameW->Length / sizeof(WCHAR) - offset ] = 0;
|
|
|
|
+
|
2020-07-10 19:10:05 -07:00
|
|
|
+ dospathW.Buffer = name;
|
|
|
|
+ dospathW.Length = wcslen( name ) * sizeof(WCHAR);
|
2020-07-07 15:59:50 -07:00
|
|
|
+ status = nt_to_unix_file_name_internal( &dospathW, unix_name_ret, disposition );
|
2017-05-27 09:47:06 -07:00
|
|
|
+
|
2020-07-14 16:10:39 -07:00
|
|
|
+ free( name );
|
2017-05-27 09:47:06 -07:00
|
|
|
+ return status;
|
|
|
|
+}
|
|
|
|
|
2020-06-16 17:03:04 -07:00
|
|
|
/******************************************************************
|
|
|
|
* unix_to_nt_file_name
|
2017-05-27 09:47:06 -07:00
|
|
|
--
|
2020-06-12 16:15:13 -07:00
|
|
|
2.27.0
|
2017-05-27 09:47:06 -07:00
|
|
|
|