git: 007d864f061d - releng/14.0 - groupmember(), realgroupmember(): Return a bool instead of an int
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 18 Oct 2023 18:03:58 UTC
The branch releng/14.0 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=007d864f061deef350f337ad835050526c68d4a7 commit 007d864f061deef350f337ad835050526c68d4a7 Author: Olivier Certner <olce.freebsd@certner.fr> AuthorDate: 2023-08-17 23:54:47 +0000 Commit: Mitchell Horne <mhorne@FreeBSD.org> 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_ */