diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-12-16 14:00:07 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-12-16 14:00:07 -0500 |
commit | 810cb4d7ebca78c9f46513b07f688eb652564250 (patch) | |
tree | 8b3316064120b7a2c3ae3d2255d67dd5c23e8fe1 /bin | |
parent | 07d8af2fe0f87b99631de230745fd09702bb9d3d (diff) |
Allow groupgroups to be nested arbitrarily deep.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/common.rb.in | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/bin/common.rb.in b/bin/common.rb.in index 7c457b8..3f5c557 100644 --- a/bin/common.rb.in +++ b/bin/common.rb.in @@ -1,4 +1,4 @@ -# Copyright 2016 Luke Shumaker <lukeshu@sbcglobal.net>. +# Copyright 2016-2017 Luke Shumaker <lukeshu@sbcglobal.net>. # # This is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -14,6 +14,7 @@ # License along with this manual; if not, see # <http://www.gnu.org/licenses/>. +require 'set' require 'yaml' def cfg @@ -26,10 +27,19 @@ def cfg return @cfg end +def add_group(group_set, groupname) + return if group_set.include?(groupname) + group_set.add(groupname) + (cfg["groupgroups"][groupname] || []).each do |subgroupname| + add_group(group_set, subgroupname) + end +end + def load_user_yaml(filename) user = YAML::load(open(filename)) - groups = user["groups"] || [] - user["groups"] = groups.concat((groups & cfg["groupgroups"].keys).map{|g|cfg["groupgroups"][g]}.flatten) + groups = Set.new + (user["groups"] || []).each{|groupname| add_group(groups, groupname)} + user["groups"] = groups return user end |