From nobody Wed Oct 18 18:03:56 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4S9dyN2q93z4xKkG; Wed, 18 Oct 2023 18:03:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S9dyN2KlHz4Y1M; Wed, 18 Oct 2023 18:03:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697652236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y3RgR83c265FGGrmXnHEZADkYK59WfmeyAw35w5+TRU=; b=vA3S4eeqMl4nRxHmLXadSPv58tuDc2UuxAQAgrV7c03YKvGgiu8MF3y9s9L+I0d3/YUVM4 Tv+VLasR39CRDh6N/vA3BTErMHaoxMfcqXlqyk+cDFONWVvM0ZI3z/z7OW889qUTnliU4W NRRBmC2JaeSshKOa1CjbqIsZ5h3/wul0vhMu6scnjJeNphrbwl3Nm7zfq6EJP4qs+LW2Ip 8SOLMQty5kGSDRVGBip3bQ84NezJSxtYy8wXQ4yNRac+0yzDJvBXEVy2HuE0a5TCD4Jcho qypBraF+j+H1vgMkzpjUbZ5sxVdv7CjUwEj89UcX3keree7xZxys9k9kFlzWSQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697652236; a=rsa-sha256; cv=none; b=g/+pd3bFrvWmG1BALj6dRFfYRhPpXp43tYpSvRFogGlfWRFAavT180E1+7F4Epcj026BQc sKHfbSvykBLZkzM1YiYaLGvh3EvwzOTEskgKU9THps7MW28qdrIKzIkWRZqJwNJjn09LTT GukGWXFTswMu/M6cRuxEHIv23GQjitTeSKQoaMnhIoK36+ZCgmfPhvNzOlU9bcKqT08Mg/ /YTJEhFuxqJp8b804u3ZTf60CE7RYmbKEwiJds2CFd2e8m3T3hSoQgTBU3qC4CaSnQT+k+ stNSOA4iaobeYEjKTaedFMufYJcWEzDFoylUhEp4Oq2Ft4W3KA1YyDdV7/U/nA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697652236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y3RgR83c265FGGrmXnHEZADkYK59WfmeyAw35w5+TRU=; b=u17aSqaxNndNT33UJiKICdEuCb7Wlwxx3m78ENiJMK5W2QsrhrbjS2WxixmwH+oNpezCnZ NEhv+8oq9WQO0C/nUXsBsMQk6w16vHN2oTYAPT30twixVOlxvSedM5OPQTYaafryZ6dmQX 8QW7b8qIde4PykOZnooZdUifpcrDKz1t6bMX3CkBYDsdpgBA6prj/Xin84CryxaycVWifF M0rjsZBxjxL6/1iIE5cCT3Aeum1jsH0df1LwVjtXtMzM72S3ygBF1YgwPUnW3jEM4yQFn5 g80H7QfAEretWH0YKjw2+KOoG15K0hhA4MPjbSxKD5VWx/On2Fwzs8fDKEo4hA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4S9dyN1JSLz24p; Wed, 18 Oct 2023 18:03:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39II3uiH044959; Wed, 18 Oct 2023 18:03:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39II3uSv044956; Wed, 18 Oct 2023 18:03:56 GMT (envelope-from git) Date: Wed, 18 Oct 2023 18:03:56 GMT Message-Id: <202310181803.39II3uSv044956@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 4750f117a060 - releng/14.0 - New realgroupmember() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 4750f117a060c835c327aebf8e76ba6abeef16e5 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=4750f117a060c835c327aebf8e76ba6abeef16e5 commit 4750f117a060c835c327aebf8e76ba6abeef16e5 Author: Olivier Certner AuthorDate: 2023-08-17 23:54:45 +0000 Commit: Mitchell Horne CommitDate: 2023-10-18 18:01:44 +0000 New realgroupmember() Like groupmember(), but taking into account the real group instead of the effective group. Leverages the new supplementary_group_member() function. Approved by: re (gjb) Reviewed by: mhorne Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40641 Differential Revision: https://reviews.freebsd.org/D40643 (cherry picked from commit 2a2bfa6ad92e9c82dcc55733ad2fd58fd2ea7559) (cherry picked from commit 5d9f38405a10fdcd9fc108c940dcf2642e9f1833) (cherry picked from commit cbe88592ab88c3940bedc3b2a651eb4556f4bbd8) --- share/man/man9/Makefile | 1 + share/man/man9/groupmember.9 | 7 +++++++ sys/kern/kern_prot.c | 13 +++++++++++++ sys/sys/ucred.h | 1 + 4 files changed, 22 insertions(+) diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index c3c81719b7d2..2122f8d6ea8c 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1157,6 +1157,7 @@ MLINKS+=g_provider.9 g_destroy_provider.9 \ g_provider.9 g_error_provider.9 \ g_provider.9 g_new_providerf.9 MLINKS+=gone_in.9 gone_in_dev.9 +MLINKS+=groupmember.9 realgroupmember.9 MLINKS+=hash.9 hash32.9 \ hash.9 hash32_buf.9 \ hash.9 hash32_str.9 \ diff --git a/share/man/man9/groupmember.9 b/share/man/man9/groupmember.9 index 3a516622efce..ae7ccd477955 100644 --- a/share/man/man9/groupmember.9 +++ b/share/man/man9/groupmember.9 @@ -36,6 +36,8 @@ .In sys/ucred.h .Ft int .Fn groupmember "gid_t gid" "struct ucred *cred" +.Ft int +.Fn realgroupmember "gid_t gid" "struct ucred *cred" .Sh DESCRIPTION The .Fn groupmember @@ -49,6 +51,11 @@ Considered groups in .Fa cred are the effective and supplementary groups. The real group is not taken into account. +.Pp +Function +.Fn realgroupmember +works the same except that it considers instead the real and supplementary +groups, and not the effective one. .Sh RETURN VALUES If the .Fa gid diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 21f5e5d3bc16..23bd2009582b 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1312,6 +1312,19 @@ groupmember(gid_t gid, struct ucred *cred) return (supplementary_group_member(gid, cred)); } +/* + * Check if gid is a member of the real group set (i.e., real and supplementary + * groups). + */ +int +realgroupmember(gid_t gid, struct ucred *cred) +{ + if (gid == cred->cr_rgid) + return (1); + + return (supplementary_group_member(gid, cred)); +} + /* * Test the active securelevel against a given level. securelevel_gt() * implements (securelevel > level). securelevel_ge() implements diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h index eb92776c158a..633bf436fcd4 100644 --- a/sys/sys/ucred.h +++ b/sys/sys/ucred.h @@ -159,6 +159,7 @@ void cru2x(struct ucred *cr, struct xucred *xcr); void cru2xt(struct thread *td, struct xucred *xcr); void crsetgroups(struct ucred *cr, int n, gid_t *groups); int groupmember(gid_t gid, struct ucred *cred); +int realgroupmember(gid_t gid, struct ucred *cred); #endif /* _KERNEL */ #endif /* !_SYS_UCRED_H_ */