Fix ControlServerSideSortingResult handling for OpenLDAP#546
Fix ControlServerSideSortingResult handling for OpenLDAP#546cpuschma merged 3 commits intogo-ldap:masterfrom
Conversation
|
Hi @EgorKo25 , thank you for your PR. RFC 2891 Section 1.2 (https://datatracker.ietf.org/doc/html/rfc2891#section-1.2) only names the second attribute as optional, but not the first. Therefore it should never happen that there are no children at controlValue: Maybe I'm missing something here, but usually we don't derivate from the RFCs. |
|
Hello, I tried to reproduce the issue myself. Here is the test program: package main
import (
"fmt"
"github.com/go-ldap/ldap/v3"
"log"
)
func main() {
l, err := ldap.DialURL("ldap://localhost:389")
if err != nil {
log.Fatal(err)
}
defer l.Close()
pageControl := ldap.NewControlPaging(1)
serverSideSortingControl := ldap.NewControlServerSideSortingWithSortKeys(
[]*ldap.SortKey{
{
Reverse: false,
AttributeType: "cn",
MatchingRule: "caseIgnoreOrderingMatch",
},
})
searchRequest := ldap.NewSearchRequest(
"dc=globus,dc=ru", // The base dn to search
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
"(&(objectClass=organizationalPerson))", // The filter to apply
[]string{"dn", "cn"}, // A list attributes to retrieve
[]ldap.Control{pageControl, serverSideSortingControl},
)
sr, err := l.Search(searchRequest)
if err != nil {
log.Fatal(err)
}
for _, entry := range sr.Entries {
fmt.Printf("%s: %v\n", entry.DN, entry.GetAttributeValue("cn"))
}
}With OpenLDAP (I tried versions 2.5.18 and 2.6.7), the program always stops with the error "failed to decode child control: bad packet" after the In the debug output I also created a dump using I have an idea that during decoding, we should use |

Description
This pull request fixes an issue in the ControlServerSideSortingResult function where an empty pkt.Children caused an error in OpenLDAP. According to OpenLDAP behavior, the presence of Children is not always required, so returning an empty ControlServerSideSortingResult instead of an error ensures better compatibility.
Changes
Testing
Additional Notes