diff options
Diffstat (limited to '')
-rw-r--r-- | bind.go | 4 | ||||
-rw-r--r-- | conn.go | 10 | ||||
-rw-r--r-- | control.go | 4 | ||||
-rw-r--r-- | filter.go | 28 | ||||
-rw-r--r-- | filter_test.go | 8 | ||||
-rw-r--r-- | ldap.go | 20 | ||||
-rw-r--r-- | ldap_test.go | 26 | ||||
-rw-r--r-- | modify.go | 4 | ||||
-rw-r--r-- | search.go | 6 |
9 files changed, 53 insertions, 57 deletions
@@ -30,13 +30,13 @@ func (l *Conn) Bind(username, password string) *Error { return err } if channel == nil { - return NewError(ErrorNetwork, errors.New("Could not send message")) + return NewError(ErrorNetwork, errors.New("ldap: could not send message")) } defer l.finishMessage(messageID) packet = <-channel if packet == nil { - return NewError(ErrorNetwork, errors.New("Could not retrieve response")) + return NewError(ErrorNetwork, errors.New("ldap: could not retrieve response")) } if l.Debug { @@ -28,7 +28,7 @@ type messagePacket struct { Channel chan *ber.Packet } -// LDAP Connection +// Conn represents an LDAP Connection type Conn struct { conn net.Conn isSSL bool @@ -55,7 +55,7 @@ func Dial(network, addr string) (*Conn, *Error) { return conn, nil } -// Dial connects to the given address on the given network using net.Dial +// DialSSL connects to the given address on the given network using net.Dial // and then sets up SSL connection and returns a new Conn for the connection. func DialSSL(network, addr string, config *tls.Config) (*Conn, *Error) { c, err := tls.Dial(network, addr, config) @@ -68,7 +68,7 @@ func DialSSL(network, addr string, config *tls.Config) (*Conn, *Error) { return conn, nil } -// Dial connects to the given address on the given network using net.Dial +// DialTLS connects to the given address on the given network using net.Dial // and then starts a TLS session and returns a new Conn for the connection. func DialTLS(network, addr string, config *tls.Config) (*Conn, *Error) { c, err := net.Dial(network, addr) @@ -138,7 +138,7 @@ func (l *Conn) startTLS(config *tls.Config) *Error { messageID := l.nextMessageID() if l.isSSL { - return NewError(ErrorNetwork, errors.New("Already encrypted")) + return NewError(ErrorNetwork, errors.New("ldap: already encrypted")) } packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") @@ -176,7 +176,7 @@ func (l *Conn) startTLS(config *tls.Config) *Error { func (l *Conn) sendMessage(packet *ber.Packet) (chan *ber.Packet, *Error) { if l.isClosing { - return nil, NewError(ErrorNetwork, errors.New("Connection closed")) + return nil, NewError(ErrorNetwork, errors.New("ldap: connection closed")) } out := make(chan *ber.Packet) message := &messagePacket{ @@ -115,10 +115,10 @@ func DecodeControl(packet *ber.Packet) Control { value.Description += " (Paging)" c := new(ControlPaging) if value.Value != nil { - value_children := ber.DecodePacket(value.Data.Bytes()) + valueChildren := ber.DecodePacket(value.Data.Bytes()) value.Data.Truncate(0) value.Value = nil - value.AppendChild(value_children) + value.AppendChild(valueChildren) } value = value.Children[0] value.Description = "Search Control Value" @@ -51,14 +51,14 @@ var FilterSubstringsMap = map[uint64]string{ func CompileFilter(filter string) (*ber.Packet, *Error) { if len(filter) == 0 || filter[0] != '(' { - return nil, NewError(ErrorFilterCompile, errors.New("Filter does not start with an '('")) + return nil, NewError(ErrorFilterCompile, errors.New("ldap: filter does not start with an '('")) } packet, pos, err := compileFilter(filter, 1) if err != nil { return nil, err } if pos != len(filter) { - return nil, NewError(ErrorFilterCompile, errors.New("Finished compiling filter with extra at end.\n"+fmt.Sprint(filter[pos:]))) + return nil, NewError(ErrorFilterCompile, errors.New("ldap: finished compiling filter with extra at end.\n"+fmt.Sprint(filter[pos:]))) } return packet, nil } @@ -66,39 +66,39 @@ func CompileFilter(filter string) (*ber.Packet, *Error) { func DecompileFilter(packet *ber.Packet) (ret string, err *Error) { defer func() { if r := recover(); r != nil { - err = NewError(ErrorFilterDecompile, errors.New("Error decompiling filter")) + err = NewError(ErrorFilterDecompile, errors.New("ldap: error decompiling filter")) } }() ret = "(" err = nil - child_str := "" + childStr := "" switch packet.Tag { case FilterAnd: ret += "&" for _, child := range packet.Children { - child_str, err = DecompileFilter(child) + childStr, err = DecompileFilter(child) if err != nil { return } - ret += child_str + ret += childStr } case FilterOr: ret += "|" for _, child := range packet.Children { - child_str, err = DecompileFilter(child) + childStr, err = DecompileFilter(child) if err != nil { return } - ret += child_str + ret += childStr } case FilterNot: ret += "!" - child_str, err = DecompileFilter(packet.Children[0]) + childStr, err = DecompileFilter(packet.Children[0]) if err != nil { return } - ret += child_str + ret += childStr case FilterSubstrings: ret += ber.DecodeString(packet.Children[0].Data.Bytes()) @@ -146,7 +146,7 @@ func compileFilterSet(filter string, pos int, parent *ber.Packet) (int, *Error) parent.AppendChild(child) } if pos == len(filter) { - return pos, NewError(ErrorFilterCompile, errors.New("Unexpected end of filter")) + return pos, NewError(ErrorFilterCompile, errors.New("ldap: unexpected end of filter")) } return pos + 1, nil @@ -158,7 +158,7 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, *Error) { defer func() { if r := recover(); r != nil { - err = NewError(ErrorFilterCompile, errors.New("Error compiling filter")) + err = NewError(ErrorFilterCompile, errors.New("ldap: error compiling filter")) } }() @@ -206,11 +206,11 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, *Error) { newPos++ } if newPos == len(filter) { - err = NewError(ErrorFilterCompile, errors.New("Unexpected end of filter")) + err = NewError(ErrorFilterCompile, errors.New("ldap: unexpected end of filter")) return packet, newPos, err } if packet == nil { - err = NewError(ErrorFilterCompile, errors.New("Error parsing filter")) + err = NewError(ErrorFilterCompile, errors.New("ldap: error parsing filter")) return packet, newPos, err } packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimative, ber.TagOctetString, attribute, "Attribute")) diff --git a/filter_test.go b/filter_test.go index 4c4ce65..70f5aa3 100644 --- a/filter_test.go +++ b/filter_test.go @@ -54,10 +54,10 @@ func BenchmarkFilterCompile(b *testing.B) { filters[idx] = i.filterStr } - max_idx := len(filters) + maxIdx := len(filters) b.StartTimer() for i := 0; i < b.N; i++ { - CompileFilter(filters[i%max_idx]) + CompileFilter(filters[i%maxIdx]) } } @@ -70,9 +70,9 @@ func BenchmarkFilterDecompile(b *testing.B) { filters[idx], _ = CompileFilter(i.filterStr) } - max_idx := len(filters) + maxIdx := len(filters) b.StartTimer() for i := 0; i < b.N; i++ { - DecompileFilter(filters[i%max_idx]) + DecompileFilter(filters[i%maxIdx]) } } @@ -153,7 +153,7 @@ var LDAPResultCodeMap = map[uint8]string{ func addLDAPDescriptions(packet *ber.Packet) (err *Error) { defer func() { if r := recover(); r != nil { - err = NewError(ErrorDebugging, errors.New("Cannot process packet to add descriptions")) + err = NewError(ErrorDebugging, errors.New("ldap: cannot process packet to add descriptions")) } }() packet.Description = "LDAP Response" @@ -229,11 +229,11 @@ func addControlDescriptions(packet *ber.Packet) { case ControlTypePaging: value.Description += " (Paging)" if value.Value != nil { - value_children := ber.DecodePacket(value.Data.Bytes()) + valueChildren := ber.DecodePacket(value.Data.Bytes()) value.Data.Truncate(0) value.Value = nil - value_children.Children[1].Value = value_children.Children[1].Data.Bytes() - value.AppendChild(value_children) + valueChildren.Children[1].Value = valueChildren.Children[1].Data.Bytes() + value.AppendChild(valueChildren) } value.Children[0].Description = "Real Search Control Value" value.Children[0].Children[0].Description = "Paging Size" @@ -286,21 +286,17 @@ func (e *Error) String() string { return fmt.Sprintf("LDAP Result Code %d %q: %s", e.ResultCode, LDAPResultCodeMap[e.ResultCode], e.Err.Error()) } -func NewError(ResultCode uint8, Err error) *Error { - return &Error{ResultCode: ResultCode, Err: Err} +func NewError(resultCode uint8, err error) *Error { + return &Error{ResultCode: resultCode, Err: err} } func getLDAPResultCode(packet *ber.Packet) (code uint8, description string) { if len(packet.Children) >= 2 { response := packet.Children[1] if response.ClassType == ber.ClassApplication && response.TagType == ber.TypeConstructed && len(response.Children) == 3 { - code = uint8(response.Children[0].Value.(uint64)) - description = response.Children[2].Value.(string) - return + return uint8(response.Children[0].Value.(uint64)), response.Children[2].Value.(string) } } - code = ErrorNetwork - description = "Invalid packet format" - return + return ErrorNetwork, "Invalid packet format" } diff --git a/ldap_test.go b/ldap_test.go index 9dd9c71..48023f1 100644 --- a/ldap_test.go +++ b/ldap_test.go @@ -5,14 +5,14 @@ import ( "testing" ) -var ldapServer string = "ldap.itd.umich.edu" -var ldapPort uint16 = 389 -var baseDN string = "dc=umich,dc=edu" -var filter []string = []string{ +var ldapServer = "ldap.itd.umich.edu" +var ldapPort = uint16(389) +var baseDN = "dc=umich,dc=edu" +var filter = []string{ "(cn=cis-fac)", "(&(objectclass=rfc822mailgroup)(cn=*Computer*))", "(&(objectclass=rfc822mailgroup)(cn=*Mathematics*))"} -var attributes []string = []string{ +var attributes = []string{ "cn", "description"} @@ -36,20 +36,20 @@ func TestSearch(t *testing.T) { } defer l.Close() - search_request := NewSearchRequest( + searchRequest := NewSearchRequest( baseDN, ScopeWholeSubtree, DerefAlways, 0, 0, false, filter[0], attributes, nil) - sr, err := l.Search(search_request) + sr, err := l.Search(searchRequest) if err != nil { t.Errorf(err.String()) return } - fmt.Printf("TestSearch: %s -> num of entries = %d\n", search_request.Filter, len(sr.Entries)) + fmt.Printf("TestSearch: %s -> num of entries = %d\n", searchRequest.Filter, len(sr.Entries)) } func TestSearchWithPaging(t *testing.T) { @@ -67,29 +67,29 @@ func TestSearchWithPaging(t *testing.T) { return } - search_request := NewSearchRequest( + searchRequest := NewSearchRequest( baseDN, ScopeWholeSubtree, DerefAlways, 0, 0, false, filter[1], attributes, nil) - sr, err := l.SearchWithPaging(search_request, 5) + sr, err := l.SearchWithPaging(searchRequest, 5) if err != nil { t.Errorf(err.String()) return } - fmt.Printf("TestSearchWithPaging: %s -> num of entries = %d\n", search_request.Filter, len(sr.Entries)) + fmt.Printf("TestSearchWithPaging: %s -> num of entries = %d\n", searchRequest.Filter, len(sr.Entries)) } func testMultiGoroutineSearch(t *testing.T, l *Conn, results chan *SearchResult, i int) { - search_request := NewSearchRequest( + searchRequest := NewSearchRequest( baseDN, ScopeWholeSubtree, DerefAlways, 0, 0, false, filter[i], attributes, nil) - sr, err := l.Search(search_request) + sr, err := l.Search(searchRequest) if err != nil { t.Errorf(err.String()) results <- nil @@ -124,7 +124,7 @@ func (l *Conn) Modify(modifyRequest *ModifyRequest) *Error { return err } if channel == nil { - return NewError(ErrorNetwork, errors.New("Could not send message")) + return NewError(ErrorNetwork, errors.New("ldap: could not send message")) } defer l.finishMessage(messageID) @@ -132,7 +132,7 @@ func (l *Conn) Modify(modifyRequest *ModifyRequest) *Error { packet = <-channel l.Debug.Printf("%d: got response %p\n", messageID, packet) if packet == nil { - return NewError(ErrorNetwork, errors.New("Could not retrieve message")) + return NewError(ErrorNetwork, errors.New("ldap: could not retrieve message")) } if l.Debug { @@ -231,7 +231,7 @@ func (l *Conn) SearchWithPaging(searchRequest *SearchRequest, pagingSize uint32) return searchResult, err } if result == nil { - return searchResult, NewError(ErrorNetwork, errors.New("Packet not received")) + return searchResult, NewError(ErrorNetwork, errors.New("ldap: packet not received")) } for _, entry := range result.Entries { @@ -292,7 +292,7 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, *Error) { return nil, err } if channel == nil { - return nil, NewError(ErrorNetwork, errors.New("Could not send message")) + return nil, NewError(ErrorNetwork, errors.New("ldap: could not send message")) } defer l.finishMessage(messageID) @@ -307,7 +307,7 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, *Error) { packet = <-channel l.Debug.Printf("%d: got response %p\n", messageID, packet) if packet == nil { - return nil, NewError(ErrorNetwork, errors.New("Could not retrieve message")) + return nil, NewError(ErrorNetwork, errors.New("ldap: could not retrieve message")) } if l.Debug { |