渴望感謝這個有趣的問題。
接下來,只是修正,你說:
我看着下面的LDAP代碼來獲取所有的memberOf條目中的一次:
(memberOf:1.2.840.113556.1.4.1941:={0})
你不讓它工作。我記得當我知道它的存在時,我就開始工作,但它在LDIFDE.EXE過濾器中。所以我將它應用於C#中的ADSI,它仍然在運行。我從微軟拿到的樣本中有太多的括號,但它正在工作(source in AD Search Filter Syntax)。
根據你的言論,我們不知道用戶是否明確屬於該組,我添加了一個請求。我知道這不是很好,但這是我最擅長的。
static void Main(string[] args)
{
/* Connection to Active Directory
*/
DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/dc=dom,dc=fr");
/* To find all the groups that "user1" is a member of :
* Set the base to the groups container DN; for example root DN (dc=dom,dc=fr)
* Set the scope to subtree
* Use the following filter :
* (member:1.2.840.113556.1.4.1941:=cn=user1,cn=users,DC=x)
*/
DirectorySearcher dsLookFor = new DirectorySearcher(deBase);
dsLookFor.Filter = "(member:1.2.840.113556.1.4.1941:=CN=user1 Users,OU=MonOu,DC=dom,DC=fr)";
dsLookFor.SearchScope = SearchScope.Subtree;
dsLookFor.PropertiesToLoad.Add("cn");
SearchResultCollection srcGroups = dsLookFor.FindAll();
/* Just to know if user is explicitly in group
*/
foreach (SearchResult srcGroup in srcGroups)
{
Console.WriteLine("{0}", srcGroup.Path);
foreach (string property in srcGroup.Properties.PropertyNames)
{
Console.WriteLine("\t{0} : {1} ", property, srcGroup.Properties[property][0]);
}
DirectoryEntry aGroup = new DirectoryEntry(srcGroup.Path);
DirectorySearcher dsLookForAMermber = new DirectorySearcher(aGroup);
dsLookForAMermber.Filter = "(member=CN=user1 Users,OU=MonOu,DC=dom,DC=fr)";
dsLookForAMermber.SearchScope = SearchScope.Base;
dsLookForAMermber.PropertiesToLoad.Add("cn");
SearchResultCollection memberInGroup = dsLookForAMermber.FindAll();
Console.WriteLine("Find the user {0}", memberInGroup.Count);
}
Console.ReadLine();
}
在我的測試系統中,這一得出:
LDAP://WM2008R2ENT:389/CN=MonGrpSec,OU=MonOu,DC=dom,DC=fr
adspath : LDAP://WM2008R2ENT:389/CN=MonGrpSec,OU=MonOu,DC=dom,DC=fr
cn : MonGrpSec
Find the user 1
LDAP://WM2008R2ENT:389/CN=MonGrpDis,OU=ForUser1,DC=dom,DC=fr
adspath : LDAP://WM2008R2ENT:389/CN=MonGrpDis,OU=ForUser1,DC=dom,DC=fr
cn : MonGrpDis
Find the user 1
LDAP://WM2008R2ENT:389/CN=MonGrpPlusSec,OU=ForUser1,DC=dom,DC=fr
adspath : LDAP://WM2008R2ENT:389/CN=MonGrpPlusSec,OU=ForUser1,DC=dom,DC=fr
cn : MonGrpPlusSec
Find the user 0
LDAP://WM2008R2ENT:389/CN=MonGrpPlusSecUniv,OU=ForUser1,DC=dom,DC=fr
adspath : LDAP://WM2008R2ENT:389/CN=MonGrpPlusSecUniv,OU=ForUser1,DC=dom,DC=fr
cn : MonGrpPlusSecUniv
Find the user 0
(編輯) '1.2.840.113556.1.4.1941' 不是在W2K3 SP1工作,它始於SP2工作。我認爲它與W2K3 R2一樣。它應該在W2K8上工作。我在這裏測試W2K8R2。我很快就可以在W2K8上進行測試。
感謝分享。這看起來很有希望。我遠離我可以馬上測試的地方(幾乎沒有互聯網),但我會盡快測試,並讓你知道我找到了什麼。再次感謝。 – IAmTimCorey 2011-06-10 03:02:35
已編輯:我做了一些更多的調查,並添加了微軟開始支持這些遞歸控件的細節。我很奇怪,信息不在根DSE中。 – JPBlanc 2011-06-10 04:51:35
所以。你測試它嗎? – JPBlanc 2011-06-15 16:13:45