From patchwork Tue Oct 26 16:43:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 1546522 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1oZnp0ja; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HdyRP6xdkz9sX3 for ; Wed, 27 Oct 2021 03:47:28 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=TFvec2Aw/Oo3+URnPBZPEFMrnmQG2qCLEyO+k/HRV0s=; b=1oZnp0jaZZOX8+ LtkDx5L4o7+yGXXj737gm7+hjS/l4H5R8vopNkrM8wIwhwR10eyKAmMPWmgU1EmbGNDCOQVaZ7bEO IZhoKzJwiSYWuHciHosjGnrziYsM4kEf6SvO+QIbfQ8b1SHlKddpQl3Wkrod8eXJck9RFi3cfRlSI L+oyHHLi1YoxxWp5pZigFPw1WpPV0LEowqu2OhF6a9JoMHDUFsGJih5MWM55qOjzCPvJIwC5t49V/ Qz+tPe2aEQfsQk36jrM89WLnGvsvqLDbm9d4ZRjC+OSLXiA8avigtjPusqWk/BGpq91QYTLgEFG3H sq0IfrUkKgntgwLhurLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfPYe-002W23-NO; Tue, 26 Oct 2021 16:44:16 +0000 Received: from fudo.makrotopia.org ([2a07:2ec0:3002::71]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfPYa-002W0x-1W for openwrt-devel@lists.openwrt.org; Tue, 26 Oct 2021 16:44:14 +0000 Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1mfPYV-0008B4-1g; Tue, 26 Oct 2021 18:44:07 +0200 Date: Tue, 26 Oct 2021 17:43:52 +0100 From: Daniel Golle To: openwrt-devel@lists.openwrt.org Cc: John Crispin Subject: [PATCH] base-files, metadata: support additional group membership Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211026_094412_106013_7B9756AA X-CRM114-Status: GOOD ( 11.55 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 multip [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 --- 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; + } + } } }; }