Exemple #1
0
//TODO refactor variable names
func GetFromLDAP(connect *ldap.Conn, LDAPBaseDN, LDAPFilter string, LDAPAttribute []string, LDAPPage uint32) *[]LDAPElement {
	searchRequest := ldap.NewSearchRequest(LDAPBaseDN, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, LDAPFilter, LDAPAttribute, nil)
	sr, err := connect.SearchWithPaging(searchRequest, LDAPPage)
	CheckForError(err)
	//fmt.Println(len(sr.Entries))
	ADElements := []LDAPElement{}
	for _, entry := range sr.Entries {
		NewADEntity := new(LDAPElement)
		NewADEntity.DN = entry.DN
		for _, attrib := range entry.Attributes {
			NewADEntity.attributes = append(NewADEntity.attributes, keyvalue{attrib.Name: attrib.Values})
		}
		ADElements = append(ADElements, *NewADEntity)
	}
	return &ADElements
}
Exemple #2
0
func GetFromAD(connect *ldap.Conn, ADBaseDN, ADFilter string, ADAttribute []string, ADPage uint32) *[]LDAPElement {
	//sizelimit in searchrequest is the limit, which throws an error when the number of results exceeds the limit.
	searchRequest := ldap.NewSearchRequest(ADBaseDN, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, ADFilter, ADAttribute, nil)
	sr, err := connect.SearchWithPaging(searchRequest, ADPage)
	CheckForError(err)
	//fmt.Println(len(sr.Entries))
	ADElements := []LDAPElement{}
	for _, entry := range sr.Entries {
		NewADEntity := new(LDAPElement)
		NewADEntity.DN = entry.DN
		for _, attrib := range entry.Attributes {
			NewADEntity.attributes = append(NewADEntity.attributes, keyvalue{attrib.Name: attrib.Values})
		}
		ADElements = append(ADElements, *NewADEntity)
	}
	return &ADElements
}