From nobody Thu Jan 16 18:08:27 2025 X-Original-To: dev-commits-src-branches@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 4YYrT85PMRz5kksZ; Thu, 16 Jan 2025 18:08:28 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YYrT74xjrz3RvQ; Thu, 16 Jan 2025 18:08:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737050907; 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=mw+Xu11BMN7mvcoZoW/aTy56lhTZQnrFwAh2wFg4P+M=; b=uz8uPFGA6QdpwlshfvqatsxcQCiJkhvol7FJLjhI56ON6a2K5Oi5C3C9mTYXucsUHh3/HE MU3uosCjFkMfCPZQY7ceACxSD0P9xNIj/XgXJiLD0ZqfU8T/bWtoluyMPwtTDRMnDDtByt U+eVhCXtp0DXco7isd4yby5QYvIlXm1uIx0c3qmRs1bR2DJfvGbhUdoKj3uBUdxmHIzTMH YJjKNG967rCWvE0UMr9W2yukvZPJMLmgtCdGOO96pVIeyOFF0X0SLOMFoZRBzYqHgl175S SJ1gAKS3+v8j0mPGbCG9v8koH9KnH9wNqyBU7CUWMYAREoSBHoqdEcKg1QlrJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737050907; 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=mw+Xu11BMN7mvcoZoW/aTy56lhTZQnrFwAh2wFg4P+M=; b=jBpvg9qZ+qzRw34+x8G2X1twxYdEv0TueNiXhrpUmSd5Gx9lLGOlBupG5yoG8wjONTBPgD 8IO091vx82Oxy53+R2jYfc036bE0lJV0ahVA5zoIaUxGO/88ddmgqrPk3/4gRnWwwg6YW9 F4rx45UqtuVnuLxgLYO+X6Tb1mwspr6NHOvLMqcouUJhNGjjy4rtQXpMu2t+E3BqFhbntP wttxx53/hNrQOFiN5sY97Z3uM1AbYNInvjCrS8TfrcSobgRkuBEe6o5XPwy6RSWicmk1jf tQgo6XyrgdY2XFADW9lD1tUxzudFkhLQrF+V2DUdltLwShoGTaGRKHpz3IPGcA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737050907; a=rsa-sha256; cv=none; b=ZEUTfMw028Sxy+JmU2z6bNDw6vYR5Q7WR2EGbtfisRgASmIdwYtjgeBiy+hqBqgWkLuCqK Iw5Ii/zGyBRCKcPP/MsHM1rjM8AGwriYRhZjboOcgklV+OFazcYXOjV3fRjM+YLBspBxmv dYoayDOPao+iXnXdoY2Vfiy5digI90iWeLoRLtix1mUdVMvbQKrgWVZWYcSUWF6fECWEbA kZz0wGchRj6lJZKaqmhtGshuDDHDm+LahqWBGZK0jMziywB3fbA6oRF67duto/f62mbM+M ytVgSsYoY2SkQ5Ei3BlUIMBDZcPdn7I+5izeENGehKOmTvk5CK6UwsWqx8hwRA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YYrT74MNFzk14; Thu, 16 Jan 2025 18:08:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50GI8RQx092383; Thu, 16 Jan 2025 18:08:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50GI8RuY092380; Thu, 16 Jan 2025 18:08:27 GMT (envelope-from git) Date: Thu, 16 Jan 2025 18:08:27 GMT Message-Id: <202501161808.50GI8RuY092380@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 8caa6bc96c8c - stable/14 - mountd(8): parsecred(): Re-order operations for clarity List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 8caa6bc96c8c51353b5ce2feb66bf563ea27d469 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=8caa6bc96c8c51353b5ce2feb66bf563ea27d469 commit 8caa6bc96c8c51353b5ce2feb66bf563ea27d469 Author: Olivier Certner AuthorDate: 2024-10-08 10:06:55 +0000 Commit: Olivier Certner CommitDate: 2025-01-16 18:06:59 +0000 mountd(8): parsecred(): Re-order operations for clarity No functional change (intended). Reviewed by: rmacklem (older version) Approved by: markj (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47015 (cherry picked from commit a20d50245f280be404cb8e3b5c9d570ded9594b9) --- usr.sbin/mountd/mountd.c | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c index efc6e0ef6730..5c8c6aad63ec 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -3616,21 +3616,14 @@ parsecred(char *namelist, struct expcred *cr) char *name; char *names; struct passwd *pw; - struct group *gr; gid_t groups[NGROUPS_MAX + 1]; int ngroups; unsigned long name_ul; char *end = NULL; /* - * Set up the unprivileged user. - */ - cr->cr_groups = cr->cr_smallgrps; - cr->cr_uid = UID_NOBODY; - cr->cr_groups[0] = nogroup(); - cr->cr_ngroups = 1; - /* - * Get the user's password table entry. + * Parse the user and if possible get its password table entry. + * 'cr_uid' is filled when exiting this block. */ names = namelist; name = strsep_quote(&names, ":"); @@ -3639,13 +3632,25 @@ parsecred(char *namelist, struct expcred *cr) pw = getpwnam(name); else pw = getpwuid((uid_t)name_ul); + if (pw != NULL) { + cr->cr_uid = pw->pw_uid; + } else if (*end != '\0' || end == name) { + syslog(LOG_ERR, "unknown user: %s", name); + cr->cr_uid = UID_NOBODY; + goto nogroup; + } else { + cr->cr_uid = name_ul; + } + /* - * Credentials specified as those of a user. + * Credentials specified as those of a user (i.e., use its associated + * groups as specified in the password database). */ if (names == NULL) { if (pw == NULL) { - syslog(LOG_ERR, "unknown user: %s", name); - return; + syslog(LOG_ERR, "no passwd entry for user: %s, " + "can't determine groups", name); + goto nogroup; } cr->cr_uid = pw->pw_uid; ngroups = NGROUPS_MAX + 1; @@ -3660,20 +3665,14 @@ parsecred(char *namelist, struct expcred *cr) memcpy(cr->cr_groups, groups, ngroups * sizeof(gid_t)); return; } + /* - * Explicit credential specified as a colon separated list: + * Explicit credentials specified as a colon separated list: * uid:gid:gid:... */ - if (pw != NULL) { - cr->cr_uid = pw->pw_uid; - } else if (*end != '\0' || end == name) { - syslog(LOG_ERR, "unknown user: %s", name); - return; - } else { - cr->cr_uid = name_ul; - } cr->cr_ngroups = 0; while (names != NULL && *names != '\0') { + const struct group *gr; gid_t group; name = strsep_quote(&names, ":"); @@ -3693,14 +3692,16 @@ parsecred(char *namelist, struct expcred *cr) } groups[cr->cr_ngroups++] = group; } - if (cr->cr_ngroups == 0) { - /* cr->cr_groups[0] filled at start with nogroup(). */ - cr->cr_ngroups = 1; - return; - } + if (cr->cr_ngroups == 0) + goto nogroup; if (cr->cr_ngroups > SMALLNGROUPS) cr->cr_groups = malloc(cr->cr_ngroups * sizeof(gid_t)); memcpy(cr->cr_groups, groups, cr->cr_ngroups * sizeof(gid_t)); + return; + +nogroup: + cr->cr_ngroups = 1; + cr->cr_groups[0] = nogroup(); } #define STRSIZ (MNTNAMLEN+MNTPATHLEN+50)