From 087eff3658b4468f6b0b6556adb6d8164fbd9d04 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 3 Mar 2021 11:24:42 -0700 Subject: [PATCH] Girocco/Project.pm: add get_full_list_extended function The existing get_full_list function returns the list of project names by reading the group file directly. Add a new get_full_list_extended function that does the same thing but returns an array of array refs consisting of all the individual fields rather than just the names. Tighten up the check a bit to only return items with a gid >= 10000 rather than just 5 or more digits. Add some comments explaining the return value for the functions. Signed-off-by: Kyle J. McKay --- Girocco/Project.pm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Girocco/Project.pm b/Girocco/Project.pm index 9c52c67..9a508d1 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -1781,12 +1781,27 @@ sub does_exist { return 1; } +# returns array of names only taken strictly from the group file +# only entries with non-invalid names and gid >= 10000 are returned +# a "non-invalid" name is 1 or more non-whitespace or '#' chars, NOT starting with '_' sub get_full_list { open my $fd, '<', jailed_file("/etc/group") or die "getting project list failed: $!"; - my @projects = map {/^([^:_\s#][^:\s#]*):[^:]*:\d{5,}:/ ? $1 : ()} <$fd>; + my @projects = map {/^([^:_\s#][^:\s#]*):[^:]*:[1-9]\d{4,}:/ ? $1 : ()} <$fd>; close $fd; @projects; } +# returns array of array refs containing all fields (at least 3) of each entry from group file +# only entries with non-invalid names and gid >= 10000 are returned +# a "non-invalid" name is 1 or more non-whitespace or '#' chars, NOT starting with '_' +# using +# join(':',@{}) +# will recover the _exact_ original line from the group file for that entry +sub get_full_list_extended { + open my $fd, '<', jailed_file("/etc/group") or die "getting project list failed: $!"; + my @projects = map {chomp; /^([^:_\s#][^:\s#]*):[^:]*:[1-9]\d{4,}:/ ? [split(/:/,$_,-1)] : ()} <$fd>; + close $fd; + @projects; +} 1; -- 2.11.4.GIT