- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的场景如下:使用 CreateNamedPipe()
创建命名管道对象的过程具有管理员权限,但客户端进程“连接”到它 CreateFile()
才不是。通过 NULL
作为 CreateNamedPipe()
的最后一个参数似乎默认为仅管理员访问权限。
作为 hack,我尝试做一个服务器端 ImpersonateLoggedOnUser()
/RevertToSelf()
管道相关代码期间的方法,但它失败了。在我看来,最好的办法就是实际设置一个合适的 SECURITY_ATTRIBUTES
结构到 CreateNamedPipe()
的最后一个参数,但我不知道该怎么做。
MSDN example有一个与注册表项操作有关的示例,但我缺乏根据我的目的调整该示例的专业知识。
这是我试过的:
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()
.这里有什么问题?
最佳答案
您可以将描述符的 DACL 设置为 NULL,以允许任何人访问管道:
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (!pSD)
{
...
}
if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
{
...
}
if (!SetSecurityDescriptorDacl(pSD, TRUE, NULL, FALSE))
{
...
}
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
... = CreateNamedPipe(..., &sa);
关于c++ - SECURITY_ATTRIBUTES 结构和 CreateNamedPipe(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38412919/
程式码片段: void RunThread(void* unused_args) { PSECURITY_DESCRIPTOR sdsc; ULONG size; Conver
我需要为客户端和服务器(在同一主机)之间的通信创建命名管道,代码如下: WCHAR wszPipeName[MAX_FILE_LENGTH]; swprintf_s(wszPipeName, MAX_
我的场景如下:使用 CreateNamedPipe() 创建命名管道对象的过程具有管理员权限,但客户端进程“连接”到它 CreateFile()才不是。通过 NULL作为 CreateNamedPip
我正在尝试使用 Windows API CreateNamedPipe 创建一个双工命名管道,以用于我的 shell 扩展和我的主桌面应用程序之间的 IPC。 对于 Vista 及更高版本,您可以传递
我多久可以销毁传递给 CreateNamedPipe() 的 lpSecurityAttributes 指向的结构? 是否需要为每个管道实例单独设置一个? CreateNamedPipe() 的 MS
我想执行任意命令行应用程序并在生成时读取其标准输出。我用 CreateNamedPipe创建一个管道,然后将另一端(打开使用 CreateFile)供应到 CreateProcess .如果目标进程没
我是一名优秀的程序员,十分优秀!