Skip to content
Draft
Show file tree
Hide file tree
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
32 changes: 28 additions & 4 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,37 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
}

switch packet.Children[1].Tag {
case 4:
case ApplicationSearchResultEntry:
entry := &Entry{
DN: packet.Children[1].Children[0].Value.(string),
Attributes: unpackAttributes(packet.Children[1].Children[1].Children),
}
result.Entries = append(result.Entries, entry)
case 5:
case ApplicationSearchResultDone:
err := GetLDAPError(packet)
if err != nil {
if IsErrorWithCode(err, LDAPResultReferral) && len(packet.Children) >= 2 {
var (
referral string
ok bool
)

for _, child := range packet.Children[1].Children {
if child.Tag == ber.TagBitString && len(child.Children) >= 1 {
referral, ok = child.Children[0].Value.(string)

if ok {
break
}
}
}

if ok {
result.Referrals = append(result.Referrals, referral)
continue
}
}

return result, err
}
if len(packet.Children) == 3 {
Expand All @@ -393,8 +415,10 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
}
}
return result, nil
case 19:
result.Referrals = append(result.Referrals, packet.Children[1].Children[0].Value.(string))
case ApplicationSearchResultReference:
if len(packet.Children) >= 2 && len(packet.Children[1].Children) >= 1 {
result.Referrals = append(result.Referrals, packet.Children[1].Children[0].Value.(string))
}
}
}
}
Expand Down
32 changes: 28 additions & 4 deletions v3/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,37 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
}

switch packet.Children[1].Tag {
case 4:
case ApplicationSearchResultEntry:
entry := &Entry{
DN: packet.Children[1].Children[0].Value.(string),
Attributes: unpackAttributes(packet.Children[1].Children[1].Children),
}
result.Entries = append(result.Entries, entry)
case 5:
case ApplicationSearchResultDone:
err := GetLDAPError(packet)
if err != nil {
if IsErrorWithCode(err, LDAPResultReferral) && len(packet.Children) >= 2 {
var (
referral string
ok bool
)

for _, child := range packet.Children[1].Children {
if child.Tag == ber.TagBitString && len(child.Children) >= 1 {
referral, ok = child.Children[0].Value.(string)

if ok {
break
}
}
}

if ok {
result.Referrals = append(result.Referrals, referral)
continue
}
}

return result, err
}
if len(packet.Children) == 3 {
Expand All @@ -393,8 +415,10 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
}
}
return result, nil
case 19:
result.Referrals = append(result.Referrals, packet.Children[1].Children[0].Value.(string))
case ApplicationSearchResultReference:
if len(packet.Children) >= 2 && len(packet.Children[1].Children) >= 1 {
result.Referrals = append(result.Referrals, packet.Children[1].Children[0].Value.(string))
}
}
}
}
Expand Down