@@ -210,13 +210,21 @@ private void getControls(string nextTokenStr, byte[] nextToken, int nextToken_cl
210210 }
211211 }
212212 else {
213- if ( nextTokenStr == null ) {
213+ // Initial Page Search for Client Based Token
214+ if ( nextTokenStr == null && nextToken == null ) {
214215 SimplePagedResultsControl pagedRequestControl = new SimplePagedResultsControl ( maxPageSize , null ) ;
215216 options . SetControls ( pagedRequestControl ) ;
216217 }
217218 else {
218- SimplePagedResultsControl pagedRequestControl = new SimplePagedResultsControl ( maxPageSize + nextToken_client , null ) ;
219- options . SetControls ( pagedRequestControl ) ;
219+ try {
220+ // This is the options MyriAD will use when MaxResults havent been achieved, aka multiple Iterations of the while loop
221+ SimplePagedResultsControl pagedRequestControl = new SimplePagedResultsControl ( maxPageSize + nextToken_client , nextToken ) ;
222+ options . SetControls ( pagedRequestControl ) ;
223+ }
224+ catch {
225+ SimplePagedResultsControl pagedRequestControl = new SimplePagedResultsControl ( maxPageSize + nextToken_client , null ) ;
226+ options . SetControls ( pagedRequestControl ) ;
227+ }
220228 }
221229 }
222230 }
@@ -242,6 +250,9 @@ public LdapResponse Search(LdapRequest request, string searchBase, string search
242250 parsed_string = nextTokenStr . Split ( "-" ) ;
243251 nextToken = Utils . Base64ToBytes ( parsed_string [ 0 ] ) ;
244252 Pick_up_Here = Int32 . Parse ( parsed_string [ 1 ] ) ;
253+ if ( Pick_up_Here == 0 ) {
254+ Pick_up_Here = 1 ;
255+ }
245256 }
246257
247258 }
@@ -400,17 +411,21 @@ public LdapResponse Search(LdapRequest request, string searchBase, string search
400411 }
401412 bool Token_present = false ;
402413 Token_present = CheckForToken ( results , entries , nextToken_checker ) . Item1 ;
414+ currentRecords = entries . Count ;
403415 if ( nextTokenStr != null ) {
416+ currentRecords = 0 ;
404417 // This for loop is used to determine the count of the records gathered during the previous search
405418 for ( int i = 0 ; i < entries . Count ; i ++ ) {
406419 if ( i < nextToken_client ) {
407420 continue ;
408421 }
409422 entries_copy . Add ( entries [ i ] ) ;
410423 }
411- entries = entries_copy ;
424+ if ( entries_copy . Count > 0 ) {
425+ entries = entries_copy ;
426+ currentRecords = entries_copy . Count ;
427+ }
412428 }
413- currentRecords = entries . Count ;
414429 if ( MultipleSearches != null ) {
415430 iteration = Pick_up_Here ;
416431 int recordsLeft = maxSearchResults - currentRecords ;
@@ -521,15 +536,14 @@ public LdapResponse Search(LdapRequest request, string searchBase, string search
521536 if ( nextToken_checker != null ) {
522537 nextToken = nextToken_checker ;
523538 }
524- else if ( ! String . IsNullOrEmpty ( PossibleNextToken ) ) {
539+ else if ( ! String . IsNullOrEmpty ( PossibleNextToken ) && currentRecords == maxResults ) {
525540 nextToken = Encoding . ASCII . GetBytes ( PossibleNextToken ) ;
526541 }
527542 else {
528543 nextToken = pagedResponseControl . Cookie ;
529544 }
530- // nextToken = pagedResponseControl.Cookie;
531545 // Max Results Retrieved.
532- if ( maxSearchResults <= entries . Count )
546+ if ( maxSearchResults <= currentRecords )
533547 break ;
534548
535549 }
@@ -549,8 +563,12 @@ public LdapResponse Search(LdapRequest request, string searchBase, string search
549563 if ( nextToken != null && nextToken . Length > 0 )
550564 if ( iteration >= 1 && string . IsNullOrEmpty ( PossibleNextToken ) )
551565 response . NextToken = String . Concat ( Utils . BytesToBase64 ( nextToken ) , String . Concat ( "-" , iteration . ToString ( ) ) ) ;
552- else
553- response . NextToken = Utils . BytesToBase64 ( nextToken ) ;
566+ else {
567+ if ( TokenType == "Client" )
568+ response . NextToken = Utils . BytesToBase64 ( nextToken ) ;
569+ else
570+ response . NextToken = String . Concat ( Utils . BytesToBase64 ( nextToken ) , String . Concat ( "-" , iteration . ToString ( ) ) ) ;
571+ }
554572 }
555573 catch ( Exception e )
556574 {
@@ -724,23 +742,6 @@ static public LdapResponse ReturnError(Exception e, LdapConfig config)
724742 return response ;
725743 }
726744
727- private bool MySSLHandler ( X509Certificate certificate , int [ ] certificateErrors )
728- {
729-
730- //X509Store store = null;
731- //X509Stores stores = X509StoreManager.CurrentUser;
732- ////string input;
733- //store = stores.TrustedRoot;
734-
735- //X509Certificate x509 = null;
736- //X509CertificateCollection coll = new X509CertificateCollection();
737- //byte[] data = certificate.GetRawCertData();
738- //if (data != null)
739- // x509 = new X509Certificate(data);
740-
741- return true ;
742- }
743-
744745 public static void get_Known_attributes ( string Key , AttributeValue value ) {
745746 bool key_checker = DefaultTypes . ContainsKey ( Key ) ;
746747 if ( key_checker ) {
0 commit comments