From 810cb4d7ebca78c9f46513b07f688eb652564250 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 16 Dec 2017 14:00:07 -0500 Subject: Allow groupgroups to be nested arbitrarily deep. --- bin/common.rb.in | 16 +++++++++++++--- parabola-hackers.yml | 2 +- 2 files changed, 14 insertions(+), 4 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 . +# Copyright 2016-2017 Luke Shumaker . # # 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 # . +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 diff --git a/parabola-hackers.yml b/parabola-hackers.yml index 04c5992..4dfb451 100644 --- a/parabola-hackers.yml +++ b/parabola-hackers.yml @@ -3,7 +3,7 @@ yamldir: "/var/lib/hackers-git/users" # Which groups imply membership in other groups (since UNIX groups -# can't be nested). Only one level of nesting is supported ATM. +# can't be nested). # # That is, if you are in the 'hackers' group, you are also in the # 'repo' and 'git' groups, even if they aren't listed. -- cgit v1.2.2