git: d43f0394c57e - stable/13 - cred: Make group_is_supplementary() public; New group_is_primary()

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Fri, 15 Nov 2024 13:00:45 UTC
The branch stable/13 has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=d43f0394c57e9119248039b04f063ed6b839e1cd

commit d43f0394c57e9119248039b04f063ed6b839e1cd
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2024-07-19 09:54:35 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2024-11-15 12:59:08 +0000

    cred: Make group_is_supplementary() public; New group_is_primary()
    
    Reviewed by:    mhorne
    Approved by:    markj (mentor)
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D46908
    
    (cherry picked from commit 6369544278b2e4fb5203b10dab466ff7c72c0a25)
    
    Approved by:    markj (mentor)
---
 sys/kern/kern_prot.c |  2 +-
 sys/sys/ucred.h      | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index eb4910e1591a..5fdb0a40a425 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -1285,7 +1285,7 @@ sys___setugid(struct thread *td, struct __setugid_args *uap)
 /*
  * Returns whether gid designates a supplementary group in cred.
  */
-static int
+int
 group_is_supplementary(const gid_t gid, const struct ucred *const cred)
 {
 
diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h
index 74e2d59c57ea..da0568e9648f 100644
--- a/sys/sys/ucred.h
+++ b/sys/sys/ucred.h
@@ -158,6 +158,17 @@ 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);
+
+/*
+ * Returns whether gid designates a primary group in cred.
+ */
+static inline int
+group_is_primary(const gid_t gid, const struct ucred *const cred)
+{
+	return (gid == cred->cr_groups[0] || gid == cred->cr_rgid ||
+	    gid == cred->cr_svgid);
+}
+int	group_is_supplementary(const gid_t gid, const struct ucred *const cred);
 int	groupmember(gid_t gid, const struct ucred *cred);
 int	realgroupmember(gid_t gid, const struct ucred *cred);
 #endif /* _KERNEL */