-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ControlServerSideSortingResult handling for OpenLDAP #546
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EgorKo25 Can you please take a look at my review? Thank you in advance!
v3/control.go
Outdated
|
||
if pkt == nil || len(pkt.Children) == 0 { | ||
return nil, fmt.Errorf("bad packet") | ||
// Фикс бага, наличие Children для OpenLdap не обязательно. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use english comments, thank you!
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