[openwrt/openwrt] base-files, metadata: support additional group membership
LEDE Commits
lede-commits at lists.infradead.org
Thu Oct 28 08:29:30 PDT 2021
dangole pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/b2aca61360c33ad3161f8ef35a1c28ebb2507600
commit b2aca61360c33ad3161f8ef35a1c28ebb2507600
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Tue Oct 26 13:02:37 2021 +0100
base-files, metadata: support additional group membership
Some packages may require additional group membership for the system
user added by that package. Allow defining additional groups as third
member of the ':'-separated tuple, allowing to specify multiple
','-separated groups with optional GID.
Example:
USERID:=foouser=1000:foogroup=1000:addg1=1001,addg2=1002,addg3
Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
package/base-files/files/lib/functions.sh | 23 ++++++++++++++++++++---
scripts/metadata.pm | 8 +++++++-
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index d8604415cc..a5b23eb135 100644
--- a/package/base-files/files/lib/functions.sh
+++ b/package/base-files/files/lib/functions.sh
@@ -209,10 +209,10 @@ add_group_and_user() {
if [ -n "$rusers" ]; then
local tuple oIFS="$IFS"
for tuple in $rusers; do
- local uid gid uname gname
+ local uid gid uname gname addngroups addngroup addngname addngid
IFS=":"
- set -- $tuple; uname="$1"; gname="$2"
+ set -- $tuple; uname="$1"; gname="$2"; addngroups="$3"
IFS="="
set -- $uname; uname="$1"; uid="$2"
set -- $gname; gname="$1"; gid="$2"
@@ -232,7 +232,24 @@ add_group_and_user() {
group_add_user "$gname" "$uname"
fi
- unset uid gid uname gname
+ if [ -n "$uname" ] && [ -n "$addngroups" ]; then
+ oIFS="$IFS"
+ IFS=","
+ for addngroup in $addngroups ; do
+ IFS="="
+ set -- $addngroup; addngname="$1"; addngid="$2"
+ if [ -n "$addngid" ]; then
+ group_exists "$addngname" || group_add "$addngname" "$addngid"
+ else
+ group_add_next "$addngname"
+ fi
+
+ group_add_user "$addngname" "$uname"
+ done
+ IFS="$oIFS"
+ fi
+
+ unset uid gid uname gname addngroups addngroup addngname addngid
done
fi
}
diff --git a/scripts/metadata.pm b/scripts/metadata.pm
index f252c5309c..ee5a2945ca 100644
--- a/scripts/metadata.pm
+++ b/scripts/metadata.pm
@@ -295,13 +295,19 @@ sub parse_package_metadata($) {
my @ugspecs = split /\s+/, $1;
for my $ugspec (@ugspecs) {
- my @ugspec = split /:/, $ugspec, 2;
+ my @ugspec = split /:/, $ugspec, 3;
if ($ugspec[0]) {
parse_package_metadata_usergroup($src->{makefile}, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
}
if ($ugspec[1]) {
parse_package_metadata_usergroup($src->{makefile}, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;
}
+ if ($ugspec[2]) {
+ my @addngroups = split /,/, $ugspec[2];
+ for my $addngroup (@addngroups) {
+ parse_package_metadata_usergroup($src->{makefile}, "group", \%groupnames, \%groupids, $addngroup) or return 0;
+ }
+ }
}
};
}
More information about the lede-commits
mailing list