精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
The question doesn't specify what specific information it wants to be returned in the security descriptor, so we will assume it wants the whole lot returned in the security descriptor (Control, SACL, DACL, Group, and Owner).
In order to read the SACL, you must first have the SeSecurityPrivilege enabled in your token (use the handy SetPrivilege() function from fig. 10 for this).
该问题并未在安全描述符中指定要返回的特定信息,因此我们假设它希望在安全描述符中返回整个批次(控件,SACL,DACL,组和所有者)。
为了读取SACL,必须首先SeSecurityPrivilege在令牌中启用(SetPrivilege()为此使用图10中的便捷功能)。
int GetFolderSecDesc(const CStringT< <TCHAR, ATL::StrTraitATL< <TCHAR> > &FileName) { ATL::CSecurityDesc OutSecDesc; ATL::AtlGetSecurityDescriptor(FileName, SE_FILE_OBJECT, &OutSecDesc); return 0; }
Figure 15: Obtaining the security descriptor for a folder.
GetNamedSecurityInfo() can also be used to read security descriptors from registry keys, kernel objects, window stations, and other objects. For a complete list of objects supported by GetNamedSecurityInfo(), see section 17 or your help documentation for SE_OBJECT_TYPE. If your object is not supported by GetNamedSecurityInfo(), then open a handle yourself (with READ_CONTROL access), and pass it to the GetSecurityInfo() function.
The returned security descriptor will be in self-relative form. If you are going to enumerate the security descriptor, it will be easier if the security descriptor was absolute.
GetNamedSecurityInfo()也可以用于从注册表项,内核对象,窗口站和其他对象中读取安全描述符。有关所支持的对象的完整列表GetNamedSecurityInfo(),请参阅第17节或SE_OBJECT_TYPE 的帮助文档。如果您的对象不受GetNamedSecurityInfo()的支持,请自己打开一个句柄(具有READ_CONTROL访问权限),然后将其传递给GetSecurityInfo()函数。
返回的安全描述符将为自相关形式。如果要枚举安全描述符,则如果安全描述符是绝对的,则将更加容易。
... OutSecDesc.MakeAbsolute(); ...
Figure 16: Converting a self relative security descriptor to an absolute security descriptor.
It's much easier to do the reverse (i.e. convert an absolute security descriptor to a self relative one). The reason is because an absolute security descriptor has to maintain five buffers to work (or in our case, a heap of five pointers), whereas a self relative security descriptor only needs to maintain one buffer. The good news is that unless you need to work with method 1, converting security descriptors is rarely required.
You may have been asking why not allocate a buffer of the same size as the self-relative security descriptor, reinterpret_cast it to an absolute security descriptor, then convert the offset index into physical pointers. The problem is that you are assuming indexes that are of the same size as the pointers. This is not true on Win64, and attempting to do so will lead to errors (yes, Microsoft should have made the DWORD indexes in the self relative security descriptor size agnostic, but now we're stuck with that 17+ year old mistake).
进行相反操作要容易得多(即将绝对安全描述符转换为自相关描述符)。原因是因为绝对安全描述符必须维护五个缓冲区才能工作(或者在我们的示例中是五个指针的堆),而自相关安全描述符仅需要维护一个缓冲区。好消息是,除非您需要使用方法1,否则很少需要转换安全描述符。
您可能一直在问为什么不分配与自安全标识符相同大小的缓冲区,将其分配reinterpret_cast给绝对安全描述符,然后将偏移量索引转换为物理指针。问题是您假设索引的大小与指针的大小相同。在Win64上并非如此,尝试这样做会导致错误(是的,Microsoft应该使DWORD自我相对安全描述符大小中的索引不可知,但现在我们已经陷入了17年以上的错误)。
Although it's not mentioned, this question wants the security descriptor in either debugger form, or SDDL form.
尽管未提及,但此问题希望使用调试器形式或SDDL形式的安全描述符。
... ATL::CString pstr = _T(""); OutSecDesc.ToString(&pstr); std::wcout << static_cast(pstr); ...
Figure 17: Printing out the contents of the security descriptor.
Now that you have the security descriptor presented in a uniform way (SDDL), you have reduced the task of parsing a security descriptor into a text processing task.现在,您已经以统一的方式(SDDL)展示了安全描述符,您已经减少了将安全描述符解析为文本处理任务的任务
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州市文化路47号院1号楼4层(47-1楼位于文化路和红专路十字路口东北角,郑州大学工学院招待所南边,工学院科技报告厅西边。)