Структура SECURITY_ATTRIBUTES и CreateNamedPipe ()
Мой сценарий следующий: процесс, который создает объект именованного канала сCreateNamedPipe()
имеет права администратора, но клиентский процесс «подключается» к нему сCreateFile()
не. ПроходяNULL
в качестве последнего аргументаCreateNamedPipe()
По умолчанию отображается только для прав администратора.
Как хак, я попытался сделать на стороне сервераImpersonateLoggedOnUser()
/RevertToSelf()
метод для продолжительности кода, связанного с каналом, но он не работает. Мне кажется, что лучше всего здесь сделатьSECURITY_ATTRIBUTES
структура до последнего параметраCreateNamedPipe()
, но у меня проблемы с выяснением, как это сделать.
Пример MSDN Есть пример, относящийся к манипулированию ключами реестра, но мне не хватает опыта, чтобы приспособить его к моим целям.
Вот что я пробовал:
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;
В результате клиентская сторона получает ошибку0x5
(доступ запрещен) включенCreateFile()
, Что здесь не так?