Active directory Active Directory主组的含义和用途是什么?

Active directory Active Directory主组的含义和用途是什么?,active-directory,ldap,Active Directory,Ldap,我最近听说过Active Directory中的主要组概念,但到目前为止还不清楚它的用途以及它是如何工作的 作为同一问题的一部分,如何使用LDAP获取主组?这似乎没有列为属性的成员。我一直在使用此代码获取Active Directory中用户的主要组: private string GetPrimaryGroup(DirectoryEntry aEntry, DirectoryEntry aDomainEntry) { int primaryGroupID = (int)aEntry.Pr

我最近听说过Active Directory中的主要组概念,但到目前为止还不清楚它的用途以及它是如何工作的


作为同一问题的一部分,如何使用LDAP获取主组?这似乎没有列为
属性的
成员。

我一直在使用此代码获取Active Directory中用户的主要组:

private string GetPrimaryGroup(DirectoryEntry aEntry, DirectoryEntry aDomainEntry)
{
   int primaryGroupID = (int)aEntry.Properties["primaryGroupID"].Value;
   byte[] objectSid = (byte[])aEntry.Properties["objectSid"].Value;

   StringBuilder escapedGroupSid = new StringBuilder();

   // Copy over everything but the last four bytes(sub-authority)
   // Doing so gives us the RID of the domain
   for(uint i = 0; i < objectSid.Length - 4; i++)
   {
      escapedGroupSid.AppendFormat("\\{0:x2}", objectSid[i]);
   }

   // Add the primaryGroupID to the escape string to build the SID of the primaryGroup
   for(uint i = 0; i < 4; i++)
   {
      escapedGroupSid.AppendFormat("\\{0:x2}", (primaryGroupID & 0xFF));
      primaryGroupID >>= 8;
   }

   // Search the directory for a group with this SID
   DirectorySearcher searcher = new DirectorySearcher();

   if(aDomainEntry != null)
   {
       searcher.SearchRoot = aDomainEntry;
   }

   searcher.Filter = "(&(objectCategory=Group)(objectSID=" + escapedGroupSid.ToString() + "))";
   searcher.PropertiesToLoad.Add("distinguishedName");

   return searcher.FindOne().Properties["distinguishedName"][0].ToString();
}
私有字符串GetPrimaryGroup(DirectoryEntry aEntry,DirectoryEntry aDomainEntry)
{
int primaryGroupID=(int)aEntry.Properties[“primaryGroupID”].Value;
字节[]对象SID=(字节[])aEntry.Properties[“对象SID”].Value;
StringBuilder escapedGroupSid=新StringBuilder();
//复制除最后四个字节以外的所有内容(子权限)
//这样做可以让我们摆脱这个领域
对于(uint i=0;i>=8;
}
//在目录中搜索具有此SID的组
DirectorySearcher search=新的DirectorySearcher();
if(aDomainEntry!=null)
{
searcher.SearchRoot=aDomainEntry;
}
searcher.Filter=“(&(objectCategory=Group)(objectSID=“+escapedGroupSid.ToString()+”)”;
searcher.PropertiesToLoad.Add(“DiscrimitedName”);
返回searcher.FindOne().Properties[“DifferentizedName”][0].ToString();
}
主组是默认情况下每个新用户都添加到的组-通常是
域用户