@@ -7,26 +7,43 @@ class Ldap
7
7
class ForestSearch
8
8
include Instrumentation
9
9
10
+ # Build a new GitHub::Ldap::ForestSearch instance
11
+ #
12
+ # connection: GitHub::Ldap object representing the main AD connection.
13
+ # naming_context: The Distinguished Name (DN) of this forest's Configuration
14
+ # Naming Context, e.g., "CN=Configuration,DC=ad,DC=ghe,DC=com"
15
+ #
16
+ # See: https://technet.microsoft.com/en-us/library/aa998375(v=exchg.65).aspx
17
+ #
10
18
def initialize ( connection , naming_context )
11
19
@naming_context = naming_context
12
20
@connection = connection
13
- @forest = get_domain_forest
14
21
end
15
22
23
+ # Search over all domain controllers in the ActiveDirectory forest.
24
+ #
25
+ # options: options hash passed in from GitHub::Ldap#search
26
+ # &block: optional block passed in from GitHub::Ldap#search
27
+ #
28
+ # If no domain controllers are found in the forest, fall back on searching
29
+ # the main GitHub::Ldap object in @connection.
30
+ #
31
+ # If @forest is populated, iterate over each domain controller and perform
32
+ # the requested search, excluding domain controllers whose naming context
33
+ # is not in scope for the search base DN defined in options[:base].
34
+ #
16
35
def search ( options , &block )
17
- instrument "forest_search.github_ldap" do |payload |
18
- result =
19
- if @forest . empty?
20
- @connection . search ( options , &block )
21
- else
22
- @forest . each_with_object ( [ ] ) do |( rootdn , server ) , res |
23
- if options [ :base ] . end_with? ( rootdn )
24
- rs = server . search ( options , &block )
25
- res . concat Array ( rs ) unless rs == false
26
- end
36
+ instrument "forest_search.github_ldap" do
37
+ if forest . empty?
38
+ @connection . search ( options , &block )
39
+ else
40
+ forest . each_with_object ( [ ] ) do |( ncname , connection ) , res |
41
+ if options [ :base ] . end_with? ( ncname )
42
+ rs = connection . search ( options , &block )
43
+ res . concat Array ( rs ) unless rs == false
27
44
end
28
45
end
29
- return result
46
+ end
30
47
end
31
48
end
32
49
0 commit comments