From d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 17 May 2017 16:51:25 -0400 Subject: Upgrading server dependancies (#6431) --- vendor/github.com/go-ldap/ldap/Makefile | 12 +++++++- vendor/github.com/go-ldap/ldap/atomic_value.go | 13 +++++++++ .../github.com/go-ldap/ldap/atomic_value_go13.go | 28 ++++++++++++++++++ vendor/github.com/go-ldap/ldap/conn.go | 33 ++++++++++++++-------- vendor/github.com/go-ldap/ldap/conn_test.go | 6 +--- vendor/github.com/go-ldap/ldap/error.go | 7 +++++ vendor/github.com/go-ldap/ldap/example_test.go | 2 +- 7 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 vendor/github.com/go-ldap/ldap/atomic_value.go create mode 100644 vendor/github.com/go-ldap/ldap/atomic_value_go13.go (limited to 'vendor/github.com/go-ldap') diff --git a/vendor/github.com/go-ldap/ldap/Makefile b/vendor/github.com/go-ldap/ldap/Makefile index c1fc96657..f7899f59a 100644 --- a/vendor/github.com/go-ldap/ldap/Makefile +++ b/vendor/github.com/go-ldap/ldap/Makefile @@ -1,5 +1,15 @@ .PHONY: default install build test quicktest fmt vet lint +GO_VERSION := $(shell go version | cut -d' ' -f3 | cut -d. -f2) + +# Only use the `-race` flag on newer versions of Go +IS_OLD_GO := $(shell test $(GO_VERSION) -le 2 && echo true) +ifeq ($(IS_OLD_GO),true) + RACE_FLAG := +else + RACE_FLAG := -race +endif + default: fmt vet lint build quicktest install: @@ -9,7 +19,7 @@ build: go build -v ./... test: - go test -v -cover ./... + go test -v $(RACE_FLAG) -cover ./... quicktest: go test ./... diff --git a/vendor/github.com/go-ldap/ldap/atomic_value.go b/vendor/github.com/go-ldap/ldap/atomic_value.go new file mode 100644 index 000000000..bccf7573e --- /dev/null +++ b/vendor/github.com/go-ldap/ldap/atomic_value.go @@ -0,0 +1,13 @@ +// +build go1.4 + +package ldap + +import ( + "sync/atomic" +) + +// For compilers that support it, we just use the underlying sync/atomic.Value +// type. +type atomicValue struct { + atomic.Value +} diff --git a/vendor/github.com/go-ldap/ldap/atomic_value_go13.go b/vendor/github.com/go-ldap/ldap/atomic_value_go13.go new file mode 100644 index 000000000..04920bb26 --- /dev/null +++ b/vendor/github.com/go-ldap/ldap/atomic_value_go13.go @@ -0,0 +1,28 @@ +// +build !go1.4 + +package ldap + +import ( + "sync" +) + +// This is a helper type that emulates the use of the "sync/atomic.Value" +// struct that's available in Go 1.4 and up. +type atomicValue struct { + value interface{} + lock sync.RWMutex +} + +func (av *atomicValue) Store(val interface{}) { + av.lock.Lock() + av.value = val + av.lock.Unlock() +} + +func (av *atomicValue) Load() interface{} { + av.lock.RLock() + ret := av.value + av.lock.RUnlock() + + return ret +} diff --git a/vendor/github.com/go-ldap/ldap/conn.go b/vendor/github.com/go-ldap/ldap/conn.go index b5bd99adb..e701a9b66 100644 --- a/vendor/github.com/go-ldap/ldap/conn.go +++ b/vendor/github.com/go-ldap/ldap/conn.go @@ -11,6 +11,7 @@ import ( "log" "net" "sync" + "sync/atomic" "time" "gopkg.in/asn1-ber.v1" @@ -82,8 +83,8 @@ const ( type Conn struct { conn net.Conn isTLS bool - isClosing bool - closeErr error + closeCount uint32 + closeErr atomicValue isStartingTLS bool Debug debugging chanConfirm chan bool @@ -158,10 +159,20 @@ func (l *Conn) Start() { l.wgClose.Add(1) } +// isClosing returns whether or not we're currently closing. +func (l *Conn) isClosing() bool { + return atomic.LoadUint32(&l.closeCount) > 0 +} + +// setClosing sets the closing value to true +func (l *Conn) setClosing() { + atomic.AddUint32(&l.closeCount, 1) +} + // Close closes the connection. func (l *Conn) Close() { l.once.Do(func() { - l.isClosing = true + l.setClosing() l.wgSender.Wait() l.Debug.Printf("Sending quit message and waiting for confirmation") @@ -258,7 +269,7 @@ func (l *Conn) sendMessage(packet *ber.Packet) (*messageContext, error) { } func (l *Conn) sendMessageWithFlags(packet *ber.Packet, flags sendMessageFlags) (*messageContext, error) { - if l.isClosing { + if l.isClosing() { return nil, NewError(ErrorNetwork, errors.New("ldap: connection closed")) } l.messageMutex.Lock() @@ -297,7 +308,7 @@ func (l *Conn) sendMessageWithFlags(packet *ber.Packet, flags sendMessageFlags) func (l *Conn) finishMessage(msgCtx *messageContext) { close(msgCtx.done) - if l.isClosing { + if l.isClosing() { return } @@ -316,7 +327,7 @@ func (l *Conn) finishMessage(msgCtx *messageContext) { } func (l *Conn) sendProcessMessage(message *messagePacket) bool { - if l.isClosing { + if l.isClosing() { return false } l.wgSender.Add(1) @@ -333,8 +344,8 @@ func (l *Conn) processMessages() { for messageID, msgCtx := range l.messageContexts { // If we are closing due to an error, inform anyone who // is waiting about the error. - if l.isClosing && l.closeErr != nil { - msgCtx.sendResponse(&PacketResponse{Error: l.closeErr}) + if l.isClosing() && l.closeErr.Load() != nil { + msgCtx.sendResponse(&PacketResponse{Error: l.closeErr.Load().(error)}) } l.Debug.Printf("Closing channel for MessageID %d", messageID) close(msgCtx.responses) @@ -397,7 +408,7 @@ func (l *Conn) processMessages() { if msgCtx, ok := l.messageContexts[message.MessageID]; ok { msgCtx.sendResponse(&PacketResponse{message.Packet, nil}) } else { - log.Printf("Received unexpected message %d, %v", message.MessageID, l.isClosing) + log.Printf("Received unexpected message %d, %v", message.MessageID, l.isClosing()) ber.PrintPacket(message.Packet) } case MessageTimeout: @@ -439,8 +450,8 @@ func (l *Conn) reader() { packet, err := ber.ReadPacket(l.conn) if err != nil { // A read error is expected here if we are closing the connection... - if !l.isClosing { - l.closeErr = fmt.Errorf("unable to read LDAP response packet: %s", err) + if !l.isClosing() { + l.closeErr.Store(fmt.Errorf("unable to read LDAP response packet: %s", err)) l.Debug.Printf("reader error: %s", err.Error()) } return diff --git a/vendor/github.com/go-ldap/ldap/conn_test.go b/vendor/github.com/go-ldap/ldap/conn_test.go index 10766bbd4..30554d23c 100644 --- a/vendor/github.com/go-ldap/ldap/conn_test.go +++ b/vendor/github.com/go-ldap/ldap/conn_test.go @@ -60,7 +60,7 @@ func TestUnresponsiveConnection(t *testing.T) { // TestFinishMessage tests that we do not enter deadlock when a goroutine makes // a request but does not handle all responses from the server. -func TestConn(t *testing.T) { +func TestFinishMessage(t *testing.T) { ptc := newPacketTranslatorConn() defer ptc.Close() @@ -174,16 +174,12 @@ func testSendUnhandledResponsesAndFinish(t *testing.T, ptc *packetTranslatorConn } func runWithTimeout(t *testing.T, timeout time.Duration, f func()) { - runtime.Gosched() - done := make(chan struct{}) go func() { f() close(done) }() - runtime.Gosched() - select { case <-done: // Success! case <-time.After(timeout): diff --git a/vendor/github.com/go-ldap/ldap/error.go b/vendor/github.com/go-ldap/ldap/error.go index ff697873d..4cccb537f 100644 --- a/vendor/github.com/go-ldap/ldap/error.go +++ b/vendor/github.com/go-ldap/ldap/error.go @@ -97,6 +97,13 @@ var LDAPResultCodeMap = map[uint8]string{ LDAPResultObjectClassModsProhibited: "Object Class Mods Prohibited", LDAPResultAffectsMultipleDSAs: "Affects Multiple DSAs", LDAPResultOther: "Other", + + ErrorNetwork: "Network Error", + ErrorFilterCompile: "Filter Compile Error", + ErrorFilterDecompile: "Filter Decompile Error", + ErrorDebugging: "Debugging Error", + ErrorUnexpectedMessage: "Unexpected Message", + ErrorUnexpectedResponse: "Unexpected Response", } func getLDAPResultCode(packet *ber.Packet) (code uint8, description string) { diff --git a/vendor/github.com/go-ldap/ldap/example_test.go b/vendor/github.com/go-ldap/ldap/example_test.go index b018a9664..821189bd6 100644 --- a/vendor/github.com/go-ldap/ldap/example_test.go +++ b/vendor/github.com/go-ldap/ldap/example_test.go @@ -193,7 +193,7 @@ func Example_userAuthentication() { searchRequest := ldap.NewSearchRequest( "dc=example,dc=com", ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, - fmt.Sprintf("(&(objectClass=organizationalPerson)&(uid=%s))", username), + fmt.Sprintf("(&(objectClass=organizationalPerson)(uid=%s))", username), []string{"dn"}, nil, ) -- cgit v1.2.3-1-g7c22