Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial cut of context support #406

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion add.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ldap

import (
"context"

ber "github.com/go-asn1-ber/asn1-ber"
)

Expand Down Expand Up @@ -66,7 +68,12 @@ func NewAddRequest(dn string, controls []Control) *AddRequest {

// Add performs the given AddRequest
func (l *Conn) Add(addRequest *AddRequest) error {
msgCtx, err := l.doRequest(addRequest)
return l.AddContext(l.ctx, addRequest)
}

// AddContext performs the given AddRequest
func (l *Conn) AddContext(ctx context.Context, addRequest *AddRequest) error {
msgCtx, err := l.doRequest(ctx, addRequest)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (l *Conn) SimpleBind(simpleBindRequest *SimpleBindRequest) (*SimpleBindResu
return nil, NewError(ErrorEmptyPassword, errors.New("ldap: empty password not allowed by the client"))
}

msgCtx, err := l.doRequest(simpleBindRequest)
msgCtx, err := l.doRequest(l.ctx, simpleBindRequest)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func (l *Conn) DigestMD5Bind(digestMD5BindRequest *DigestMD5BindRequest) (*Diges
return nil, NewError(ErrorEmptyPassword, errors.New("ldap: empty password not allowed by the client"))
}

msgCtx, err := l.doRequest(digestMD5BindRequest)
msgCtx, err := l.doRequest(l.ctx, digestMD5BindRequest)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func (l *Conn) DigestMD5Bind(digestMD5BindRequest *DigestMD5BindRequest) (*Diges
auth.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, resp, "Credentials"))
request.AppendChild(auth)
packet.AppendChild(request)
msgCtx, err = l.sendMessage(packet)
msgCtx, err = l.sendMessage(l.ctx, packet)
if err != nil {
return nil, fmt.Errorf("send message: %s", err)
}
Expand Down Expand Up @@ -375,7 +375,7 @@ var externalBindRequest = requestFunc(func(envelope *ber.Packet) error {
//
// See https://tools.ietf.org/html/rfc4422#appendix-A
func (l *Conn) ExternalBind() error {
msgCtx, err := l.doRequest(externalBindRequest)
msgCtx, err := l.doRequest(l.ctx, externalBindRequest)
if err != nil {
return err
}
Expand Down Expand Up @@ -478,7 +478,7 @@ func (l *Conn) NTLMChallengeBind(ntlmBindRequest *NTLMBindRequest) (*NTLMBindRes
return nil, NewError(ErrorEmptyPassword, errors.New("ldap: empty password not allowed by the client"))
}

msgCtx, err := l.doRequest(ntlmBindRequest)
msgCtx, err := l.doRequest(l.ctx, ntlmBindRequest)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -538,7 +538,7 @@ func (l *Conn) NTLMChallengeBind(ntlmBindRequest *NTLMBindRequest) (*NTLMBindRes

request.AppendChild(auth)
packet.AppendChild(request)
msgCtx, err = l.sendMessage(packet)
msgCtx, err = l.sendMessage(l.ctx, packet)
if err != nil {
return nil, fmt.Errorf("send message: %s", err)
}
Expand Down Expand Up @@ -671,7 +671,7 @@ func (l *Conn) saslBindTokenExchange(reqControls []Control, reqToken []byte) ([]
envelope.AppendChild(encodeControls(reqControls))
}

msgCtx, err := l.sendMessage(envelope)
msgCtx, err := l.sendMessage(l.ctx, envelope)
if err != nil {
return nil, err
}
Expand Down
10 changes: 10 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ldap

import (
"context"
"crypto/tls"
"time"
)
Expand All @@ -22,14 +23,23 @@ type Client interface {
Unbind() error

Add(*AddRequest) error
AddContext(context.Context, *AddRequest) error
Del(*DelRequest) error
DelContext(context.Context, *DelRequest) error
Modify(*ModifyRequest) error
ModifyContext(context.Context, *ModifyRequest) error
ModifyDN(*ModifyDNRequest) error
ModifyDNContext(context.Context, *ModifyDNRequest) error
ModifyWithResult(*ModifyRequest) (*ModifyResult, error)
ModifyWithResultContext(context.Context, *ModifyRequest) (*ModifyResult, error)

Compare(dn, attribute, value string) (bool, error)
CompareContext(ctx context.Context, dn, attribute, value string) (bool, error)
PasswordModify(*PasswordModifyRequest) (*PasswordModifyResult, error)
PasswordModifyContext(context.Context, *PasswordModifyRequest) (*PasswordModifyResult, error)

Search(*SearchRequest) (*SearchResult, error)
SearchContext(context.Context, *SearchRequest) (*SearchResult, error)
SearchWithPaging(searchRequest *SearchRequest, pagingSize uint32) (*SearchResult, error)
SearchWithPagingContext(ctx context.Context, searchRequest *SearchRequest, pagingSize uint32) (*SearchResult, error)
}
9 changes: 8 additions & 1 deletion compare.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ldap

import (
"context"
"fmt"

ber "github.com/go-asn1-ber/asn1-ber"
Expand Down Expand Up @@ -31,7 +32,13 @@ func (req *CompareRequest) appendTo(envelope *ber.Packet) error {
// Compare checks to see if the attribute of the dn matches value. Returns true if it does otherwise
// false with any error that occurs if any.
func (l *Conn) Compare(dn, attribute, value string) (bool, error) {
msgCtx, err := l.doRequest(&CompareRequest{
return l.CompareContext(l.ctx, dn, attribute, value)
}

// CompareContext checks to see if the attribute of the dn matches value. Returns true if it does otherwise
// false with any error that occurs if any.
func (l *Conn) CompareContext(ctx context.Context, dn, attribute, value string) (bool, error) {
msgCtx, err := l.doRequest(ctx, &CompareRequest{
DN: dn,
Attribute: attribute,
Value: value})
Expand Down
Loading