[Solved] Creating named pipes with non-default permissions
Posted: Fri Sep 10, 2021 1:20 pm
Hi all,
I'm currently working on a project that involves multiple components, one of which is a windows service, and some of which run as the user.
To communicate between these, I've been assuming I could use named pipes and had done quite a bit of testing, proof of concept stuff.
Now that I get to the point where I actually have the service running, I run into a problem that my components running in user space can't talk to it - they get an access denied when trying to connect to the pipe. This is clearly a permissions problem somewhere - if I run the client side with elevation (i.e. run as administrator), it all starts working again.
Up to now, I've been creating the named pipe like this:
The relevant bit is that last #Null in the place of a pointer to a SECURITY_ATTRIBUTES structure.
According to the docs (https://docs.microsoft.com/en-us/window ... namedpipea):
So, I need to construct one of these somehow, but the API for doing so looks impenetrable to me. It looks many layers deep where I have to have a SECURITY_ATTRIBUTES structure that includes pointers to other kinds of structure which in turn include pointers to more structures.
Does anyone happen to have reasonably straightforward existing PB code for assembling one of these structures? It's an area of the Windows API I've managed to steer clear of up to now...
The permissions themselves do not need to be complicated - I just need to allow any process to connect to the pipe and send/receive messages.
I'm currently working on a project that involves multiple components, one of which is a windows service, and some of which run as the user.
To communicate between these, I've been assuming I could use named pipes and had done quite a bit of testing, proof of concept stuff.
Now that I get to the point where I actually have the service running, I run into a problem that my components running in user space can't talk to it - they get an access denied when trying to connect to the pipe. This is clearly a permissions problem somewhere - if I run the client side with elevation (i.e. run as administrator), it all starts working again.
Up to now, I've been creating the named pipe like this:
Code: Select all
handle=CreateNamedPipe_("\\.\pipe\MyPipeName",
#PIPE_ACCESS_DUPLEX | #FILE_FLAG_FIRST_PIPE_INSTANCE,
#PIPE_TYPE_MESSAGE | #PIPE_READMODE_MESSAGE | #PIPE_REJECT_REMOTE_CLIENTS,
1,
65536,
65536,
0,
#Null)
According to the docs (https://docs.microsoft.com/en-us/window ... namedpipea):
That's clearly not enough, and for non-elevated programs to access it, I need to grant more rights to the Everyone group. When the client connects to the pipe, it uses CallNamedPipe_, which requires GENERIC_READ and GENERIC_WRITE.If lpSecurityAttributes is NULL, the named pipe gets a default security descriptor and the handle cannot be inherited. The ACLs in the default security descriptor for a named pipe grant full control to the LocalSystem account, administrators, and the creator owner. They also grant read access to members of the Everyone group and the anonymous account.
So, I need to construct one of these somehow, but the API for doing so looks impenetrable to me. It looks many layers deep where I have to have a SECURITY_ATTRIBUTES structure that includes pointers to other kinds of structure which in turn include pointers to more structures.
Does anyone happen to have reasonably straightforward existing PB code for assembling one of these structures? It's an area of the Windows API I've managed to steer clear of up to now...
The permissions themselves do not need to be complicated - I just need to allow any process to connect to the pipe and send/receive messages.