diff options
author | unai.avila <uavila@fonyou.com> | 2014-08-19 15:00:43 +0200 |
---|---|---|
committer | unai.avila <uavila@fonyou.com> | 2014-08-19 15:00:43 +0200 |
commit | d108cf9db3a007fb1ace1f3a8369470d0b27a5fa (patch) | |
tree | d7df8bede965270f03413721ed0c2683b8bcd742 | |
parent | cleanup : unexport FilterMap & remove FilterSubstringsMap (unneeded) (diff) | |
download | ldap-d108cf9db3a007fb1ace1f3a8369470d0b27a5fa.tar ldap-d108cf9db3a007fb1ace1f3a8369470d0b27a5fa.tar.gz ldap-d108cf9db3a007fb1ace1f3a8369470d0b27a5fa.tar.bz2 ldap-d108cf9db3a007fb1ace1f3a8369470d0b27a5fa.tar.lz ldap-d108cf9db3a007fb1ace1f3a8369470d0b27a5fa.tar.xz ldap-d108cf9db3a007fb1ace1f3a8369470d0b27a5fa.tar.zst ldap-d108cf9db3a007fb1ace1f3a8369470d0b27a5fa.zip |
-rw-r--r-- | bind.go | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -53,3 +53,47 @@ func (l *Conn) Bind(username, password string) error { return nil } + +func (l *Conn) Unbind() error { + defer l.Close() + + messageID := l.nextMessageID() + + packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) + unbindRequest := ber.Encode(ber.ClassApplication, ber.TypePrimitive, ApplicationUnbindRequest, nil, "Unbind Request") + packet.AppendChild(unbindRequest) + + if l.Debug { + ber.PrintPacket(packet) + } + + channel, err := l.sendMessage(packet) + if err != nil { + return err + } + if channel == nil { + return NewError(ErrorNetwork, errors.New("ldap: could not send message")) + } + defer l.finishMessage(messageID) + + packet = <-channel + if packet == nil { + return NewError(ErrorNetwork, errors.New("ldap: could not retrieve response")) + } + + if l.Debug { + if err := addLDAPDescriptions(packet); err != nil { + return err + } + ber.PrintPacket(packet) + } + + resultCode, resultDescription := getLDAPResultCode(packet) + if resultCode != 0 { + return NewError(resultCode, errors.New(resultDescription)) + } + + return nil +} + |