func main() { l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", LdapServer, LdapPort)) if err != nil { log.Fatalf("ERROR: %s\n", err.Error()) } defer l.Close() // l.Debug = true l.Bind(BindDN, BindPW) log.Printf("The Search for Kirk ... %s\n", Filter) entry, err := search(l, Filter, []string{}) if err != nil { log.Fatal("could not get entry") } entry.PrettyPrint(0) log.Printf("modify the mail address and add a description ... \n") modify := ldap.NewModifyRequest(entry.DN) modify.Add("description", []string{"Captain of the USS Enterprise"}) modify.Replace("mail", []string{"*****@*****.**"}) if err := l.Modify(modify); err != nil { log.Fatalf("ERROR: %s\n", err.Error()) } entry, err = search(l, Filter, []string{}) if err != nil { log.Fatal("could not get entry") } entry.PrettyPrint(0) log.Printf("reset the entry ... \n") modify = ldap.NewModifyRequest(entry.DN) modify.Delete("description", []string{}) modify.Replace("mail", []string{"*****@*****.**"}) if err := l.Modify(modify); err != nil { log.Fatalf("ERROR: %s\n", err.Error()) } entry, err = search(l, Filter, []string{}) if err != nil { log.Fatal("could not get entry") } entry.PrettyPrint(0) }
func (h ldapHandler) getSession(conn net.Conn) (session, error) { id := connID(conn) h.lock.Lock() s, ok := h.sessions[id] // use server connection if it exists h.lock.Unlock() if !ok { // open a new server connection if not l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", h.ldapServer, h.ldapPort)) if err != nil { return session{}, err } //l.Debug = true s = session{id: id, c: conn, ldap: l} h.lock.Lock() h.sessions[s.id] = s h.lock.Unlock() } return s, nil }