My scenario is the following: the process that creates the named pipe object with CreateNamedPipe()
has administrator privileges, but the client process "connecting" to it with CreateFile()
does not. Passing a NULL
as the last argument to CreateNamedPipe()
appears to default to admin-only access rights.
As a hack, I've tried do a server-side ImpersonateLoggedOnUser()
/RevertToSelf()
method for the duration of the pipe related code, but it fails. Seems to me like the best thing to do here is to actually set a proper SECURITY_ATTRIBUTES
struct to the last parameter of CreateNamedPipe()
, but I'm having trouble figuring out how to do that.
The MSDN example has an example pertaining to registry key manipulation, but I lack the expertise to adapt that to my purposes.
This is what I've tried:
if (!AllocateAndInitializeSid(&SIDAuthWorld, 1,
SECURITY_WORLD_RID,
0, 0, 0, 0, 0, 0, 0,
&pEveryoneSID))
{
_tprintf(_T("AllocateAndInitializeSid Error %u\n"), GetLastError());
ret_val = 0;
goto Cleanup;
}
// Initialize an EXPLICIT_ACCESS structure for an ACE.
// The ACE will allow Everyone read access to the key.
ZeroMemory(&ea, 2 * sizeof(EXPLICIT_ACCESS));
ea[0].grfAccessPermissions = STANDARD_RIGHTS_ALL;
ea[0].grfAccessMode = SET_ACCESS;
ea[0].grfInheritance = NO_INHERITANCE;
ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName = (LPTSTR)pEveryoneSID;
// there's another ACE for administrators in between, but is of no relevance here
dwRes = SetEntriesInAcl(2, ea, NULL, &pACL);
// Initialize a security descriptor.
pSD = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);
if (NULL == pSD)
{
_tprintf(_T("LocalAlloc Error %u\n"), GetLastError());
ret_val = 0;
goto Cleanup;
}
if (!InitializeSecurityDescriptor(pSD,
SECURITY_DESCRIPTOR_REVISION))
{
_tprintf(_T("InitializeSecurityDescriptor Error %u\n"),
GetLastError());
ret_val = 0;
goto Cleanup;
}
// Add the ACL to the security descriptor.
if (!SetSecurityDescriptorDacl(pSD,
TRUE, // bDaclPresent flag
pACL,
FALSE)) // not a default DACL
{
_tprintf(_T("SetSecurityDescriptorDacl Error %u\n"),
GetLastError());
ret_val = 0;
goto Cleanup;
}
// Initialize a security attributes structure.
*sa = new SECURITY_ATTRIBUTES;
(*sa)->nLength = sizeof(SECURITY_ATTRIBUTES);
(*sa)->lpSecurityDescriptor = pSD;
(*sa)->bInheritHandle = FALSE;
Outcome is that client-side gets the error 0x5
(access denied) on CreateFile()
. What is wrong here?