我想測試任意用戶是否具有對特定Active Directory對象的屬性的寫入訪問權限。我認爲,解決方案的一部分似乎是這樣的:檢查ActiveDirectory對象上的授權
NTAccount Account = new NTAccount("Domain\\XYZ");
SecurityIdentifier Sid =
(SecurityIdentifier)Account.Translate(typeof(SecurityIdentifier));
這似乎讓我從用戶的字符串表示得到了具體體現。我想這是另一個難題:
string strMemberString = "LDAP://OU=Test,DC=Domain,DC=local";
DirectoryEntry computers = new DirectoryEntry();
computers.Path = strMemberString;
computers.Options.SecurityMasks = SecurityMasks.Owner | SecurityMasks.Group
| SecurityMasks.Dacl | SecurityMasks.Sacl;
foreach (DirectoryEntry computer in computers.Children)
{
if (computer.Name == "CN=Test")
{
ActiveDirectorySecurity sdc = computer.ObjectSecurity;
//...
不知道該從哪裏去。我如何完成這個?我應該追求完全不同的方式嗎?我正在使用.net 4.0。
我寧願解決方案完全是BCL代碼,而不是PInvoke或WMI。
您是否意識到「對特定活動目錄對象的屬性具有寫權限」這一事實可能源自屬於某個組的組或屬於該組等等? – JPBlanc
@JPBlanc:是的,我知道。這項「工作」應該由BCL爲我處理。我只需要了解使用情況。 –
我編輯了我的答案,你會發現有辦法檢索用戶所在的安全組。 – JPBlanc