示例#1
0
 public void ReferralChasing_SetInvalid_ThrowsInvalidEnumArgumentException(ReferralChasingOptions referralChasing)
 {
     using (var connection = new LdapConnection("server"))
     {
         AssertExtensions.Throws <InvalidEnumArgumentException>("value", () => connection.SessionOptions.ReferralChasing = referralChasing);
     }
 }
示例#2
0
        private void GetSingleObjectPaths(string dc,
                                          string searchBase,
                                          string ldapFilter,
                                          string[] propertiesToLoad,
                                          SearchScope scope,
                                          ReferralChasingOptions referralChasing,
                                          QueryControl queryInfo)
        {
            GlobalEventHandler.RaiseErrorOccured(String.Format("Attribute list contains (a) constructed attribute(s) {0}\t-> changing to single object path base query", Environment.NewLine));

            if ((queryInfo.PhantomRoot) && (propertiesToLoad.ContainsSubString("tokengroups", MATCH_POSITION.STARTSWITH)))
            {
                GlobalEventHandler.RaiseErrorOccured(String.Format("Turning off PhantomRoot {0}\t-> attribute(s) contain tokenGroups*", Environment.NewLine));

                queryInfo.PhantomRoot = false;
            }

            GlobalEventHandler.QueryCompleted += QuerySingleObjectPaths;

            string[] attribs = new string[] { "cn" };

            Query(dc,
                  searchBase,
                  ldapFilter,
                  attribs,
                  scope,
                  referralChasing,
                  queryInfo,
                  propertiesToLoad);
        }
示例#3
0
        public void ReferralChasing_Set_GetReturnsExpected(ReferralChasingOptions value)
        {
            LdapSessionOptions options = new LdapConnection("server").SessionOptions;

            Assert.Equal(ReferralChasingOptions.All, options.ReferralChasing);

            options.ReferralChasing = value;
            Assert.Equal(value, options.ReferralChasing);
        }
示例#4
0
        public void ReferralChasing_Set_GetReturnsExpected_On_Windows(ReferralChasingOptions value)
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Equal(ReferralChasingOptions.All, options.ReferralChasing);

                options.ReferralChasing = value;
                Assert.Equal(value, options.ReferralChasing);
            }
        }
示例#5
0
        private void Connect(string dc,
                             ReferralChasingOptions referralChasing,
                             bool isAsync        = false,
                             bool connectionLess = false)
        {
            int port = ForestBase.CurrentPorts.SelectedPort;

            base.IsConnected = false;

            string        inex    = null;
            LdapConnector tempcon = null;

            try
            {
                LdapDirectoryIdentifier ldapid = new LdapDirectoryIdentifier(dc, port, true, connectionLess);

                tempcon = GetLdapConnection(ldapid, ForestBase.GivenCreds);

                tempcon.SessionOptions.ReferralChasing = referralChasing;

                tempcon.Timeout = TimeSpan.FromSeconds((double)ForestBase.CurrentTimeOut); //new TimeSpan(0, 2, 0);
                tempcon.SessionOptions.SendTimeout = TimeSpan.FromSeconds((double)ForestBase.CurrentTimeOut);
                tempcon.ServerTimeOut = TimeSpan.FromSeconds((double)ForestBase.CurrentTimeOut);


                if (!isAsync)
                {
                    base.Connection = tempcon;
                }

                else
                {
                    base.AsyncConnection = tempcon;
                }

                base.IsConnected = true;
            }

            catch (Exception ex)
            { inex = "Connect LDAP: " + ex.Message; }

            if (inex != null)
            {
                base.SetError(inex);
            }
        }
示例#6
0
        public void AsyncQuery(string dc,
                               string searchBase,
                               string ldapFilter,
                               string[] propertiesToLoad,
                               SearchScope scope,
                               ReferralChasingOptions referralChasing,
                               QueryControl queryInfo,
                               bool performASQ = false)
        {
            CancelToken = false;

            GlobalEventHandler.ClearSearchCancelled();

            GlobalEventHandler.SearchCancelled += ReceivedCancellation;

            byte[] pagingCookie = null;

            ForestBase.CurrentPorts.SelectedPort = queryInfo.Port;

            Connect(dc, referralChasing, true, connectionLess: (searchBase.Length == 0));

            if (propertiesToLoad.Length == 0)
            {
                propertiesToLoad = null;
            }

            else if ((propertiesToLoad.Length == 1) && (propertiesToLoad[0] == "*"))
            {
                propertiesToLoad = null;
            }

            ForestBase.CurrentRequestExtender = new SearchRequestExtender(searchBase,
                                                                          ldapFilter,
                                                                          propertiesToLoad,
                                                                          scope,
                                                                          pagingCookie,
                                                                          queryInfo);


            base.AsyncComplete = false;
            base.AsyncCalls    = 0;

            GlobalEventHandler.AsyncQureyIsCompleted += AsyncSearchComplete;

            PagedAsyncQuery();
        }
示例#7
0
        private bool RunParallelQueries(string dc,
                                        string searchBase,
                                        string ldapFilter,
                                        ref string[] propertiesToLoad,
                                        SearchScope scope,
                                        ReferralChasingOptions referralChasing,
                                        QueryControl queryInfo,
                                        out SearchRequestExtender reqStore)
        {
            bool ret = false;

            reqStore = null;

            if ((searchBase == null) || (searchBase.Length == 0))
            {
                return(ret);
            }

            reqStore = new SearchRequestExtender(searchBase,
                                                 ldapFilter,
                                                 propertiesToLoad,
                                                 scope,
                                                 null,
                                                 queryInfo);



            if ((scope == SearchScope.Subtree) && (queryInfo.PerformPagedQuery) && ((referralChasing & ReferralChasingOptions.Subordinate) == ReferralChasingOptions.Subordinate))
            {
                ret = true;
            }

            if (!ret)
            {
                return(ret);
            }

            Dictionary <string, string> querylist = SubNCsToDCs(searchBase, dc);

            base.ParallelRuns = querylist.Count;

            if (base.ParallelRuns == 0)
            {
                return(ret);
            }


            ret = true;

            referralChasing = ReferralChasingOptions.None;
            string[] attributes = propertiesToLoad;

            foreach (KeyValuePair <string, string> kvp in querylist)
            {
                base.RunningParallel = true;

                Thread thquery = new Thread(() => { AsyncQuery(kvp.Value, kvp.Key, ldapFilter, attributes, scope, referralChasing, queryInfo); });

                thquery.Start();
            }

            return(ret);
        }
示例#8
0
        public List <SearchResultEntry> Query(string dc,
                                              string searchBase,
                                              string ldapFilter,
                                              string[] propertiesToLoad,
                                              SearchScope scope,
                                              ReferralChasingOptions referralChasing,
                                              QueryControl queryInfo,
                                              string[] attributesRemebered = null,
                                              bool returnResults           = false)
        {
            CancelToken = false;

            GlobalEventHandler.ClearSearchCancelled();

            GlobalEventHandler.SearchCancelled += ReceivedCancellation;

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

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

            QueryHasConstructedAttribute(propertiesToLoad, scope, ref queryInfo);

            if (queryInfo.MustGetSingleObjectPath)
            {
                GetSingleObjectPaths(dc,
                                     searchBase,
                                     ldapFilter,
                                     propertiesToLoad,
                                     scope,
                                     referralChasing,
                                     queryInfo);
                return(ret);
            }

            ForestBase.CurrentPorts.SelectedPort = queryInfo.Port;

            byte[] pagingCookie = null;

            SearchRequestExtender reqstore = new SearchRequestExtender(searchBase,
                                                                       ldapFilter,
                                                                       propertiesToLoad,
                                                                       scope,
                                                                       pagingCookie,
                                                                       queryInfo);

            reqstore.DC = dc;

            reqstore.ReferralChasing = referralChasing;

            propertiesToLoad = reqstore.Attributes;

            while (true)
            {
                if (!reqstore.HasError)
                {
                    reqstore.PageCount++;
                }

                SearchResultEntryCollection colresult = null;

                if (!CancelToken)
                {
                    if (!queryInfo.PerformDirSync)
                    {
                        DateTime starttime = DateTime.Now;

                        colresult = PagedQuery(ref reqstore);

                        if (reqstore.CurrentPageSize > 0)
                        {
                            GlobalEventHandler.RaiseMessageOccured(String.Format("Page: {0} ({1}) [{2}] ms]", reqstore.PageCount, reqstore.CurrentPageSize, DateTime.Now.Subtract(starttime).TotalMilliseconds));
                        }
                    }

                    else
                    {
                        colresult = DirSyncQuery(ref reqstore);
                    }
                }

                else
                {
                    break;
                }

                if (reqstore.HasError)
                {
                    break;
                }

                if ((colresult != null) && (colresult.Count > 0) && ((colresult[0].DistinguishedName.Length != 0) || (searchBase == "")))
                {
                    SearchResultEntry[] temp = new SearchResultEntry[colresult.Count];

                    colresult.CopyTo(temp, 0);

                    fire = temp.ToList();

                    if (returnResults)
                    {
                        ret.AddRange(fire);
                    }
                }

                if ((queryInfo.CurrentResultEventType == QUERY_RESULT_EVENT_TYPE.FROM_SINGLE_OBJECT_PATH) && (attributesRemebered != null))
                {
                    reqstore.HandleAttributes(attributesRemebered);
                }

                if (reqstore.MoreData)
                {
                    if ((fire.Count > 0) && !returnResults)
                    {
                        GlobalEventHandler.RaiseQueryCompleted(fire, reqstore, QUERY_RESULT_EVENT_TYPE.IS_PARTIAL | queryInfo.CurrentResultEventType);
                    }

                    if ((queryInfo.CurrentResultEventType == QUERY_RESULT_EVENT_TYPE.FROM_SINGLE_OBJECT_PATH) && (attributesRemebered != null))
                    {
                        reqstore.HandleAttributes(propertiesToLoad);
                    }
                }

                else
                {
                    break;
                }
            }

            if (reqstore.DoPaging)
            {
                reqstore.AddMessage(String.Format("PageSize: {0}", reqstore.CurrentPageSize));
                reqstore.AddMessage(String.Format("Pages: {0}", reqstore.PageCount));
            }

            if (!returnResults)
            {
                GlobalEventHandler.RaiseQueryCompleted(fire, reqstore, QUERY_RESULT_EVENT_TYPE.IS_COMPLETED | queryInfo.CurrentResultEventType);
            }

            Disconnect();

            return(ret);
        }