From nobody Wed Oct 18 18:03:58 2023 X-Original-To: dev-commits-src-all@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 4S9dyQ57n5z4xL3X; Wed, 18 Oct 2023 18:03:58 +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 4S9dyQ4ZNYz4Xr4; Wed, 18 Oct 2023 18:03:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697652238; 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=xCSh6wqlJHqgmMU81Lkn8l57ruQhzY3DdRqm4b+17SA=; b=q8mb+sYn8OH1w/XWx0gddSLyU+HATR+PKmkMEx4tONsgbznbp5W8hbzxVbbOARz27+wC/p W9rynX4GKQ805UZZBaW8Mlewibv/PVVxBij5fX+L4rfUanAUxHhIgZXf7V46Sn4RdvFjsY PxALZ3V2WZQaeCZcqvm79z/Xakel16WpKaynPJRC6JnVmWJhvzqH+Fu6ZPf0Rxly2ZehlT 7Qt7EZeXqZzfeHGrIF8YeuMXZvgx5vKjtpxKAQUcENj08GyD2ObPQQW4EeLfx1a4iOR+ly 64zjozfmDfYVYT3t+G+TZxsMhiOMX6Sh8MJgYXkQZ2Q9opb21/WkHSIfUmfvIQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697652238; a=rsa-sha256; cv=none; b=Nu5UidYSywY25cF5IvAw3pb+EYUXtv3uN6ndHjlJ1dvE5bgfblnoHGty9k1hn/9yaEKyb4 pvKargu+iEzP74VziGwpfROZDlroD2REV6B8VNqaBlVExSMUEu6at8Debc56xGDRIRgwHs 5eLKBP+K7mJjx75Ruovu7nkZMs4cBHO5dMZukc/uXTIesxFgwtQpN+vV0Wr/AVvcNyC9S5 OE7nv46wQ8leZ9xIp0TtIZOTVcOoKctrCnApeOjuLErGoIBpDsUGKqTKbp3UVc8lxUmGMS lNZUZmlHJQFpwwhDb3cbfViXZodsENaSWwI2kONLuZo5Y/i8Vu8ZQ6t1FZyH5g== 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=1697652238; 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=xCSh6wqlJHqgmMU81Lkn8l57ruQhzY3DdRqm4b+17SA=; b=iiiFDv6ExaEdcup6jkT0gv7eSAQ7//DJLF4ji+O/G34/ra9ikMGi4O/l24b+SlJpExkn4S EYeBzGGM7dIkIwy+dY4BV6/hOjCQ5Ne/vQdLAyGP7v/fWVixYBD1EsJDZ38N8D7a8vWOJV LfbnioxBqKedSeUyo80XivXWZ1Dhl27FIjbem1FKC5QckFiiY+bCvi6QM45hB4onQW0xbt QwrkgijtqhOPDeYBwhWUdiB73qOJaykcTt0Ok7CtTsvdzya1VX2s6xK4u00MGKbkVeCTgS TZroVbWl4uqLdnsgHgGQzeZD9qK+ZIf9Aaop1C1p59GPVlY4zyKGGlHDHYj+Mg== 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 4S9dyQ3gdcz1qX; Wed, 18 Oct 2023 18:03:58 +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 39II3wNF045066; Wed, 18 Oct 2023 18:03:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39II3wjE045063; Wed, 18 Oct 2023 18:03:58 GMT (envelope-from git) Date: Wed, 18 Oct 2023 18:03:58 GMT Message-Id: <202310181803.39II3wjE045063@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: 007d864f061d - releng/14.0 - groupmember(), realgroupmember(): Return a bool instead of an int List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 007d864f061deef350f337ad835050526c68d4a7 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=007d864f061deef350f337ad835050526c68d4a7 commit 007d864f061deef350f337ad835050526c68d4a7 Author: Olivier Certner AuthorDate: 2023-08-17 23:54:47 +0000 Commit: Mitchell Horne CommitDate: 2023-10-18 18:01:57 +0000 groupmember(), realgroupmember(): Return a bool instead of an int Approved by: re (gjb) Requested by: mhorne Reviewed by: mhorne Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40958 Differential Revision: https://reviews.freebsd.org/D40959 (cherry picked from commit ffd3ef8ee0253ffaf214cf711251d112f6a2bcf6) (cherry picked from commit 845b7c80887ac84c82ee776836ef86d68ea71c94) (cherry picked from commit 8cfce55f8f949869378c06279e4409beeddbea4e) --- share/man/man9/groupmember.9 | 18 +++++++++++++----- sys/kern/kern_prot.c | 12 ++++++------ sys/sys/ucred.h | 4 ++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/share/man/man9/groupmember.9 b/share/man/man9/groupmember.9 index ae7ccd477955..b7865a35fdc9 100644 --- a/share/man/man9/groupmember.9 +++ b/share/man/man9/groupmember.9 @@ -34,9 +34,9 @@ .Sh SYNOPSIS .In sys/param.h .In sys/ucred.h -.Ft int +.Ft bool .Fn groupmember "gid_t gid" "struct ucred *cred" -.Ft int +.Ft bool .Fn realgroupmember "gid_t gid" "struct ucred *cred" .Sh DESCRIPTION The @@ -57,9 +57,17 @@ Function 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 -is found, 1 is returned, otherwise 0. +The +.Fn groupmember +and +.Fn realgroupmember +functions return +.Dv true +if the given credentials indicate membership of the group +.Fa gid , +or +.Dv false +otherwise. .Sh SEE ALSO .Xr getgroups 2 .Xr setgroups 2 diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 43fc3100bfa7..14b19837d5dc 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1275,7 +1275,7 @@ sys___setugid(struct thread *td, struct __setugid_args *uap) /* * Returns whether gid designates a supplementary group in cred. */ -static int +static bool supplementary_group_member(gid_t gid, struct ucred *cred) { int l, h, m; @@ -1302,12 +1302,12 @@ supplementary_group_member(gid_t gid, struct ucred *cred) * Check if gid is a member of the (effective) group set (i.e., effective and * supplementary groups). */ -int +bool groupmember(gid_t gid, struct ucred *cred) { - if (cred->cr_groups[0] == gid) - return (1); + if (gid == cred->cr_groups[0]) + return (true); return (supplementary_group_member(gid, cred)); } @@ -1316,11 +1316,11 @@ groupmember(gid_t gid, struct ucred *cred) * Check if gid is a member of the real group set (i.e., real and supplementary * groups). */ -int +bool realgroupmember(gid_t gid, struct ucred *cred) { if (gid == cred->cr_rgid) - return (1); + return (true); return (supplementary_group_member(gid, cred)); } diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h index 633bf436fcd4..7c9e46e47774 100644 --- a/sys/sys/ucred.h +++ b/sys/sys/ucred.h @@ -158,8 +158,8 @@ void crcowfree(struct thread *td); 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); +bool groupmember(gid_t gid, struct ucred *cred); +bool realgroupmember(gid_t gid, struct ucred *cred); #endif /* _KERNEL */ #endif /* !_SYS_UCRED_H_ */