summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorunai.avila <uavila@fonyou.com>2014-08-19 15:00:43 +0200
committerunai.avila <uavila@fonyou.com>2014-08-19 15:00:43 +0200
commitd108cf9db3a007fb1ace1f3a8369470d0b27a5fa (patch)
treed7df8bede965270f03413721ed0c2683b8bcd742
parentcleanup : unexport FilterMap & remove FilterSubstringsMap (unneeded) (diff)
downloadldap-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.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/bind.go b/bind.go
index 07417fe..c3ba8ce 100644
--- a/bind.go
+++ b/bind.go
@@ -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
+}
+