Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NamedPipeClientStream can not access to NamedPipeServerStream under session 0

I have NamedPipeClientStream which connects to NamedPipeServerStream. They exchange a couple of messages, and then NamedPipeClientStream closing, while NamedPipeServerStream recreated and continue listening for the client pipes. (I couldn't make a working async Server Pipe, so this is some kind of dog-nail)

The client-server interaction works fine during my client's streams launched from normal user sessions.

But there are a situation when Client pipe is launched from session 0 on Win7 and win2008 server. When this happens I had an error in Client stream:

"Access to the path is denied"

What is the problem? How to avoid it?

Sorry I can't tell you more info about exception. Only I have is this message in log. And I can't debug my program from zero session, can I?

The server stream code:

PipeSecurity ps = new PipeSecurity();
System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
PipeAccessRule par = new PipeAccessRule(sid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
ps.AddAccessRule(par);
pipeClientConnection = new NamedPipeServerStream(General.PIPENAME, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, General.BUFFERSIZE, General.BUFFERSIZE, ps);
Console.Write("Waiting for client connection...");
IAsyncResult result = pipeClientConnection.BeginWaitForConnection(OnPipeConnected, pipeClientConnection);

Maybe something is wrong with security settings?

And the client code:

using (NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", General.PIPENAME, PipeDirection.InOut))
{
    try
    {
        Console.WriteLine("Connecting with pipe...");
        pipeStream.Connect(General.CONNECTIONTIMEOUT);
        Console.WriteLine("Pipe connection established");
        //..do something..
    }
    //...
}

The server is launched as windows service under LocalSystem. The client - is a simple console application. It's launched by another application launched from LocalSystem service.

like image 612
Ksice Avatar asked Nov 01 '12 09:11

Ksice


2 Answers

Looks like the problem was in security settings here:

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);

Should be :

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);

Thanks microsoft communnity

like image 200
Ksice Avatar answered Sep 22 '22 15:09

Ksice


I know this question is old bit I just ran across this issue and figured I'd add to it.

This error can also indicate that the named pipe is already in use. I had a production service running of the same executable that I was trying to debug, and when initializing that pipe server it failed because it was already in use by another process. Seems like the error should be a little more informative of a situation like this, but it is what it is.

like image 36
Zulukas Avatar answered Sep 26 '22 15:09

Zulukas