/// <summary>
 /// LoadForests method implementation
 /// </summary>
 public static void LoadForests(string domainname, string account, string password, bool usessl, bool reset = false)
 {
     if (reset)
     {
         ResetForests();
     }
     if (_isbinded)
     {
         return;
     }
     try
     {
         _usessl = usessl;
         using (Domain domain = ADDSUtils.GetRootDomain(domainname, account, password))
         {
             using (Forest forest = ADDSUtils.GetForest(domain.Name, account, password))
             {
                 Forests.Clear();
                 ADDSHostForest root = new ADDSHostForest
                 {
                     IsRoot    = true,
                     ForestDNS = forest.Name
                 };
                 Forests.Add(root);
                 foreach (ForestTrustRelationshipInformation trusts in forest.GetAllTrustRelationships())
                 {
                     ADDSHostForest sub = new ADDSHostForest
                     {
                         IsRoot    = false,
                         ForestDNS = trusts.TargetName
                     };
                     foreach (TopLevelName t in trusts.TopLevelNames)
                     {
                         if (t.Status == TopLevelNameStatus.Enabled)
                         {
                             sub.TopLevelNames.Add(t.Name);
                         }
                     }
                     Forests.Add(sub);
                 }
             }
         }
         _isbinded = true;
     }
     catch (Exception ex)
     {
         DataLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5100);
         _isbinded = false;
     }
 }
예제 #2
0
        /// <summary>
        /// GetDirectoryEntry() method implmentation
        /// </summary>
        internal static DirectoryEntry GetDirectoryEntry(ADDSHost host, ADDSHostForest forest, bool usessl)
        {
            string         root  = "LDAP://";
            DirectoryEntry entry = null;

            if (!string.IsNullOrEmpty(host.DomainName))
            {
                if (usessl)
                {
                    entry = new DirectoryEntry(root + host.DomainName + ":636");
                }
                else
                {
                    entry = new DirectoryEntry(root + host.DomainName);
                }
            }
            else
            {
                if (usessl)
                {
                    entry = new DirectoryEntry(root + forest.ForestDNS + ":636");
                }
                else
                {
                    entry = new DirectoryEntry(root + forest.ForestDNS);
                }
            }
            if (!string.IsNullOrEmpty(host.Account))
            {
                entry.Username = host.Account;
            }
            if (!string.IsNullOrEmpty(host.Password))
            {
                entry.Password = host.Password;
            }
            return(entry);
        }