@@ -52,9 +52,8 @@ def perform(group)
52
52
dns = member_dns ( group )
53
53
54
54
# search for base group's subgroups
55
- filter = ALL_GROUPS_FILTER
56
55
groups = dns . each_with_object ( [ ] ) do |dn , groups |
57
- groups . concat ldap . search ( base : dn , scope : Net :: LDAP :: SearchScope_BaseObject , attributes : attrs , filter : filter )
56
+ groups . concat find_groups_by_dn ( dn )
58
57
searched << dn
59
58
end
60
59
@@ -77,13 +76,14 @@ def perform(group)
77
76
78
77
# search for subgroups
79
78
subgroups = sub_dns . each_with_object ( [ ] ) do |dn , subgroups |
80
- subgroups . concat ldap . search ( base : dn , scope : Net :: LDAP :: SearchScope_BaseObject , attributes : attrs , filter : filter )
81
- searched << dn
79
+ subgroups . concat find_groups_by_dn ( dn )
80
+ searched << dn
82
81
end
83
82
83
+ # give up if there were no subgroups found
84
84
break if subgroups . empty?
85
85
86
- # track found groups
86
+ # track found subgroups
87
87
subgroups . each { |g | found [ g . dn ] = g }
88
88
89
89
# descend another level
@@ -106,6 +106,27 @@ def perform(group)
106
106
entries
107
107
end
108
108
109
+ # Internal: Search for Groups by DN.
110
+ #
111
+ # Given a Distinguished Name (DN) String value, find the Group entry
112
+ # that matches it. The DN may map to a `person` entry, but we want to
113
+ # filter those out.
114
+ #
115
+ # This will find zero or one entry most of the time, but it's not
116
+ # guaranteed so we account for the possibility of more.
117
+ #
118
+ # This method is intended to be used with `Array#concat` by the caller.
119
+ #
120
+ # Returns an Array of zero or more Net::LDAP::Entry objects.
121
+ def find_groups_by_dn ( dn )
122
+ ldap . search \
123
+ base : dn ,
124
+ scope : Net ::LDAP ::SearchScope_BaseObject ,
125
+ attributes : attrs ,
126
+ filter : ALL_GROUPS_FILTER
127
+ end
128
+ private :find_group_by_dn
129
+
109
130
# Internal: Fetch entries by UID.
110
131
#
111
132
# Returns an Array of Net::LDAP::Entry objects.
0 commit comments