Skip to content

Commit

Permalink
Resort to generic ber packet design instead of fixed octet string in …
Browse files Browse the repository at this point in the history
…requestValue
  • Loading branch information
cpuschma committed Apr 24, 2024
1 parent 49bb329 commit b6483ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (er ExtendedRequest) appendTo(envelope *ber.Packet) error {

type ExtendResponse struct {
Name string
Value string
Value *ber.Packet
}

func (l *Conn) Extended(er *ExtendedRequest) (*ExtendResponse, error) {
Expand All @@ -57,7 +57,11 @@ func (l *Conn) Extended(er *ExtendedRequest) (*ExtendResponse, error) {
if err != nil {
return nil, err
}
if len(packet.Children) < 2 || len(packet.Children[1].Children) < 4 {
if err = GetLDAPError(packet); err != nil {
return nil, err
}

if len(packet.Children[1].Children) < 4 {
return nil, fmt.Errorf(
"ldap: malformed extended response: expected 4 children, got %d",
len(packet.Children),
Expand All @@ -67,7 +71,7 @@ func (l *Conn) Extended(er *ExtendedRequest) (*ExtendResponse, error) {
response := new(ExtendResponse)
response.Name = packet.Children[1].Children[3].Data.String()
if len(packet.Children) == 4 {
response.Value = packet.Children[1].Children[4].Data.String()
response.Value = packet.Children[1].Children[4]
}

return response, nil
Expand Down
10 changes: 7 additions & 3 deletions v3/extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (er ExtendedRequest) appendTo(envelope *ber.Packet) error {

type ExtendResponse struct {
Name string
Value string
Value *ber.Packet
}

func (l *Conn) Extended(er *ExtendedRequest) (*ExtendResponse, error) {
Expand All @@ -57,7 +57,11 @@ func (l *Conn) Extended(er *ExtendedRequest) (*ExtendResponse, error) {
if err != nil {
return nil, err
}
if len(packet.Children) < 2 || len(packet.Children[1].Children) < 4 {
if err = GetLDAPError(packet); err != nil {
return nil, err
}

if len(packet.Children[1].Children) < 4 {
return nil, fmt.Errorf(
"ldap: malformed extended response: expected 4 children, got %d",
len(packet.Children),
Expand All @@ -67,7 +71,7 @@ func (l *Conn) Extended(er *ExtendedRequest) (*ExtendResponse, error) {
response := new(ExtendResponse)
response.Name = packet.Children[1].Children[3].Data.String()
if len(packet.Children) == 4 {
response.Value = packet.Children[1].Children[4].Data.String()
response.Value = packet.Children[1].Children[4]
}

return response, nil
Expand Down

0 comments on commit b6483ea

Please sign in to comment.