Exemple #1
0
        private void EndPollDirectory(IAsyncResult asyncResult)
        {
            // harvest results
            SearchResponse response =
                (SearchResponse)_connection.EndSendRequest(asyncResult);

            // grab the current search cookie
            foreach (DirectoryControl control in response.Controls)
            {
                DirSyncResponseControl dsrc = control
                                              as DirSyncResponseControl;
                if (null != dsrc)
                {
                    cookie = dsrc.Cookie;
                }
            }

            // if anything changed, notify any listeners
            if (response.Entries.Count > 0)
            {
                if (null != Changed)
                {
                    Changed(this, EventArg.New(response));
                }
            }
        }
Exemple #2
0
        // Token: 0x06001223 RID: 4643 RVA: 0x00057E9C File Offset: 0x0005609C
        protected override SearchResultEntryCollection GetNextResultCollection()
        {
            this.dirSyncRequestControl.Cookie = base.Cookie;
            DirectoryControl            directoryControl;
            SearchResultEntryCollection nextResultCollection   = base.GetNextResultCollection(typeof(DirSyncResponseControl), out directoryControl);
            DirSyncResponseControl      dirSyncResponseControl = directoryControl as DirSyncResponseControl;

            base.Cookie           = dirSyncResponseControl.Cookie;
            base.RetrievedAllData = new bool?(!dirSyncResponseControl.MoreData);
            return(nextResultCollection);
        }
Exemple #3
0
        public void UpdateDirSyncCookie(DirectoryControl dControl)
        {
            Request.Controls.Remove(DirSyncControl);

            MoreData = false;

            DirSyncResponseControl response = null;

            if (dControl != null)
            {
                response = (DirSyncResponseControl)dControl;

                MoreData = response.MoreData;
            }

            if (MoreData)
            {
                QueryInfo.DirSyncCookie = response.Cookie;

                DirSyncCookie();
            }
        }
        internal static void TransformControls(DirectoryControl[] controls)
        {
            for (int i = 0; i < controls.Length; i++)
            {
                Debug.Assert(controls[i] != null);
                byte[] value = controls[i].GetValue();
                if (controls[i].Type == "1.2.840.113556.1.4.319")
                {
                    // The control is a PageControl.
                    object[] result = BerConverter.Decode("{iO}", value);
                    Debug.Assert((result != null) && (result.Length == 2));

                    int size = (int)result[0];
                    // user expects cookie with length 0 as paged search is done.
                    byte[] cookie = (byte[])result[1] ?? Array.Empty <byte>();

                    PageResultResponseControl pageControl = new PageResultResponseControl(size, cookie, controls[i].IsCritical, controls[i].GetValue());
                    controls[i] = pageControl;
                }
                else if (controls[i].Type == "1.2.840.113556.1.4.1504")
                {
                    // The control is an AsqControl.
                    object[] o = BerConverter.Decode("{e}", value);
                    Debug.Assert((o != null) && (o.Length == 1));

                    int result             = (int)o[0];
                    AsqResponseControl asq = new AsqResponseControl(result, controls[i].IsCritical, controls[i].GetValue());
                    controls[i] = asq;
                }
                else if (controls[i].Type == "1.2.840.113556.1.4.841")
                {
                    // The control is a DirSyncControl.
                    object[] o = BerConverter.Decode("{iiO}", value);
                    Debug.Assert(o != null && o.Length == 3);

                    int    moreData      = (int)o[0];
                    int    count         = (int)o[1];
                    byte[] dirsyncCookie = (byte[])o[2];

                    DirSyncResponseControl dirsync = new DirSyncResponseControl(dirsyncCookie, (moreData == 0 ? false : true), count, controls[i].IsCritical, controls[i].GetValue());
                    controls[i] = dirsync;
                }
                else if (controls[i].Type == "1.2.840.113556.1.4.474")
                {
                    // The control is a SortControl.
                    int      result    = 0;
                    string   attribute = null;
                    object[] o         = BerConverter.TryDecode("{ea}", value, out bool decodeSucceeded);

                    // decode might fail as AD for example never returns attribute name, we don't want to unnecessarily throw and catch exception
                    if (decodeSucceeded)
                    {
                        Debug.Assert(o != null && o.Length == 2);
                        result    = (int)o[0];
                        attribute = (string)o[1];
                    }
                    else
                    {
                        // decoding might fail as attribute is optional
                        o = BerConverter.Decode("{e}", value);
                        Debug.Assert(o != null && o.Length == 1);

                        result = (int)o[0];
                    }

                    SortResponseControl sort = new SortResponseControl((ResultCode)result, attribute, controls[i].IsCritical, controls[i].GetValue());
                    controls[i] = sort;
                }
                else if (controls[i].Type == "2.16.840.1.113730.3.4.10")
                {
                    // The control is a VlvResponseControl.
                    int      position;
                    int      count;
                    int      result;
                    byte[]   context = null;
                    object[] o       = BerConverter.TryDecode("{iieO}", value, out bool decodeSucceeded);

                    if (decodeSucceeded)
                    {
                        Debug.Assert(o != null && o.Length == 4);
                        position = (int)o[0];
                        count    = (int)o[1];
                        result   = (int)o[2];
                        context  = (byte[])o[3];
                    }
                    else
                    {
                        o = BerConverter.Decode("{iie}", value);
                        Debug.Assert(o != null && o.Length == 3);
                        position = (int)o[0];
                        count    = (int)o[1];
                        result   = (int)o[2];
                    }

                    VlvResponseControl vlv = new VlvResponseControl(position, count, context, (ResultCode)result, controls[i].IsCritical, controls[i].GetValue());
                    controls[i] = vlv;
                }
            }
        }
Exemple #5
0
        public virtual IEnumerable <ExSearchResultEntry> DirSyncScan(Cookie cookie, string query, SearchScope scope, params string[] attributes)
        {
            SearchRequest         request        = new SearchRequest(cookie.BaseDN, query, scope, attributes);
            DirSyncRequestControl dirsyncControl = new DirSyncRequestControl(null, DirectorySynchronizationOptions.ObjectSecurity);

            dirsyncControl.IsCritical = true;
            dirsyncControl.Cookie     = cookie.CookieValue;
            request.Controls.Add(dirsyncControl);
            DirSyncResponseControl dirSyncResponseControl = null;
            bool hasDirSyncResponseControl = false;

            for (;;)
            {
                ExTraceGlobals.ConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Connection.DirSyncScan sending LDAP query: {0}", query);
                SearchResponse response;
                try
                {
                    response = (SearchResponse)this.SendRequest(request);
                }
                catch (ExDirectoryException ex)
                {
                    if (ex.ResultCode == ResultCode.NoSuchObject)
                    {
                        yield break;
                    }
                    throw;
                }
                foreach (DirectoryControl directoryControl in response.Controls)
                {
                    if (directoryControl is DirSyncResponseControl)
                    {
                        hasDirSyncResponseControl = true;
                        dirSyncResponseControl    = (DirSyncResponseControl)directoryControl;
                        dirsyncControl.Cookie     = dirSyncResponseControl.Cookie;
                        cookie.CookieValue        = dirSyncResponseControl.Cookie;
                    }
                }
                if (!hasDirSyncResponseControl)
                {
                    break;
                }
                int entriesWithNullDN  = 0;
                int entriesWithEmptyDN = 0;
                foreach (object obj in response.Entries)
                {
                    SearchResultEntry resultEntry = (SearchResultEntry)obj;
                    if (resultEntry.DistinguishedName == null)
                    {
                        entriesWithNullDN++;
                    }
                    else if (resultEntry.DistinguishedName == string.Empty)
                    {
                        entriesWithEmptyDN++;
                    }
                    else
                    {
                        yield return(new ExSearchResultEntry(resultEntry));
                    }
                }
                if (entriesWithNullDN > 0)
                {
                    ExTraceGlobals.ConnectionTracer.TraceWarning <int>((long)this.GetHashCode(), "Connection.DirSyncScan encountered {0} search results with null DistinguishedName", entriesWithNullDN);
                }
                if (entriesWithEmptyDN > 0)
                {
                    ExTraceGlobals.ConnectionTracer.TraceWarning <int>((long)this.GetHashCode(), "Connection.DirSyncScan encountered {0} search results with empty DistinguishedName", entriesWithEmptyDN);
                }
                if (dirSyncResponseControl == null || !dirSyncResponseControl.MoreData)
                {
                    goto IL_29E;
                }
            }
            throw new InvalidOperationException("No DirSync control retured from DirSync");
IL_29E:
            yield break;
        }