[PATCH] server: Allow using \Device\NamedPipe file as RootDirectory for creating named pipes.

Jinoh Kang jinoh.kang.kr at gmail.com
Wed Nov 24 11:49:43 CST 2021


Signed-off-by: Jinoh Kang <jinoh.kang.kr at gmail.com>
---
 dlls/ntdll/tests/om.c | 30 ++++++++++++++++++++++++++++++
 server/named_pipe.c   |  9 ++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/dlls/ntdll/tests/om.c b/dlls/ntdll/tests/om.c
index 77eb58a23b5..1b6d9d2d2d1 100644
--- a/dlls/ntdll/tests/om.c
+++ b/dlls/ntdll/tests/om.c
@@ -197,6 +197,35 @@ static void test_namespace_pipe(void)
     pNtClose(pipe);
 }
 
+static void test_pipe_device_file_as_root(void)
+{
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING str;
+    IO_STATUS_BLOCK iosb;
+    NTSTATUS status;
+    LARGE_INTEGER timeout;
+    HANDLE pipe, root, h;
+
+    pRtlInitUnicodeString(&str, L"\\Device\\NamedPipe");
+    InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
+    status = pNtOpenFile(&root, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, 0);
+    ok(status == STATUS_SUCCESS, "NtOpenFile should have succeeded got %08x\n", status);
+
+    pRtlInitUnicodeString(&str, L"test2\\pipe");
+    InitializeObjectAttributes(&attr, &str, 0, root, NULL);
+    status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
+                                    FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
+    ok(status == STATUS_SUCCESS, "Failed to create NamedPipe(%08x)\n", status);
+
+    h = CreateFileA("\\\\.\\pipe\\test2\\pipe", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
+                    OPEN_EXISTING, 0, 0 );
+    ok(h != INVALID_HANDLE_VALUE, "Failed to open NamedPipe (%u)\n", GetLastError());
+
+    pNtClose(h);
+    pNtClose(pipe);
+    pNtClose(root);
+}
+
 #define check_create_open_dir(parent, name, status) check_create_open_dir_(__LINE__, parent, name, status)
 static void check_create_open_dir_( int line, HANDLE parent, const WCHAR *name, NTSTATUS expect )
 {
@@ -2434,6 +2463,7 @@ START_TEST(om)
 
     test_case_sensitive();
     test_namespace_pipe();
+    test_pipe_device_file_as_root();
     test_name_collisions();
     test_name_limits();
     test_directory();
diff --git a/server/named_pipe.c b/server/named_pipe.c
index 1bbf7f17a3a..22971c4752f 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -1278,13 +1278,20 @@ static struct pipe_end *create_pipe_client( struct named_pipe *pipe, data_size_t
 
 static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent )
 {
-    struct named_pipe_device *dev = (struct named_pipe_device *)parent;
+    struct named_pipe_device *dev;
+
+    if (parent->ops == &named_pipe_device_file_ops)
+    {
+        parent = &((struct named_pipe_device_file *)parent)->device->obj;
+    }
 
     if (parent->ops != &named_pipe_device_ops)
     {
         set_error( STATUS_OBJECT_NAME_INVALID );
         return 0;
     }
+
+    dev = (struct named_pipe_device *)parent;
     namespace_add( dev->pipes, name );
     name->parent = grab_object( parent );
     return 1;
-- 
2.31.1




More information about the wine-devel mailing list