-
Notifications
You must be signed in to change notification settings - Fork 28
/
bind.go
39 lines (31 loc) · 1.26 KB
/
bind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// File contains Bind functionality
package ldap
import (
"github.com/mavricknz/asn1-ber"
)
/*
Simple bind to the server. If using a timeout you should close the connection
on a bind failure.
*/
func (l *LDAPConnection) Bind(username, password string) error {
messageID, ok := l.nextMessageID()
if !ok {
return NewLDAPError(ErrorClosing, "MessageID channel is closed.")
}
encodedBind := encodeSimpleBindRequest(username, password)
packet, err := requestBuildPacket(messageID, encodedBind, nil)
if err != nil {
return err
}
return l.sendReqRespPacket(messageID, packet)
}
func encodeSimpleBindRequest(username, password string) (bindRequest *ber.Packet) {
bindRequest = ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationBindRequest, nil, "Bind Request")
bindRequest.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimative, ber.TagInteger, 3, "Version"))
bindRequest.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimative, ber.TagOctetString, username, "User Name"))
bindRequest.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimative, 0, password, "Password"))
return
}