git: f2d2318fafbb - main - mountd(8): parsecred(): Remove "duplicate compression"

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Mon, 16 Dec 2024 14:45:23 UTC
The branch main has been updated by olce:

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

commit f2d2318fafbb16c8a7773fe20c724c986f424fa2
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2024-09-26 17:00:26 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2024-12-16 14:42:29 +0000

    mountd(8): parsecred(): Remove "duplicate compression"
    
    No functional change (intended).
    
    This code dates back to 4.4BSD, became wrong after some getgrouplist()
    (nssswitch-related) change in 2007, was fixed only in 2020 and since
    then underwent cosmetic changes.
    
    It is likely that in fact it never served any useful purpose in FreeBSD,
    except perhaps at the very beginning.  It's most probably not the case
    today: NFS credentials are normally only used to check for file
    accesses, whose group is checked against all groups of a credentials
    indiscriminately (except for the real GID).  Consequently, having
    a single duplicate, which the code would actually remove only if in the
    first supplementary group slot, doesn't change behavior.  Moreover, we
    are going to regain one slot in a subsequent commit.
    
    Discussed with: rmacklem
    Approved by:    markj (mentor)
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D46920
---
 usr.sbin/mountd/mountd.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c
index c903431c2ecf..22ed57d8669d 100644
--- a/usr.sbin/mountd/mountd.c
+++ b/usr.sbin/mountd/mountd.c
@@ -3610,7 +3610,6 @@ static void
 parsecred(char *namelist, struct expcred *cr)
 {
 	char *name;
-	int inpos;
 	char *names;
 	struct passwd *pw;
 	struct group *gr;
@@ -3652,23 +3651,12 @@ parsecred(char *namelist, struct expcred *cr)
 			ngroups = NGROUPS_MAX + 1;
 		}
 
-		/*
-		 * Compress out duplicate.
-		 */
-		if (ngroups > 1 && groups[0] == groups[1]) {
-			ngroups--;
-			inpos = 2;
-		} else {
-			inpos = 1;
-		}
 		if (ngroups > NGROUPS_MAX)
 			ngroups = NGROUPS_MAX;
 		if (ngroups > SMALLNGROUPS)
 			cr->cr_groups = malloc(ngroups * sizeof(gid_t));
 		cr->cr_ngroups = ngroups;
-		cr->cr_groups[0] = groups[0];
-		memcpy(&cr->cr_groups[1], &groups[inpos], (ngroups - 1) *
-		    sizeof(gid_t));
+		memcpy(cr->cr_groups, groups, ngroups * sizeof(gid_t));
 		return;
 	}
 	/*