Browse Source

Fix the code to match the documentation.

Permit for LDAP groups to be groupofuniquenames composed of uniquename (DN).
For this, propose DN as group_search_filter_user_attribute and DN also for the member_of in the server.attributes section.

DN is processed as a special attribute name which returns the LdapSearchResult.DN field instead of a member of attr array.
Sébastien BERNARD 7 years ago
parent
commit
380aa26ea3
1 changed files with 6 additions and 1 deletions
  1. 6 1
      pkg/login/ldap.go

+ 6 - 1
pkg/login/ldap.go

@@ -404,9 +404,11 @@ func (a *ldapAuther) searchForUser(username string) (*LdapUserInfo, error) {
 		var groupSearchResult *ldap.SearchResult
 		var groupSearchResult *ldap.SearchResult
 		for _, groupSearchBase := range a.server.GroupSearchBaseDNs {
 		for _, groupSearchBase := range a.server.GroupSearchBaseDNs {
 			var filter_replace string
 			var filter_replace string
-			filter_replace = getLdapAttr(a.server.GroupSearchFilterUserAttribute, searchResult)
+
 			if a.server.GroupSearchFilterUserAttribute == "" {
 			if a.server.GroupSearchFilterUserAttribute == "" {
 				filter_replace = getLdapAttr(a.server.Attr.Username, searchResult)
 				filter_replace = getLdapAttr(a.server.Attr.Username, searchResult)
+			} else {
+				filter_replace = getLdapAttr(a.server.GroupSearchFilterUserAttribute, searchResult)
 			}
 			}
 			filter := strings.Replace(a.server.GroupSearchFilter, "%s", ldap.EscapeFilter(filter_replace), -1)
 			filter := strings.Replace(a.server.GroupSearchFilter, "%s", ldap.EscapeFilter(filter_replace), -1)
 
 
@@ -448,6 +450,9 @@ func (a *ldapAuther) searchForUser(username string) (*LdapUserInfo, error) {
 }
 }
 
 
 func getLdapAttrN(name string, result *ldap.SearchResult, n int) string {
 func getLdapAttrN(name string, result *ldap.SearchResult, n int) string {
+        if name == "DN" {
+		return result.Entries[0].DN
+	}
 	for _, attr := range result.Entries[n].Attributes {
 	for _, attr := range result.Entries[n].Attributes {
 		if attr.Name == name {
 		if attr.Name == name {
 			if len(attr.Values) > 0 {
 			if len(attr.Values) > 0 {