summaryrefslogtreecommitdiff
path: root/bin/common.rb.in
diff options
context:
space:
mode:
Diffstat (limited to 'bin/common.rb.in')
-rw-r--r--bin/common.rb.in16
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