From 255544907377f696c1046c86f8f327060b1db010 Mon Sep 17 00:00:00 2001 From: juju2013 Date: Fri, 18 Apr 2014 15:55:25 +0200 Subject: make examples search works --- examples/search.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'examples') diff --git a/examples/search.go b/examples/search.go index 77fc214..9618123 100644 --- a/examples/search.go +++ b/examples/search.go @@ -12,31 +12,38 @@ import ( ) var ( - LdapServer string = "localhost" - LdapPort uint16 = 389 - BaseDN string = "dc=enterprise,dc=org" - Filter string = "(cn=kirkj)" - Attributes []string = []string{"mail"} + ldapServer string = "adserver" + ldapPort uint16 = 3268 + baseDN string = "dc=*,dc=*" + filter string = "(&(objectClass=user)(sAMAccountName=*)(memberOf=CN=*,OU=*,DC=*,DC=*))" + Attributes []string = []string{"memberof"} + user string = "*" + passwd string = "*" ) func main() { - l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", LdapServer, LdapPort)) + l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) if err != nil { - log.Fatalf("ERROR: %s\n", err.String()) + log.Fatalf("ERROR: %s\n", err.Error()) } defer l.Close() // l.Debug = true + err = l.Bind(user, passwd) + if err != nil { + log.Printf("ERROR: Cannot bind: %s\n", err.Error()) + return + } search := ldap.NewSearchRequest( - BaseDN, + baseDN, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, - Filter, + filter, Attributes, nil) sr, err := l.Search(search) if err != nil { - log.Fatalf("ERROR: %s\n", err.String()) + log.Fatalf("ERROR: %s\n", err.Error()) return } -- cgit v1.2.3