Skip to content

Active Directory range retrieval returns duplicates? #208

Open
@christopher-b

Description

@christopher-b

I'm using range retrieval on an AD server to load the members of a group containing around 5600 members. The resulting list of members contains duplicated entries, and is missing some entries that are members of the group. The number of duplicates is not consistent across runs.

Something strange is there are no new duplicates after around record 3670. Regardless of page size, all duplicates occur between the second page and whatever page loads a range containing a record around 3670. No new duplicates are found after that point.

This only happens on my production machine, not on my workstation. Both are running the same version of Ruby and the same version of this gem (0.11). So my hunch is that it might be a network issue, but I'm not sure what that might be or where to look.

Has anyone ever encountered anything like this? It's a bit baffling. If I can't figure out the cause of this error, I should be able to work around it by loading entries with memberOf=group_name, but I'd like to figure this out. Thanks in advance for any insight.

Here's the code I'm using to load the group membership, and the resulting output.

def load_members
  range_regex    = /member;range=\d+-(\d+|\*)/ # member;range=0-1499, member;range=1500-*
  remote_members = []
  start          = 0
  match          = nil
  loop do
    entry = search("member;range=#{start}-*").first
    range = entry.attribute_names.map(&:to_s).find { |attr| match = attr.match range_regex }
    break unless range
    puts "Found range: #{range}"
    remote_members.concat entry[range]
    puts "Added #{entry[range].size}"
    puts "Duplicates: #{remote_members.size-remote_members.uniq.size}"
    stop = match[1]
    break if stop == '*' # Halt if we're at the end of the records: member;range=1500-*
    start = stop.to_i + 1
  end
  remote_members
end

def search(attributes)
  puts "Searching for: #{attributes} "
  @ldap.search(
    base:       ou,
    filter:     Net::LDAP::Filter.eq('sAMAccountName', name),
    attributes: attributes
  )
end
Searching for: member;range=0-*
Found range: member;range=0-1499
Added 1500
Duplicates: 0
Searching for: member;range=1500-*
Found range: member;range=1500-2999
Added 1500
Duplicates: 53
Searching for: member;range=3000-*
Found range: member;range=3000-4499
Added 1500
Duplicates: 425
Searching for: member;range=4500-*
Found range: member;range=4500-*
Added 1170
Duplicates: 425
Members: 5670
Unique: 5245

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions