gpt4 book ai didi

c++ - 从 SECURITY_DESCRIPTOR 转换为字符串并再次转换回来不起作用

转载 作者:行者123 更新时间:2023-11-28 07:20:03 25 4
gpt4 key购买 nike

简单的测试程序来说明想法:

“MyBuildSecurityDescriptor”是从 here 复制的函数创建基本安全描述符。

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;

下面是上述程序的 piSecDescpiNewSecDesc 在 vi​​sual studio 中的调试 View ; Debug view of piSecDesc Debug view of piNewSecDesc

所以我的问题是为什么转换后的 SECURITY_DESCRIPTOR 没有正确的数据?

鉴于this声明(关于 ConverStringSecurityDescriptorToSecurityDescriptor)“此函数检索 ConvertSecurityDescriptorToStringSecurityDescriptor 函数转换为字符串格式的安全描述符。”我认为这个简单的程序会起作用。

一些背景我的工作要求我检索一个 SECURITY_DESCRIPTOR,然后通过管道将其传递给另一个程序。最简单的方法似乎是转换为字符串,传递它,然后在另一端转换回来。

最佳答案

我强烈怀疑您看到的差异是因为 MyBuildSecurityDescriptor 构建了一个 absolute security descriptor ,而 ConvertStringSecurityDescriptorToSecurityDescriptor 构建一个 self-relative安全描述符。您可以使用 MakeAbsoluteSD 将自相关安全描述符转换为绝对安全描述符,但老实说,这没有任何意义;所有 Windows API 都接受绝对或自相关的安全描述符。

MSDN explicitly notes在 SECURITY_DESCRIPTOR 结构的描述中:

Because the internal format of a security descriptor can vary, we recommend that applications not modify the SECURITY_DESCRIPTOR structure directly. For creating and manipulating a security descriptor, use the functions listed in See Also.

我会使用 IsValidSecurityDescriptor函数(以及检查返回值)来验证描述符的一致性。

关于c++ - 从 SECURITY_DESCRIPTOR 转换为字符串并再次转换回来不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19642219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com