Skip to content

Fix ControlServerSideSortingResult handling for OpenLDAP #546

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

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions v3/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func NewControlServerSideSorting(value *ber.Packet) (*ControlServerSideSorting,
sequences := val[0].Children

for i, sequence := range sequences {
sortKey := &SortKey{}
sortKey := new(SortKey)

if len(sequence.Children) < 2 {
return nil, fmt.Errorf("attributeType or matchingRule is missing from sequence %d", i)
Expand Down Expand Up @@ -864,19 +864,22 @@ func (c ControlServerSideSortingCode) Valid() error {
}

func NewControlServerSideSortingResult(pkt *ber.Packet) (*ControlServerSideSortingResult, error) {
control := &ControlServerSideSortingResult{}
control := new(ControlServerSideSortingResult)

if pkt == nil || len(pkt.Children) == 0 {
return nil, fmt.Errorf("bad packet")
// This is currently not compliant with the ServerSideSorting RFC (see https://datatracker.ietf.org/doc/html/rfc2891#section-1.2).
// but it's necessary because there seems to be a bug in the implementation of the popular OpenLDAP server.
//
// See: https://github.com/go-ldap/ldap/pull/546
return control, nil
}

codeInt, err := ber.ParseInt64(pkt.Children[0].Data.Bytes())
if err != nil {
return nil, err
}

code := ControlServerSideSortingCode(codeInt)
if err := code.Valid(); err != nil {
if err = ControlServerSideSortingCode(codeInt).Valid(); err != nil {
return nil, err
}

Expand Down
Loading