Active Directory LDAP,读取组的提升权限..?
Active Directory LDAP, Elevated permissions to read groups..?
我有一个用 C# 编写的测试实用程序。使用 System.DirectoryServices.AccountManagement;我正在从虚拟服务器 (LDAP) 到远程计算机上的 Active Directory 创建 PrincipalContext 连接。
我 100% 能够连接到活动目录,并使用用户名和密码进行身份验证(UserPrincipal.FindByIdentity,然后是 context.ValidateCredentials)。
但是我看不懂群。它拉回默认的,如域用户。
如果我 运行 实用程序作为虚拟服务器的本地管理员(不是 AD 中存在的用户),那么我突然可以使用完全相同的参数从 Active Directory 获取所有指定的用户组。
这怎么可能?我错过了什么?
我的代码如下,尽管我认为问题与代码完全无关,如前所述,当 运行ning 提升时它工作正常。
g_context = new PrincipalContext(ContextType.Domain, this.USERDOMAIN);
g_principal = UserPrincipal.FindByIdentity(g_context, IdentityType.SamAccountName, this.USERNAME);
this.g_entry = (DirectoryEntry)g_principal.GetUnderlyingObject();
this.AUTHENTICATED = g_context.ValidateCredentials(this.USERNAME, this.USERPASS);
这就是设置。然后我们稍后使用 g_context..
List<String> memberships=GetGroups(this.g_principal, true); // get a list of all possible groups for user
调用递归组扫描函数..
private List<String> GetGroups(Principal source, bool debug, int depth=0, List<String> resultset=null) {
if (resultset==null) resultset = new List<String>();
depth++;
foreach (GroupPrincipal group in source.GetGroups()) {
if (!resultset.Contains(group.Name)) {
resultset.Add(group.Name);
if (debug) {
log.Debug((String.Join("\t",new String[depth-1]))+"Located group("+group.Name+") at depth: "+depth);
}
resultset=GetGroups(group, debug, depth, resultset);
}
}
return resultset;
}
当 运行 作为管理员时,AD 会响应该用户名的所有可能的组成员身份。当不是 运行ning 作为提升程序时,AD 响应较少的组(只有基本组)。
关于我需要在哪里挖掘解决方案的任何建议?虚拟 windows 机器 o/s 上是否有一些隐藏的本地策略,为非管理员隐藏 ldap 连接上的活动目录数据?
发现问题,基本上 AD 2008 或更早版本不会(显然)在非管理员用户(或类似用户)请求时响应所有组。不得不使用不同的方法..
[cn] 的 SearchResult 条目扫描 属性
过滤器 = String.Format("(&(objectCategory=group)(member={0}))", user.DistinguishedName);
或使用 System.Security.Principal.WindowsIdentity 有一个要循环的组集合。
两者都很好。
我有一个用 C# 编写的测试实用程序。使用 System.DirectoryServices.AccountManagement;我正在从虚拟服务器 (LDAP) 到远程计算机上的 Active Directory 创建 PrincipalContext 连接。
我 100% 能够连接到活动目录,并使用用户名和密码进行身份验证(UserPrincipal.FindByIdentity,然后是 context.ValidateCredentials)。
但是我看不懂群。它拉回默认的,如域用户。 如果我 运行 实用程序作为虚拟服务器的本地管理员(不是 AD 中存在的用户),那么我突然可以使用完全相同的参数从 Active Directory 获取所有指定的用户组。
这怎么可能?我错过了什么?
我的代码如下,尽管我认为问题与代码完全无关,如前所述,当 运行ning 提升时它工作正常。
g_context = new PrincipalContext(ContextType.Domain, this.USERDOMAIN);
g_principal = UserPrincipal.FindByIdentity(g_context, IdentityType.SamAccountName, this.USERNAME);
this.g_entry = (DirectoryEntry)g_principal.GetUnderlyingObject();
this.AUTHENTICATED = g_context.ValidateCredentials(this.USERNAME, this.USERPASS);
这就是设置。然后我们稍后使用 g_context..
List<String> memberships=GetGroups(this.g_principal, true); // get a list of all possible groups for user
调用递归组扫描函数..
private List<String> GetGroups(Principal source, bool debug, int depth=0, List<String> resultset=null) {
if (resultset==null) resultset = new List<String>();
depth++;
foreach (GroupPrincipal group in source.GetGroups()) {
if (!resultset.Contains(group.Name)) {
resultset.Add(group.Name);
if (debug) {
log.Debug((String.Join("\t",new String[depth-1]))+"Located group("+group.Name+") at depth: "+depth);
}
resultset=GetGroups(group, debug, depth, resultset);
}
}
return resultset;
}
当 运行 作为管理员时,AD 会响应该用户名的所有可能的组成员身份。当不是 运行ning 作为提升程序时,AD 响应较少的组(只有基本组)。
关于我需要在哪里挖掘解决方案的任何建议?虚拟 windows 机器 o/s 上是否有一些隐藏的本地策略,为非管理员隐藏 ldap 连接上的活动目录数据?
发现问题,基本上 AD 2008 或更早版本不会(显然)在非管理员用户(或类似用户)请求时响应所有组。不得不使用不同的方法..
[cn] 的 SearchResult 条目扫描 属性 过滤器 = String.Format("(&(objectCategory=group)(member={0}))", user.DistinguishedName);
或使用 System.Security.Principal.WindowsIdentity 有一个要循环的组集合。
两者都很好。