Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

find_first and recursive lookup debugging #1

Merged
merged 3 commits into from

2 participants

@Mazwak

I wanted to do a few queries on my AD, and found some bugs.

See commit messages for changes.

Simon Arnaud added some commits
@ajrkerr ajrkerr merged commit 02e7765 into ajrkerr:master
@ajrkerr
Owner

Thank you =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 29, 2011
  1. Use only firt result of LDAP query in find_first

    Simon Arnaud authored
  2. Really return nil if search found nothing

    Simon Arnaud authored
    By default, Net::LDAP returns an empty array.
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 37 deletions.
  1. +3 −1 lib/active_directory/base.rb
  2. +14 −36 lib/active_directory/group.rb
View
4 lib/active_directory/base.rb
@@ -305,7 +305,9 @@ def self.find_all(options)
end
def self.find_first(options)
- ad_obj = new(@@ldap.search(:filter => options[:filter], :base => options[:in]))
+ ldap_result = @@ldap.search(:filter => options[:filter], :base => options[:in])
+ return nil if ldap_result.empty?
+ ad_obj = new(ldap_result[0])
@@cache[ad_obj.dn] = ad_obj unless ad_obj.instance_of? Base
return ad_obj
end
View
50 lib/active_directory/group.rb
@@ -98,26 +98,13 @@ def has_members?
# belong to this Group, or any of its subgroups, are returned.
#
def member_users(recursive = false)
- return [] unless has_members?
- if recursive
- if @member_users_r.nil?
- @member_users_r = []
- @entry.member.each do |member_dn|
- subuser = User.find_by_distinguishedName(member_dn)
- if subuser
- @member_users_r << subuser
- else
- subgroup = Group.find_by_distinguishedName(member_dn)
- if subgroup
- @member_users_r = @member_users_r.concat(subgroup.member_users(true))
- end
- end
- end
- end
- return @member_users_r
- else
- @member_users_non_r ||= User.find(:all, :distinguishedname => @entry.member).delete_if { |u| u.nil? }
- end
+ @member_users = User.find(:all, :distinguishedname => @entry.member).delete_if { |u| u.nil? }
+ if recursive then
+ self.member_groups.each do |group|
+ @member_users.concat(group.member_users(true))
+ end
+ end
+ return @member_users
end
#
@@ -130,22 +117,13 @@ def member_users(recursive = false)
# belong to this Group, or any of its subgroups, are returned.
#
def member_groups(recursive = false)
- return [] unless has_members?
- if recursive
- if @member_groups_r.nil?
- @member_groups_r = []
- @entry.member.each do |member_dn|
- subgroup = Group.find_by_distinguishedName(member_dn)
- if subgroup
- @member_groups_r << subgroup
- @member_groups_r = @member_groups_r.concat(subgroup.member_groups(true))
- end
- end
- end
- return @member_groups_r
- else
- @member_groups_non_r ||= Group.find(:all, :distinguishedname => @entry.member).delete_if { |g| g.nil? }
- end
+ @member_groups ||= Group.find(:all, :distinguishedname => @entry.member).delete_if { |g| g.nil? }
+ if recursive then
+ self.member_groups.each do |group|
+ @member_groups.concat(group.member_groups(true))
+ end
+ end
+ return @member_groups
end
#
Something went wrong with that request. Please try again.