From a55d800e4c5105fa024a1f3b6b1004cc780b7543 Mon Sep 17 00:00:00 2001 From: kozlov-e Date: Thu, 30 Jan 2025 06:31:34 +0300 Subject: [PATCH 1/2] fix: handle missing sorting control in OpenLDAP response --- v3/control.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/v3/control.go b/v3/control.go index ab75c342..a20acd4e 100644 --- a/v3/control.go +++ b/v3/control.go @@ -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) @@ -864,10 +864,11 @@ 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") + // Фикс бага, наличие Children для OpenLdap не обязательно. + return control, nil } codeInt, err := ber.ParseInt64(pkt.Children[0].Data.Bytes()) @@ -875,8 +876,7 @@ func NewControlServerSideSortingResult(pkt *ber.Packet) (*ControlServerSideSorti return nil, err } - code := ControlServerSideSortingCode(codeInt) - if err := code.Valid(); err != nil { + if err = ControlServerSideSortingCode(codeInt).Valid(); err != nil { return nil, err } From 99a0beef9ba40d1d314a9c85d0dfbf0d2d95af99 Mon Sep 17 00:00:00 2001 From: Christopher Puschmann Date: Wed, 19 Feb 2025 23:15:37 +0100 Subject: [PATCH 2/2] Update control.go --- v3/control.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/v3/control.go b/v3/control.go index a20acd4e..6267e210 100644 --- a/v3/control.go +++ b/v3/control.go @@ -867,7 +867,10 @@ func NewControlServerSideSortingResult(pkt *ber.Packet) (*ControlServerSideSorti control := new(ControlServerSideSortingResult) if pkt == nil || len(pkt.Children) == 0 { - // Фикс бага, наличие Children для OpenLdap не обязательно. + // 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 }