server: Correctly implement permission checking for named pipes.
diff --git a/server/named_pipe.c b/server/named_pipe.c
index 750f3bc..d6c1383 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -804,6 +804,7 @@
     struct named_pipe *pipe = (struct named_pipe *)obj;
     struct pipe_server *server;
     struct pipe_client *client;
+    unsigned int pipe_sharing;
     int fds[2];
 
     if (!(server = find_available_server( pipe )))
@@ -812,6 +813,15 @@
         return NULL;
     }
 
+    pipe_sharing = server->pipe->sharing;
+    if (((access & GENERIC_READ) && !(pipe_sharing & FILE_SHARE_READ)) ||
+        ((access & GENERIC_WRITE) && !(pipe_sharing & FILE_SHARE_WRITE)))
+    {
+        set_error( STATUS_ACCESS_DENIED );
+        release_object( server );
+        return NULL;
+    }
+
     if ((client = create_pipe_client( options )))
     {
         if (!socketpair( PF_UNIX, SOCK_STREAM, 0, fds ))