RandomEngy / PipeMethodCalls

Lightweight .NET Standard 2.0 library for method calls over named pipes for IPC. Supports two-way communication with callbacks.
https://www.nuget.org/packages/PipeMethodCalls
MIT License
145 stars 24 forks source link

Is it possible to add an argument for the pipe security when creating the pipe #24

Open Marledonna opened 6 months ago

Marledonna commented 6 months ago

I am using the PipeMethodCalls to communicate between a NET core 6 application as PipeServer and a Web API running under IIS as a PipeClient. In this particular situation I get the following error:

{ "ClassName": "System.AggregateException", "Message": "One or more errors occurred.", "Data": null, "InnerException": { "ClassName": "System.UnauthorizedAccessException", "Message": "Access to the path is denied.", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at System.IO.Pipes.NamedPipeClientStream.TryConnect(Int32 timeout, CancellationToken cancellationToken)\r\n at System.IO.Pipes.NamedPipeClientStream.ConnectInternal(Int32 timeout, CancellationToken cancellationToken, Int32 startTime)\r\n at System.IO.Pipes.NamedPipeClientStream.<>cDisplayClass20_0.b0()\r\n at System.Threading.Tasks.Task.InnerInvoke()\r\n at System.Threading.Tasks.Task.<>c.<.cctor>b272_0(Object obj)\r\n at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)\r\n--- End of stack trace from previous location ---\r\n at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)\r\n--- End of stack trace from previous location ---\r\n at PipeMethodCalls.PipeClient`1.ConnectAsync(CancellationToken cancellationToken)", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2147024891, "Source": "System.IO.Pipes", "WatsonBuckets": null }, "HelpURL": null, "StackTraceString": " at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)\r\n at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout)\r\n at PoctWebAPI.Infrastructure.DS.DataStoragePipe.Connect() in C:\Develop\Projects\LeydenDelta\PoctWebApi\PoctWebAPI\Infrastructure\DS\DataStoragePipe.cs:line 115\r\n at PoctWebAPI.Infrastructure.DS.DataStoragePipe.Login(String user, String password, StringBuilder outdata, Int32& outlen) in C:\Develop\Projects\LeydenDelta\PoctWebApi\PoctWebAPI\Infrastructure\DS\DataStoragePipe.cs:line 39\r\n at PoctWebAPI.Controllers.PoctController.Login(LoginRequest request) in C:\Develop\Projects\LeydenDelta\PoctWebApi\PoctWebAPI\Controllers\PoctController.cs:line 97", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2146233088, "Source": "System.Private.CoreLib", "WatsonBuckets": null, "InnerExceptions": [ { "ClassName": "System.UnauthorizedAccessException", "Message": "Access to the path is denied.", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at System.IO.Pipes.NamedPipeClientStream.TryConnect(Int32 timeout, CancellationToken cancellationToken)\r\n at System.IO.Pipes.NamedPipeClientStream.ConnectInternal(Int32 timeout, CancellationToken cancellationToken, Int32 startTime)\r\n at System.IO.Pipes.NamedPipeClientStream.<>cDisplayClass20_0.b0()\r\n at System.Threading.Tasks.Task.InnerInvoke()\r\n at System.Threading.Tasks.Task.<>c.<.cctor>b272_0(Object obj)\r\n at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)\r\n--- End of stack trace from previous location ---\r\n at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)\r\n--- End of stack trace from previous location ---\r\n at PipeMethodCalls.PipeClient`1.ConnectAsync(CancellationToken cancellationToken)", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2147024891, "Source": "System.IO.Pipes", "WatsonBuckets": null } ] }

RandomEngy commented 5 months ago

There is an overload that takes in a NamedPipeClientStream as long as you set PipeOptions.Asynchronous and PipeDirection.InOut on it. That should allow you to set whatever security options you like on the underlying pipe stream.