@@ -53,30 +53,44 @@ def search(options, &block)
53
53
54
54
# Internal: Queries configuration for available domains
55
55
#
56
- # Membership of local or global groups need to be evaluated by contacting referral Donmain Controllers
56
+ # Membership of local or global groups need to be evaluated by contacting referral
57
+ # Domain Controllers
57
58
#
58
- # Returns all Domain Controllers within the forest
59
- def get_domain_forest
60
- instrument "get_domain_forest.github_ldap" do |payload |
61
- domains = @connection . search (
62
- base : naming_context ,
63
- search_referrals : true ,
64
- filter : Net ::LDAP ::Filter . eq ( "nETBIOSName" , "*" )
65
- )
66
- unless domains . nil?
67
- return domains . each_with_object ( { } ) do |server , result |
68
- if server [ :ncname ] . any? and server [ :dnsroot ] . any?
69
- result [ server [ :ncname ] . first ] = Net ::LDAP . new ( {
70
- host : server [ :dnsroot ] . first ,
71
- port : @connection . instance_variable_get ( :@encryption ) ? 636 : 389 ,
72
- auth : @connection . instance_variable_get ( :@auth ) ,
73
- encryption : @connection . instance_variable_get ( :@encryption ) ,
74
- instrumentation_service : @connection . instance_variable_get ( :@instrumentation_service )
75
- } )
59
+ # returns: A memoized Hash of Domain Controllers from this AD forest in the format:
60
+ #
61
+ # {<nCNname> => <connection>}
62
+ #
63
+ # where "nCName" specifies the distinguished name of the naming context for the domain
64
+ # controller, and "connection" is an instance of Net::LDAP that represents a connection
65
+ # to that domain controller, for instance:
66
+ #
67
+ # {"DC=ad,DC=ghe,DC=local" => <Net::LDAP:0x007f9c3e20b200>,
68
+ # "DC=fu,DC=bar,DC=local" => <Net::LDAP:0x007f9c3e20b890>}
69
+ #
70
+ def forest
71
+ @forest ||= begin
72
+ instrument "get_domain_forest.github_ldap" do
73
+ domains = @connection . search (
74
+ base : naming_context ,
75
+ search_referrals : true ,
76
+ filter : Net ::LDAP ::Filter . eq ( "nETBIOSName" , "*" )
77
+ )
78
+ if domains
79
+ domains . each_with_object ( { } ) do |server , result |
80
+ if server [ :ncname ] . any? && server [ :dnsroot ] . any?
81
+ result [ server [ :ncname ] . first ] = Net ::LDAP . new ( {
82
+ host : server [ :dnsroot ] . first ,
83
+ port : @connection . instance_variable_get ( :@encryption ) ? 636 : 389 ,
84
+ auth : @connection . instance_variable_get ( :@auth ) ,
85
+ encryption : @connection . instance_variable_get ( :@encryption ) ,
86
+ instrumentation_service : @connection . instance_variable_get ( :@instrumentation_service )
87
+ } )
88
+ end
76
89
end
90
+ else
91
+ { }
77
92
end
78
93
end
79
- return { }
80
94
end
81
95
end
82
96
0 commit comments