You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
970 B

10 years ago
10 years ago
10 years ago
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "fmt"
  7. "log"
  8. "github.com/gogits/gogs/modules/ldap"
  9. )
  10. var (
  11. LdapServer string = "localhost"
  12. LdapPort uint16 = 636
  13. BaseDN string = "dc=enterprise,dc=org"
  14. Filter string = "(cn=kirkj)"
  15. Attributes []string = []string{"mail"}
  16. )
  17. func main() {
  18. l, err := ldap.DialSSL("tcp", fmt.Sprintf("%s:%d", LdapServer, LdapPort), nil)
  19. if err != nil {
  20. log.Fatalf("ERROR: %s\n", err.String())
  21. }
  22. defer l.Close()
  23. // l.Debug = true
  24. search := ldap.NewSearchRequest(
  25. BaseDN,
  26. ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
  27. Filter,
  28. Attributes,
  29. nil)
  30. sr, err := l.Search(search)
  31. if err != nil {
  32. log.Fatalf("ERROR: %s\n", err.String())
  33. return
  34. }
  35. log.Printf("Search: %s -> num of entries = %d\n", search.Filter, len(sr.Entries))
  36. sr.PrettyPrint(0)
  37. }