218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/inspec/resources/groups.rb', line 218
def groups
group_by_id = runmap("dscl . -list /Groups PrimaryGroupID") { |l| name, id = l.split; [id.to_i, name] }
= runmap("dscl . -list /Users PrimaryGroupID") { |l| name, id = l.split; [name, id.to_i] }
membership = runmap("dscl . -list /Groups GroupMembership") { |l| key, *vs = l.split; [key, vs] }
membership.default_proc = ->(h, k) { h[k] = [] }
users_by_group = hashmap(.keys.group_by { |k| [k] }) { |k, vs| [group_by_id[k], vs] }
users_by_group.each do |name, users|
membership[name].concat users
end
group_info = inspec.command("dscacheutil -q group").stdout.split("\n\n").uniq
regex = /^([^:]*?)\s*:\s(.*?)\s*$/
groups = group_info.map do |data|
inspec.parse_config(data, assignment_regex: regex).params
end
groups.each { |g| g["gid"] = g["gid"].to_i }
groups.each do |g|
users = g.delete("users") || ""
users = users.split
users += Array(users_by_group[g["name"]])
g["members"] = users.sort
end
groups .group_by { |g| g["gid"] }
.values
.map { |subgroups|
g = subgroups.first
if subgroups.size != 1
g["members"] = subgroups.map { |h| h["members"] }.flatten.uniq
end
g
}
end
|