...

Source file src/github.com/go-ldap/ldap/v3/unbind.go

Documentation: github.com/go-ldap/ldap/v3

     1  package ldap
     2  
     3  import (
     4  	"errors"
     5  
     6  	ber "github.com/go-asn1-ber/asn1-ber"
     7  )
     8  
     9  // ErrConnUnbound is returned when Unbind is called on an already closing connection.
    10  var ErrConnUnbound = NewError(ErrorNetwork, errors.New("ldap: connection is closed"))
    11  
    12  type unbindRequest struct{}
    13  
    14  func (unbindRequest) appendTo(envelope *ber.Packet) error {
    15  	envelope.AppendChild(ber.Encode(ber.ClassApplication, ber.TypePrimitive, ApplicationUnbindRequest, nil, ApplicationMap[ApplicationUnbindRequest]))
    16  	return nil
    17  }
    18  
    19  // Unbind will perform an unbind request. The Unbind operation
    20  // should be thought of as the "quit" operation.
    21  // See https://datatracker.ietf.org/doc/html/rfc4511#section-4.3
    22  func (l *Conn) Unbind() error {
    23  	if l.IsClosing() {
    24  		return ErrConnUnbound
    25  	}
    26  
    27  	_, err := l.doRequest(unbindRequest{})
    28  	if err != nil {
    29  		return err
    30  	}
    31  
    32  	// Sending an unbindRequest will make the connection unusable.
    33  	// Pending requests will fail with:
    34  	// LDAP Result Code 200 "Network Error": ldap: response channel closed
    35  	l.Close()
    36  
    37  	return nil
    38  }
    39  

View as plain text