Skip to content

Commit

Permalink
Fix LDAP GetError and LDAP search (#509)
Browse files Browse the repository at this point in the history
* When trying to parse ldap error, value can be nil
  • Loading branch information
gustavoluvizotto authored May 3, 2024
1 parent 17409dc commit 56e5759
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func GetLDAPError(packet *ber.Packet) error {
return &Error{
ResultCode: resultCode,
MatchedDN: response.Children[1].Value.(string),
Err: fmt.Errorf("%s", response.Children[2].Value.(string)),
Err: fmt.Errorf("%v", response.Children[2].Value),
Packet: packet,
}
}
Expand Down
6 changes: 5 additions & 1 deletion search.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,13 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
return result, ErrSizeLimitExceeded
}

attr := make([]*ber.Packet, 0)
if len(packet.Children[1].Children) > 1 {
attr = packet.Children[1].Children[1].Children
}
entry := &Entry{
DN: packet.Children[1].Children[0].Value.(string),
Attributes: unpackAttributes(packet.Children[1].Children[1].Children),
Attributes: unpackAttributes(attr),
}
result.Entries = append(result.Entries, entry)
case 5:
Expand Down
2 changes: 1 addition & 1 deletion v3/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func GetLDAPError(packet *ber.Packet) error {
return &Error{
ResultCode: resultCode,
MatchedDN: response.Children[1].Value.(string),
Err: fmt.Errorf("%s", response.Children[2].Value.(string)),
Err: fmt.Errorf("%v", response.Children[2].Value),
Packet: packet,
}
}
Expand Down
6 changes: 5 additions & 1 deletion v3/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,13 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
return result, ErrSizeLimitExceeded
}

attr := make([]*ber.Packet, 0)
if len(packet.Children[1].Children) > 1 {
attr = packet.Children[1].Children[1].Children
}
entry := &Entry{
DN: packet.Children[1].Children[0].Value.(string),
Attributes: unpackAttributes(packet.Children[1].Children[1].Children),
Attributes: unpackAttributes(attr),
}
result.Entries = append(result.Entries, entry)
case 5:
Expand Down

0 comments on commit 56e5759

Please sign in to comment.