public void AttributeCount_SetValid_GetReturnsExpected() { var control = new DirSyncRequestControl { AttributeCount = 0 }; Assert.Equal(0, control.AttributeCount); }
public void Cookie_Set_GetReturnsExpected() { byte[] cookie = new byte[] { 1, 2, 3 }; var control = new DirSyncRequestControl { Cookie = cookie }; Assert.NotSame(cookie, control.Cookie); Assert.Equal(cookie, control.Cookie); }
public void Ctor_Cookie_Options_AttributeCount(byte[] cookie, DirectorySynchronizationOptions option, int attributeCount, byte[] expectedValue) { var control = new DirSyncRequestControl(cookie, option, attributeCount); Assert.Equal(attributeCount, control.AttributeCount); Assert.Equal(cookie ?? Array.Empty <byte>(), control.Cookie); Assert.Equal(option, control.Option); Assert.True(control.IsCritical); Assert.True(control.ServerSide); Assert.Equal("1.2.840.113556.1.4.841", control.Type); Assert.Equal(expectedValue, control.GetValue()); }
public void Ctor_Default() { var control = new DirSyncRequestControl(); Assert.Equal(1048576, control.AttributeCount); Assert.Empty(control.Cookie); Assert.Equal(DirectorySynchronizationOptions.None, control.Option); Assert.True(control.IsCritical); Assert.True(control.ServerSide); Assert.Equal("1.2.840.113556.1.4.841", control.Type); Assert.Equal(new byte[] { 48, 132, 0, 0, 0, 10, 2, 1, 0, 2, 3, 16, 0, 0, 4, 0 }, control.GetValue()); }
public void Ctor_Default() { var control = new DirSyncRequestControl(); Assert.Equal(1048576, control.AttributeCount); Assert.Empty(control.Cookie); Assert.Equal(DirectorySynchronizationOptions.None, control.Option); Assert.True(control.IsCritical); Assert.True(control.ServerSide); Assert.Equal("1.2.840.113556.1.4.841", control.Type); var expected = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new byte[] { 48, 132, 0, 0, 0, 10, 2, 1, 0, 2, 3, 16, 0, 0, 4, 0 } : new byte[] { 48, 10, 2, 1, 0, 2, 3, 16, 0, 0, 4, 0 }; Assert.Equal(expected, control.GetValue()); }
public System.DirectoryServices.DirectoryEntry[] GetUsers(NetworkCredential credential) { var users = new List <System.DirectoryServices.DirectoryEntry>(); var domain = Domain.GetComputerDomain(); var entry = domain.GetDirectoryEntry(); string path = entry.Path; var ldap = new LdapDirectoryIdentifier(domain.Name); var connection = new LdapConnection(ldap); connection.Credential = credential == null ? CredentialCache.DefaultNetworkCredentials : credential; var request = new SearchRequest(path, LdapFilter, SearchScope.Subtree, Attributes); var control = new DirSyncRequestControl(_cookie, DirectorySynchronizationOptions.IncrementalValues, Int32.MaxValue); request.Controls.Add(control); connection.Timeout = new TimeSpan(0, 2, 0); var response = (SearchResponse)connection.SendRequest(request); bool loop = true; while (loop) { foreach (System.DirectoryServices.DirectoryEntry e in response.Entries) { users.Add(e); } foreach (DirectoryControl c in response.Controls) { if (c is DirSyncResponseControl) { var dsrc = (DirSyncResponseControl)c; _cookie = dsrc.Cookie; loop = dsrc.MoreData; } } control.Cookie = _cookie; response = (SearchResponse)connection.SendRequest(request); } return(users.ToArray()); }
public void AttributeCount_SetNegative_ThrowsArgumentException() { var control = new DirSyncRequestControl(); AssertExtensions.Throws <ArgumentException>("value", () => control.AttributeCount = -1); }
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; }
protected void DirSyncCookie() { DirSyncControl = new DirSyncRequestControl(QueryInfo.DirSyncCookie, DirSyncFlags, Int32.MaxValue); Request.Controls.Add(DirSyncControl); }