渴望感谢这个有趣的问题。
接下来,只是修正,你说:
我看着下面的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