// ReadAll searches for all objects which are of the same type as item and match the criteria. // dn is the root of the subtree which is searched, scope is the scope of the search, filter // is a fmt format string used as filter with args being values for the format string. The arguments are // automatically escaped and must fmt.Print to a sane (at least for your LDAP data) value. func (c *Manager) ReadAll(item Item, dn string, scope Scope, filter string, args ...interface{}) ([]Item, error) { filteredArgs := make([]interface{}, len(args)) for i, v := range args { filteredArgs[i] = ldap.FilterReplace(fmt.Sprint(v)) } realFilter := fmt.Sprintf(filter, filteredArgs...) searchRequest := ldap.NewSimpleSearchRequest(c.appendBaseDn(dn), ldap.Scope(scope), realFilter, nil) if c.Debug { log.Println("Search Request:", searchRequest) } results, err := c.conn.Search(searchRequest) if err != nil { return nil, err } items := make([]Item, len(results.Entries)) for i, v := range results.Entries { v.DN = c.removeBaseDn(v.DN) items[i] = item.Copy() items[i].UnmarshalLDAP(v) if err != nil { return nil, err } } return items, nil }
// Search for all objects which are of the same type as item and match the criteria. // dn is the root of the subtree which is searched, scope is the scope of the search, filter // is an ldap filter string. func (c *Manager) ReadAll(item Item, dn string, scope Scope, filter string) ([]Item, error) { searchRequest := ldap.NewSimpleSearchRequest(c.appendBaseDn(dn), ldap.Scope(scope), filter, nil) if c.Debug { log.Println("Search Request:", searchRequest) } results, err := c.conn.Search(searchRequest) if err != nil { return nil, err } items := make([]Item, len(results.Entries)) for i, v := range results.Entries { v.DN = c.removeBaseDn(v.DN) items[i] = item.Copy() items[i].UnmarshalLDAP(v) if err != nil { return nil, err } } return items, nil }