Skip to content

Commit 2a92a62

Browse files
Added check around SizeLimitExceeded result code when actually the correct number of entries were already returned (#177)
Fixes #176
1 parent 35c8302 commit 2a92a62

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

LdapForNet/LdapConnection.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq;
45
using System.Runtime.InteropServices;
56
using System.Security.Cryptography.X509Certificates;
@@ -372,7 +373,19 @@ private DirectoryResponse ProcessResponse(DirectoryRequest directoryRequest,
372373
var responseReferral = new Uri[0];
373374
var responseControl = new DirectoryControl[0];
374375
var res = ParseResultError(msg, out var errorMessage, out var matchedDn, ref responseReferral, ref responseControl);
375-
response.ResultCode = (Native.Native.ResultCode)res;
376+
377+
if (res == (int)Native.Native.ResultCode.SizeLimitExceeded
378+
&& directoryRequest is SearchRequest searchRequest
379+
&& response is SearchResponse searchResponse
380+
&& searchRequest.SizeLimit != 0
381+
&& searchResponse.Entries.Count >= searchRequest.SizeLimit)
382+
{
383+
Debug.WriteLine("ldap_parse_result returned ResultCode.SizeLimitExceeded but the correct number of entries were already returned");
384+
res = (int)Native.Native.ResultCode.Success;
385+
errorMessage = null;
386+
}
387+
388+
response.ResultCode = (Native.Native.ResultCode)res;
376389
response.ErrorMessage = errorMessage;
377390
response.Referral = responseReferral;
378391
response.Controls = responseControl;

0 commit comments

Comments
 (0)