Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent infinite recurse when 2 groups are members of each other #53

Merged
merged 2 commits into from
Jun 20, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, return is optional here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok!

end

def class_filter
Expand Down