From nobody Fri Jan 17 12:27:17 2025 X-Original-To: dev-commits-src-all@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 4YZJs237s0z5kvlt; Fri, 17 Jan 2025 12:27:18 +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 4YZJs13nfZz3TnZ; Fri, 17 Jan 2025 12:27:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737116837; 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=hiqnB/CQaafCTWFbtIGs6fWPEk7eZdPL0H2w7hbAyNc=; b=ZWglmzVWWiAX27SzuXBuL3sXoWH5S8vxcx6iaAfkJbuQ7Db3+1lmAaffsvHcLSwC+uqDSU 3bAYtRASuz6HDiGz87RI88ut3AZSEhS/fzwboclG2tUJsKCKwVxgZVu1+gULjjpAuNnt9x Qy6v/jAcPfBi1XDWKWBP+cTyxVmu91+TErdkUjZIZ8ZnVoYbfnjkB4UWBxwPuJfWDjdyxV WZ6yAEvAUks1Dr6knDS3cBPCZcP7h+fJaXHHE15nqcSOCMqcwMtBEGVTZeOL04fviqHQm5 8rext7qL/Z3kJ3XSeaSDRvFcw3WPNIeWCdtV61CZSklzLVAcxvq2ISabUtFcmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737116837; 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=hiqnB/CQaafCTWFbtIGs6fWPEk7eZdPL0H2w7hbAyNc=; b=pWZDZcCox18kUR6bNgzNe4zXVjLCakb52YdWU9JI9OpMhTRXBmx4v1VAKC+zU13JxbJLeL fUdSx2aJ5EqbsaK7mCeJjk7OY+CMPpnF1WiB2Lq64psxImHBQFe8NAECEdCrAG0lmU5Z8q jhCy0wKI41p8nSPSUJemoFtpGR+uwbR8N+yUA1XdrE+US39+uN3abV2m2+utRmxxSxhaJY jMTYJRqyK7T0Y0YfF+tFFcdqRk5IqaL5bkT2GJx9IUVJXbRw8MbLoFa8pAB9MUWARDsGY3 0on7kY23nfguRAnCHmpm0CTZZJ1DdEMfYdy5XlaY8oF6LAPj5HY9CsWxMNfB1Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737116837; a=rsa-sha256; cv=none; b=tPJmN8xhN0GFGzSL8+fC9G9mimRfqLYUX4H73IrvMNi3Dy68GZ0TTSXKw1FByZRuzupQME osJGeppXZi4xUyc+L0rscld/Noyfrc6wJROBP7/h0aAOoNRKf8zcnQ4XyoAXj4/SdiseFT SOrqzIQyuW7bxZHhzJ8AQkku55agF8mL0VfMY68o7U9E9ztoOdWx27oZV6JbjqjgfsAtA+ UmSXENgBf7odBU8BlGffCzlbJrFFaPrSEE3OLlWilGHxu3CXQt+XWD2V2ZKHG2tgpbyH0P kTf+vJ8ydW+TRbfmyCnvmLnujTHm9ownzg5OKLH++IJcG6x+L6HgzdYbtWyPKg== 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 4YZJs11rfwz2p5; Fri, 17 Jan 2025 12:27:17 +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 50HCRHSX052638; Fri, 17 Jan 2025 12:27:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50HCRHGY052635; Fri, 17 Jan 2025 12:27:17 GMT (envelope-from git) Date: Fri, 17 Jan 2025 12:27:17 GMT Message-Id: <202501171227.50HCRHGY052635@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: f8e47b137a80 - stable/13 - mountd(8): parsecred(): Re-order operations for clarity List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/13 X-Git-Reftype: branch X-Git-Commit: f8e47b137a80ca4c3e8d932d1b4b8f89c3d02942 Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=f8e47b137a80ca4c3e8d932d1b4b8f89c3d02942 commit f8e47b137a80ca4c3e8d932d1b4b8f89c3d02942 Author: Olivier Certner AuthorDate: 2024-10-08 10:06:55 +0000 Commit: Olivier Certner CommitDate: 2025-01-17 12:24:52 +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 8ddedbb16f24..ac1a652f349e 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -3573,21 +3573,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, ":"); @@ -3596,13 +3589,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; @@ -3617,20 +3622,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, ":"); @@ -3650,14 +3649,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)