summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorned <ned@appliedtrust.com>2015-06-03 00:15:06 +0200
committerned <ned@appliedtrust.com>2015-06-03 00:15:06 +0200
commit2a93a58a34c92bac004ec9f0bb2e8cdeed583cad (patch)
tree63e39aaf870a3cf395031307a212e27b66b0b9bb
parentAdded search SizeLimit support (diff)
downloadldap-2a93a58a34c92bac004ec9f0bb2e8cdeed583cad.tar
ldap-2a93a58a34c92bac004ec9f0bb2e8cdeed583cad.tar.gz
ldap-2a93a58a34c92bac004ec9f0bb2e8cdeed583cad.tar.bz2
ldap-2a93a58a34c92bac004ec9f0bb2e8cdeed583cad.tar.lz
ldap-2a93a58a34c92bac004ec9f0bb2e8cdeed583cad.tar.xz
ldap-2a93a58a34c92bac004ec9f0bb2e8cdeed583cad.tar.zst
ldap-2a93a58a34c92bac004ec9f0bb2e8cdeed583cad.zip
Diffstat (limited to '')
-rw-r--r--server_search.go14
-rw-r--r--server_search_test.go20
2 files changed, 28 insertions, 6 deletions
diff --git a/server_search.go b/server_search.go
index 74d06b9..3fc91c5 100644
--- a/server_search.go
+++ b/server_search.go
@@ -44,7 +44,8 @@ func HandleSearchRequest(req *ber.Packet, controls *[]Control, messageID uint64,
}
}
- for i, entry := range searchResp.Entries {
+ i := 0
+ for _, entry := range searchResp.Entries {
if server.EnforceLDAP {
// filter
keep, resultCode := ServerApplyFilter(filterPacket, entry)
@@ -72,11 +73,6 @@ func HandleSearchRequest(req *ber.Packet, controls *[]Control, messageID uint64,
}
}
- // size limit
- if searchReq.SizeLimit > 0 && i >= searchReq.SizeLimit {
- break
- }
-
// attributes
if len(searchReq.Attributes) > 1 || (len(searchReq.Attributes) == 1 && len(searchReq.Attributes[0]) > 0) {
entry, err = filterAttributes(entry, searchReq.Attributes)
@@ -84,6 +80,12 @@ func HandleSearchRequest(req *ber.Packet, controls *[]Control, messageID uint64,
return NewError(LDAPResultOperationsError, err)
}
}
+
+ // size limit
+ if searchReq.SizeLimit > 0 && i >= searchReq.SizeLimit {
+ break
+ }
+ i++
}
// respond
diff --git a/server_search_test.go b/server_search_test.go
index ed05f68..8b8fa65 100644
--- a/server_search_test.go
+++ b/server_search_test.go
@@ -114,6 +114,26 @@ func TestSearchSizelimit(t *testing.T) {
if !strings.Contains(string(out), "numEntries: 3") {
t.Errorf("ldapsearch sizelimit 0 failed - wrong number of entries: %v", string(out))
}
+
+ cmd = exec.Command("ldapsearch", "-H", ldapURL, "-x",
+ "-b", serverBaseDN, "-D", "cn=testy,"+serverBaseDN, "-w", "iLike2test", "-z", "1", "(uid=trent)")
+ out, _ = cmd.CombinedOutput()
+ if !strings.Contains(string(out), "result: 0 Success") {
+ t.Errorf("ldapsearch failed: %v", string(out))
+ }
+ if !strings.Contains(string(out), "numEntries: 1") {
+ t.Errorf("ldapsearch sizelimit 1 with filter failed - wrong number of entries: %v", string(out))
+ }
+
+ cmd = exec.Command("ldapsearch", "-H", ldapURL, "-x",
+ "-b", serverBaseDN, "-D", "cn=testy,"+serverBaseDN, "-w", "iLike2test", "-z", "0", "(uid=trent)")
+ out, _ = cmd.CombinedOutput()
+ if !strings.Contains(string(out), "result: 0 Success") {
+ t.Errorf("ldapsearch failed: %v", string(out))
+ }
+ if !strings.Contains(string(out), "numEntries: 1") {
+ t.Errorf("ldapsearch sizelimit 0 with filter failed - wrong number of entries: %v", string(out))
+ }
done <- true
}()