简单的测试程序来说明想法:
“MyBuildSecurityDescriptor”是从此处复制的用于创建基本安全描述符的函数。
PSECURITY_DESCRIPTOR pSecDesc = MyBuildSecurityDescriptor();
// Convert to a PISECURITY_DESCRIPTOR to view the contents.
PISECURITY_DESCRIPTOR piSecDesc = (PISECURITY_DESCRIPTOR)pSecDesc;
LPTSTR szSecDesc;
ConvertSecurityDescriptorToStringSecurityDescriptor(pSecDesc, SECURITY_DESCRIPTOR_REVISION,
DACL_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
&szSecDesc,
NULL);
// At this point szSecDesc has the correct security descriptor in it.
// "D:(A;;KR;;;WD)(A;;KA;;;BA)" for those interested.
// Now to convert back from string version.
PSECURITY_DESCRIPTOR pSecurityDescriptor;
ConvertStringSecurityDescriptorToSecurityDescriptor(szSecDesc, SDDL_REVISION_1, &pSecurityDescriptor, NULL);
// Convert to a PISECURITY_DESCRIPTOR to view the contents.
PISECURITY_DESCRIPTOR piNewSecDesc = (PISECURITY_DESCRIPTOR)pSecurityDescriptor;
这是上述程序 的piSecDesc和piNewSecDesc在 Visual Studio 中的调试视图;
所以我的问题是为什么转换后的 SECURITY_DESCRIPTOR 没有正确的数据?
鉴于此状态(关于 ConverStringSecurityDescriptorToSecurityDescriptor)“此函数检索 ConvertSecurityDescriptorToStringSecurityDescriptor 函数转换为字符串格式的安全描述符。” 我会假设这个简单的程序会起作用。
一些上下文 我的工作需要我检索一个 SECURITY_DESCRIPTOR,然后通过管道将它传递给另一个程序。似乎最简单的方法是转换为字符串,将其传递,然后再转换回另一端。