Skip to content

Commit

Permalink
Prevent infinite recurse when 2 groups are members of each other. Tri…
Browse files Browse the repository at this point in the history
…es to solve issue already reported:

theforeman#51

Fix _walk_group_ancestry method declaration with extra variable
Refer unused variable with _
Lineup equals signs
  • Loading branch information
c-silva authored and carlos committed Jun 7, 2016
1 parent 59f24a6 commit 4c08a1c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/ldap_fluff/ad_member_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,28 @@ def find_user_groups(uid)
def _groups_from_ldap_data(payload)
data = []
if !payload.nil?
first_level = payload[:memberof]
total_groups = _walk_group_ancestry(first_level)
data = (get_groups(first_level + total_groups)).uniq
first_level = payload[:memberof]
total_groups, _ = _walk_group_ancestry(first_level, first_level)
data = (get_groups(first_level + total_groups)).uniq
end
data
end

# recursively loop over the parent list
def _walk_group_ancestry(group_dns = [])
def _walk_group_ancestry(group_dns = [], known_groups = [])
set = []
group_dns.each do |group_dn|
search = @ldap.search(:base => group_dn, :scope => Net::LDAP::SearchScope_BaseObject, :attributes => ['memberof'])
if !search.nil? && !search.first.nil?
group = search.first
set += _walk_group_ancestry(group[:memberof])
set += group[:memberof]
groups = search.first[:memberof] - known_groups
known_groups += groups
next_level, new_known_groups = _walk_group_ancestry(groups, known_groups)
set += next_level
set += groups
known_groups += next_level
end
end
set
return [set, known_groups]
end

def class_filter
Expand Down

0 comments on commit 4c08a1c

Please sign in to comment.