@@ -20,7 +20,7 @@ const (
20
20
ScopeWholeSubtree = 2
21
21
// ScopeChildren is an OpenLDAP extension that may not be supported by another directory server.
22
22
// See: https://github.com/openldap/openldap/blob/7c55484ee153047efd0e562fc1638c1a2525f320/include/ldap.h#L598
23
- ScopeChildren = 3
23
+ ScopeChildren = 3
24
24
)
25
25
26
26
// ScopeMap contains human readable descriptions of scope choices
@@ -47,6 +47,10 @@ var DerefMap = map[int]string{
47
47
DerefAlways : "DerefAlways" ,
48
48
}
49
49
50
+ // ErrSizeLimitExceeded will be returned if the search result is exceeding the defined SizeLimit
51
+ // and enforcing the requested limit is enabled in the search request (EnforceSizeLimit)
52
+ var ErrSizeLimitExceeded = NewError (ErrorNetwork , errors .New ("ldap: size limit exceeded" ))
53
+
50
54
// NewEntry returns an Entry object with the specified distinguished name and attribute key-value pairs.
51
55
// The map of attributes is accessed in alphabetical order of the keys in order to ensure that, for the
52
56
// same input map of attributes, the output entry will contain the same order of attributes
@@ -417,6 +421,11 @@ type SearchRequest struct {
417
421
Filter string
418
422
Attributes []string
419
423
Controls []Control
424
+
425
+ // EnforceSizeLimit will hard limit the maximum number of entries parsed, in case the directory
426
+ // server returns more results than requested. This setting is disabled by default and does not
427
+ // work in async search requests.
428
+ EnforceSizeLimit bool
420
429
}
421
430
422
431
func (req * SearchRequest ) appendTo (envelope * ber.Packet ) error {
@@ -564,6 +573,12 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
564
573
565
574
switch packet .Children [1 ].Tag {
566
575
case 4 :
576
+ if searchRequest .EnforceSizeLimit &&
577
+ searchRequest .SizeLimit > 0 &&
578
+ len (result .Entries ) >= searchRequest .SizeLimit {
579
+ return result , ErrSizeLimitExceeded
580
+ }
581
+
567
582
entry := & Entry {
568
583
DN : packet .Children [1 ].Children [0 ].Value .(string ),
569
584
Attributes : unpackAttributes (packet .Children [1 ].Children [1 ].Children ),
0 commit comments