diff --git a/Makefile b/Makefile index db20a825..4d6ba1e9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 \ diff --git a/v3/extended.go b/v3/extended.go index 08c8e891..d13e5abf 100644 --- a/v3/extended.go +++ b/v3/extended.go @@ -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 @@ -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 { @@ -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 } diff --git a/v3/extended_test.go b/v3/extended_test.go index 8d9ef63f..247e1dc5 100644 --- a/v3/extended_test.go +++ b/v3/extended_test.go @@ -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) }