From 40e1417e983743f419aeb7b9e385cfffb5d8d85c Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Wed, 24 May 2017 15:27:02 +0200 Subject: [PATCH] THRIFT-4208 C# NamedPipesServer not really working in some scenarios Client: C# Patch: Jens Geyer --- .../Transport/TNamedPipeServerTransport.cs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs index c1e8400b8a..240f0df6d5 100644 --- a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs +++ b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs @@ -22,9 +22,9 @@ */ using System; -using System.Collections.Generic; using System.IO.Pipes; using System.Threading; +using System.Security.Principal; namespace Thrift.Transport { @@ -68,23 +68,32 @@ private void EnsurePipeInstance() if (stream == null) { var direction = PipeDirection.InOut; - var maxconn = 254; + var maxconn = NamedPipeServerStream.MaxAllowedServerInstances; var mode = PipeTransmissionMode.Byte; var options = asyncMode ? PipeOptions.Asynchronous : PipeOptions.None; - var inbuf = 4096; - var outbuf = 4096; - // TODO: security + const int INBUF_SIZE = 4096; + const int OUTBUF_SIZE = 4096; + + // security + var security = new PipeSecurity(); + security.AddAccessRule( + new PipeAccessRule( + new SecurityIdentifier(WellKnownSidType.WorldSid, null), + PipeAccessRights.Read | PipeAccessRights.Write | PipeAccessRights.Synchronize | PipeAccessRights.CreateNewInstance, + System.Security.AccessControl.AccessControlType.Allow + ) + ); try { - stream = new NamedPipeServerStream(pipeAddress, direction, maxconn, mode, options, inbuf, outbuf); + stream = new NamedPipeServerStream(pipeAddress, direction, maxconn, mode, options, INBUF_SIZE, OUTBUF_SIZE, security); } catch (NotImplementedException) // Mono still does not support async, fallback to sync { if (asyncMode) { options &= (~PipeOptions.Asynchronous); - stream = new NamedPipeServerStream(pipeAddress, direction, maxconn, mode, options, inbuf, outbuf); + stream = new NamedPipeServerStream(pipeAddress, direction, maxconn, mode, options, INBUF_SIZE, OUTBUF_SIZE, security); asyncMode = false; } else