From nobody Mon Dec 16 14:45:30 2024 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 4YBjRH3KQWz5hW3d; Mon, 16 Dec 2024 14:45:31 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YBjRG6Mj8z4csb; Mon, 16 Dec 2024 14:45:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734360330; 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=FCjlWvefYcvlEWoo+so7MywdQx4mTFM8x7UHAPW2jAU=; b=wsoQnSPU7myZOw8GL4yq1PNAWMxYLWkX9vn0Izo+yrI1itrVLlKn2SHU3gfimrRcgih4d1 RTeTdL7Dnw6wR2lH588AvVhg+4ARbx6LldTIjQmg9t1n0XN4CMJ/lIGmRhxFPvGFEFdsya gAREoN3duhTS+eXnadjzdR6sxtoU2eefSfoiwMcB+Dik6qRbzsh0wdPsEVfxSLKoimz38O ouhj6HRLZv13XeFu8oSwi+PgoSK6PH/d5VC995keRalCjtKtXalB/jYbU+0IYor2v/Od5Q 0o6DCxtCjYZqR8WCMUJZiIHIUW/cV4QScEaBprHy5Hi4Nfk2e8plyHYroRKmnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734360330; 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=FCjlWvefYcvlEWoo+so7MywdQx4mTFM8x7UHAPW2jAU=; b=vFqd/a9Lmeuuck5Nt4S/eZWaQukHoZyxxOA/Y8wfiZaZNfiJJIagDomV5kutRPo5EykVlO byz7MjjIH9TsLWhDJMDW/kksBGHyO6oMg306bgkYwZM+x4ke0c6lEnv855K+VjMxR5WZ0W HBp03Nq+/JecYhCIMGfKCdasrTcSryi4DVABC8MwDVXVkAOASnF7GrgTNWMCsylWcofVey UDf6JdGYqMNRX63tBYRzuo/kiLSw45zRLr3wFluYDYaC+N2Yr6sO6qDjpcDTpqpAD1SYAE s++IcPko4EWPJQJ2tgZQoHVQV7JsP7WlvvTIlEThq+9sagz9X/JF7IS18qS/iA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734360330; a=rsa-sha256; cv=none; b=UWryUILcJ0qJ2cA4vm68olxO7+9BCwWdkWh1B+LkfrvCgvIv0WhnJEodkncXHdUSwqh7zn 0zc4oi2ejy/9ngtNGOKYGwwe7R44Ijf6g+AF9mZY1aikxlYNkHYE+6pjDC604F9A89OYDj B4jAu25PR9RKsHuw5r4o8qEgRsmiHcj3PpowcpDWOy04CVvYlcdarNx57kOUtTxgq4kYLD VhYLlLAzwvuThryw9Pj2Bapqfldu04edWJJ7WGjB78KmiZ8XWu/Ho1SqPvfY+aTCYSCmDm H+ABp6Bmbgs6E7esOEslrnb4vde7yDVYkVZpt31Frg1nel6yM8QXge2JncLZEA== 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 4YBjRG5rCWzxYK; Mon, 16 Dec 2024 14:45:30 +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 4BGEjUlR052169; Mon, 16 Dec 2024 14:45:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BGEjUiV052166; Mon, 16 Dec 2024 14:45:30 GMT (envelope-from git) Date: Mon, 16 Dec 2024 14:45:30 GMT Message-Id: <202412161445.4BGEjUiV052166@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: a20d50245f28 - main - 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/main X-Git-Reftype: branch X-Git-Commit: a20d50245f280be404cb8e3b5c9d570ded9594b9 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=a20d50245f280be404cb8e3b5c9d570ded9594b9 commit a20d50245f280be404cb8e3b5c9d570ded9594b9 Author: Olivier Certner AuthorDate: 2024-10-08 10:06:55 +0000 Commit: Olivier Certner CommitDate: 2024-12-16 14:42:31 +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 --- 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 653d7135ef79..27d22ba06fa4 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -3614,21 +3614,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, ":"); @@ -3637,13 +3630,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; @@ -3658,20 +3663,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, ":"); @@ -3691,14 +3690,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)