簡單的測試程序來說明想法:從SECURITY_DESCRIPTOR轉換爲字符串,然後再返回不起作用
「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;
下面是在Visual Studio中調試視圖爲piSecDesc和piNewSecDesc用於上述程序;
所以我的問題是爲什麼轉換後的SECURITY_DESCRIPTOR沒有正確的數據?
鑑於this狀態(關於ConverStringSecurityDescriptorToSecurityDescriptor)「此函數檢索ConvertSecurityDescriptorToStringSecurityDescriptor函數轉換爲字符串格式的安全描述符。」我會假設這個簡單的程序將工作。
一些背景 我的工作需要我檢索一個SECURITY_DESCRIPTOR,然後通過管道傳遞給另一個程序。最簡單的方法似乎是轉換爲字符串,將其傳遞,然後轉換回另一端。
你檢查了Convert函數的返回值嗎? –