Skip to content
Merged
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
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

default: fmt vet lint build test

CONTAINER_CMD := $(shell command -v podman 2>/dev/null)
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD := $(shell command -v docker 2>/dev/null)
endif

# Check if we found either command
CONTAINER_CMD := $(shell command -v docker 2>/dev/null || shell command -v podman 2>/dev/null)
ifeq ($(CONTAINER_CMD),)
$(error Neither podman nor docker found in PATH)
endif
Expand All @@ -25,7 +20,7 @@ LDAP_URL := ldap://127.0.0.1:389
CONTAINER_NAME := go-ldap-test

local-server:
-$(CONTAINER_CMD) rm -f -t 10 $(CONTAINER_NAME)
-$(CONTAINER_CMD) rm -f $(CONTAINER_NAME)
$(CONTAINER_CMD) \
run \
--rm \
Expand Down
36 changes: 19 additions & 17 deletions v3/extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ type ExtendedResponse struct {
// responseName [10] LDAPOID OPTIONAL,
// responseValue [11] OCTET STRING OPTIONAL }

Name string
Value *ber.Packet
Controls []Control
Name string
ResultCode int
Referral string
Value *ber.Packet
Controls []Control
}

// Extended performs an extended request. The resulting
Expand All @@ -76,24 +78,28 @@ func (l *Conn) Extended(er *ExtendedRequest) (*ExtendedResponse, error) {
return nil, err
}

if len(packet.Children[1].Children) < 3 {
extResp := packet.Children[1]
if len(extResp.Children) < 3 {
return nil, fmt.Errorf(
"ldap: malformed extended response: expected at least 3 children, got %d",
len(packet.Children),
)
}

var name string

if len(packet.Children[1].Children) < 4 {
name = er.Name
} else {
name = packet.Children[1].Children[3].Data.String()
response := &ExtendedResponse{
ResultCode: int(extResp.Children[0].Value.(int64)),
Controls: make([]Control, 0),
}

response := &ExtendedResponse{
Name: name,
Controls: make([]Control, 0),
for _, child := range extResp.Children {
switch child.Tag {
case ber.TagBitString:
response.Referral = child.Value.(string)
case ber.TagEnumerated:
response.Name = child.Data.String()
case ber.TagEmbeddedPDV:
response.Value = child
}
}

if len(packet.Children) == 3 {
Expand All @@ -106,9 +112,5 @@ func (l *Conn) Extended(er *ExtendedRequest) (*ExtendedResponse, error) {
}
}

if len(packet.Children[1].Children) == 5 {
response.Value = packet.Children[1].Children[4]
}

return response, nil
}
4 changes: 2 additions & 2 deletions v3/extended_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestExtendedRequest_FastBind(t *testing.T) {
}
defer conn.Close()

request := NewExtendedRequest("1.3.6.1.4.1.4203.1.11.3", nil)
request := NewExtendedRequest("1.2.840.113556.1.4.1781", nil)
_, err = conn.Extended(request)
assert.NoError(t, err)
assert.Error(t, err)
}
Loading