git: 45198c6abca7 - stable/15 - nfsuserd.c: Fix handling where pw_name/gr_name differ from lookup name

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Mon, 21 Sep 2026 01:45:11 UTC
The branch stable/15 has been updated by rmacklem:

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

commit 45198c6abca7e61cc690120ab1732481c54cd8eb
Author:     Emanuel Helms <emanuel@nrv.cc>
AuthorDate: 2026-09-07 19:50:58 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2026-09-21 01:42:30 +0000

    nfsuserd.c: Fix handling where pw_name/gr_name differ from lookup name
    
    When an NSS backend returns a canonical pw_name or gr_name that differs from
    the lookup name supplied by the NFSv4 upcall, nfsuserd stores the successful
    mapping in the kernel cache under the canonical name instead of the requested
    name.
    
    This causes the retry lookup performed by nfsv4_strtouid() or
    nfsv4_strtogid() to miss the newly inserted cache entry, resulting in the
    default UID/GID being returned although the NSS lookup itself succeeded.
    
    PR:     296753
    
    (cherry picked from commit 1771ab245c2341033f0cee3bd098c76888cf3515)
---
 usr.sbin/nfsuserd/nfsuserd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/nfsuserd/nfsuserd.c b/usr.sbin/nfsuserd/nfsuserd.c
index 9326dd9018e0..e6e215ad2a41 100644
--- a/usr.sbin/nfsuserd/nfsuserd.c
+++ b/usr.sbin/nfsuserd/nfsuserd.c
@@ -704,7 +704,8 @@ nfsuserdsrv(struct svc_req *rqstp, SVCXPRT *transp)
 		if (pwd != NULL) {
 			nid.nid_usertimeout = defusertimeout;
 			nid.nid_uid = pwd->pw_uid;
-			nid.nid_name = pwd->pw_name;
+			/* NSS may canonicalize the name used for the lookup. */
+			nid.nid_name = info.name;
 		} else {
 			nid.nid_usertimeout = 5;
 			nid.nid_uid = defaultuid;
@@ -737,7 +738,8 @@ nfsuserdsrv(struct svc_req *rqstp, SVCXPRT *transp)
 		if (grp != NULL) {
 			nid.nid_usertimeout = defusertimeout;
 			nid.nid_gid = grp->gr_gid;
-			nid.nid_name = grp->gr_name;
+			/* NSS may canonicalize the name used for the lookup. */
+			nid.nid_name = info.name;
 		} else {
 			nid.nid_usertimeout = 5;
 			nid.nid_gid = defaultgid;