コード例 #1
0
        private void LoadDomains()
        {
            SearchRequest request = new SearchRequest(null, "(objectClass=domainDNS)", SearchScope.Subtree, new string[] { "canonicalName", "objectSid" });

            PageResultRequestControl pagecookie = new PageResultRequestControl(1000);

            request.Controls.Add(pagecookie);

            SearchOptionsControl phantomcookie = new SearchOptionsControl(SearchOption.PhantomRoot);

            request.Controls.Add(phantomcookie);

            LdapDirectoryIdentifier ldapid = new LdapDirectoryIdentifier(ForestBase.DefaultDC.Name, 389, true, false);

            using (LdapConnector ldapcon = new LdapConnector(ldapid))
            {
                if ((ForestBase.GivenCreds != null) && (ForestBase.GivenCreds.HasCreds))
                {
                    ldapcon.Credential = ForestBase.GivenCreds.NetCreds;
                }

                ldapcon.SessionOptions.ReferralChasing = ReferralChasingOptions.All;

                ldapcon.Bind();

                SearchResponse response = (SearchResponse)ldapcon.SendRequest(request);

                foreach (SearchResultEntry entry in response.Entries)
                {
                    if (entry.DistinguishedName.ToLowerInvariant() != ForestBase.RootDomainNamingContext.ToLowerInvariant())
                    {
                        string domdns = null;

                        entry.GetStringAttributeSafe("canonicalName", out domdns);

                        domdns = domdns.TrimChar("/");

                        foreach (DomainControllerHelper dchelper in GetDcList(domdns, entry.DistinguishedName))
                        {
                            StoreDC(dchelper, entry.DistinguishedName);
                        }

                        List <byte[]> bsids;

                        entry.GetAttributeSafe("objectSid", out bsids);

                        SecurityIdentifier dsid = new SecurityIdentifier(bsids[0], 0);

                        ForestBase.DomainSids.AddSafe(entry.DistinguishedName, dsid.ToString());
                    }
                }
            }
        }
コード例 #2
0
        public bool ValidateCreds()
        {
            bool ret = false;

            LdapDirectoryIdentifier ldapid = null;

            LdapConnector ldapcheck = null;

            try
            {
                ldapid = new LdapDirectoryIdentifier(ForestName, false, false);

                ldapcheck = new LdapConnector(ldapid);

                ldapcheck.AutoBind = false;
                ldapcheck.AuthType = AuthType.Basic;

                ldapcheck.SessionOptions.FastConcurrentBind();

                ldapcheck.Bind(NetCreds);

                ret = true;
            }

            catch (Exception ex)
            {
                ErrorMsg = String.Format("{0} ({1}\\{2})", ex.Message, DomainName, UserName);
            }

            finally
            {
                try
                { ldapcheck.Dispose(); }

                catch (Exception ex)
                { ex.ToDummy(); }
            }

            HasError = !ret;

            return(ret);
        }
コード例 #3
0
        private bool LoadConfig()
        {
            bool ret = false;

            SearchRequest request = new SearchRequest(ForestBase.ConfigurationNamingContext,
                                                      "(|(objectClass=nTDSDSA)(objectClass=queryPolicy))",
                                                      SearchScope.Subtree,
                                                      new string[] { "objectClass", "whenCreated", "queryPolicyObject", "lDAPAdminLimits" });

            LdapDirectoryIdentifier ldapid = new LdapDirectoryIdentifier(ForestBase.DefaultDC.Name, 389, true, false);

            using (LdapConnector ldapcon = new LdapConnector(ldapid))
            {
                try
                {
                    if ((ForestBase.GivenCreds != null) && (ForestBase.GivenCreds.HasCreds))
                    {
                        ldapcon.Credential = ForestBase.GivenCreds.NetCreds;
                    }

                    ldapcon.Bind();

                    SearchResponse response = (SearchResponse)ldapcon.SendRequest(request);

                    List <SearchResultEntry> ntds = new List <SearchResultEntry> {
                    };

                    List <QueryPolicy> policies = new List <QueryPolicy> {
                    };

                    foreach (SearchResultEntry entry in response.Entries)
                    {
                        List <string> classes = new List <string> {
                        };

                        entry.GetStringAttributeSafe("objectClass", out classes);

                        if (classes.Contains("nTDSDSA"))
                        {
                            ntds.Add(entry);
                        }

                        else if (classes.Contains("queryPolicy"))
                        {
                            policies.Add(new QueryPolicy(entry));
                        }
                    }

                    policies.OrderByField("WhenCreated", false);

                    foreach (QueryPolicy pol in policies)
                    {
                        ForestBase.QueryPolicies.AddSafe(pol.DN, pol);
                    }

                    foreach (SearchResultEntry entry in ntds)
                    {
                        string qpol = String.Empty;

                        entry.GetStringAttributeSafe("queryPolicyObject", out qpol);

                        if (qpol != String.Empty)
                        {
                            ForestBase.NTDSSettings.AddSafe(entry.DistinguishedName, qpol);
                        }

                        else
                        {
                            ForestBase.NTDSSettings.AddSafe(entry.DistinguishedName, policies[0].DN);
                        }
                    }

                    ret = true;
                }

                catch (Exception ex)
                { SetError(ex.Message); }
            }

            return(ret);
        }
コード例 #4
0
        private bool LoadForestName()
        {
            bool ret = false;

            string domdns = null;

            SearchRequest request = new SearchRequest(ForestBase.RootDomainNamingContext, "(objectClass=*)", SearchScope.Base, new string[] { "canonicalName", "objectSid" });

            LdapDirectoryIdentifier ldapid = new LdapDirectoryIdentifier(ForestBase.DefaultDC.Name, 389, true, false);

            using (LdapConnector ldapcon = new LdapConnector(ldapid))
            {
                if ((ForestBase.GivenCreds != null) && (ForestBase.GivenCreds.HasCreds))
                {
                    ldapcon.Credential = ForestBase.GivenCreds.NetCreds;
                }

                try
                {
                    ldapcon.Bind();

                    SearchResponse response = (SearchResponse)ldapcon.SendRequest(request);

                    foreach (SearchResultEntry entry in response.Entries)
                    {
                        domdns = null;

                        entry.GetStringAttributeSafe("canonicalName", out domdns);

                        ForestBase.ForestName = domdns.TrimChar("/");

                        List <DomainControllerHelper> dclist = GetDcList(ForestBase.ForestName, entry.DistinguishedName);

                        if ((dclist.Count == 1) && (dclist[0].Success == false))
                        {
                            string temp = domdns;

                            if (temp == null)
                            {
                                temp = "current domain";
                            }

                            base.SetError(String.Format("LoadForestName: Could not detect a DC in {0}", temp));
                        }

                        else
                        {
                            foreach (DomainControllerHelper dchelper in dclist)
                            {
                                if (dchelper.Success)
                                {
                                    StoreDC(dchelper, entry.DistinguishedName);

                                    ret = true;
                                }
                            }

                            List <byte[]> bsids;

                            entry.GetAttributeSafe("objectSid", out bsids);

                            SecurityIdentifier dsid = new SecurityIdentifier(bsids[0], 0);

                            ForestBase.DomainSids.AddSafe(entry.DistinguishedName, dsid.ToString());
                        }
                    }
                }

                catch (Exception ex)
                {
                    base.SetError(String.Format("LoadForestName: {0} ({1})", ex.Message, ex.GetType().Name));
                }
            }

            if (ret && (ForestBase.DCList.Count == 0))
            {
                base.SetError("LoadForestName: Could not detect a DC in current forest");

                ret = false;

                GlobalEventHandler.RaiseFinishedDiscovering();
            }

            return(ret);
        }