From nobody Thu Dec 02 01:12:58 2021 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 4442F18AE701; Thu, 2 Dec 2021 01:12:59 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J4Hy26kHgz3rLP; Thu, 2 Dec 2021 01:12:58 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C733013EF9; Thu, 2 Dec 2021 01:12:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B21CwdE068140; Thu, 2 Dec 2021 01:12:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B21CwPb068139; Thu, 2 Dec 2021 01:12:58 GMT (envelope-from git) Date: Thu, 2 Dec 2021 01:12:58 GMT Message-Id: <202112020112.1B21CwPb068139@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: afb6f8307494 - stable/13 - mountd: Fix handling of usernames that start with a digit 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: afb6f83074944e3843bb171656af9f52ac9d4d98 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638407579; 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=8g0hzJMII8yVc/LQU0LSgT2oBw2/0GxuAau+TmDe+as=; b=K6JYIqyJOCIEnnWufqNXTvBfzQaUzxttTqBC02MCvtycUUbMHnsdDULxU6LwlrUzo/6VRy YR4F4vlhrPLkt4WE+ufKNR6yp1UJbHStnYT+4zPPi2izX8jyk8YH0dwmrCJabusDiYnH52 kRcjcTOCPpe+61RXbFGp0FXhWCjomFJggaTN/pIYmbQUnhVk5f7XAH8PQGFaXJzqBUESD3 ss+S9wwGPxb/ATNLSD7FLk1ALjWBi2XXNz6LIj1pcMqqqI5QD86Yv25FOOVszpuEWIY9k+ Kx6aTorycLkKexwn18LCXFFXKWTjj8MumVEjCJkcpzvTPUW9AXUB8GUyRED7mg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638407579; a=rsa-sha256; cv=none; b=yQX1z3mPYs85BSvkJLe/9PWxpjKp+kjyRI9DzW/65g+lSRWit2sqGiQKeJTGdFfU4iT/Bm /DfkWvQ4hVSG/8srVmDOMrRlDQiWud7xG9fMg2U0A6o9FH1zyUmKNt8IQUvh4L1TTitw/w 7QosF0+NhbLgLsZeefuOsjq1gbjB9p4mFNozIqho74HE7C4VgX/Ys8mwdLAd8IcsBJV0UB euydf34DX1mJUOjvoLevXTP1X8XmeifhrJCvOCvtKUspx3qrsPdQ1V2vT9XKY582eX/Xwj sPHBGbHJFY0T+tYTO0LEa/I8d1n8m2cF/aOr1oiJrXTirtQ8eCPoCTf6aOkKWQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=afb6f83074944e3843bb171656af9f52ac9d4d98 commit afb6f83074944e3843bb171656af9f52ac9d4d98 Author: Rick Macklem AuthorDate: 2021-11-18 21:35:25 +0000 Commit: Rick Macklem CommitDate: 2021-12-02 01:08:35 +0000 mountd: Fix handling of usernames that start with a digit yocalebo_gmail.com submitted a patch for mountd.c that fixes the case where a username starts with a digit. Without this patch, the username that starts with a digit is misinterpreted as a numeric uid. With this patch, any string that does not entirely convert to a decimal number via strtoul() is considered a user/group name. (cherry picked from commit f4bf849bb894f4934b8df6c04a820dfa52e9576c) --- usr.sbin/mountd/mountd.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c index c66ac13b3016..0c077b857d7e 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -3534,6 +3534,8 @@ parsecred(char *namelist, struct expcred *cr) struct group *gr; gid_t groups[NGROUPS_MAX + 1]; int ngroups; + unsigned long name_ul; + char *end = NULL; /* * Set up the unprivileged user. @@ -3548,10 +3550,11 @@ parsecred(char *namelist, struct expcred *cr) names = namelist; name = strsep_quote(&names, ":"); /* Bug? name could be NULL here */ - if (isdigit(*name) || *name == '-') - pw = getpwuid(atoi(name)); - else + name_ul = strtoul(name, &end, 10); + if (*end != '\0' || end == name) pw = getpwnam(name); + else + pw = getpwuid((uid_t)name_ul); /* * Credentials specified as those of a user. */ @@ -3573,8 +3576,9 @@ parsecred(char *namelist, struct expcred *cr) if (ngroups > 1 && groups[0] == groups[1]) { ngroups--; inpos = 2; - } else + } else { inpos = 1; + } if (ngroups > NGROUPS_MAX) ngroups = NGROUPS_MAX; if (ngroups > SMALLNGROUPS) @@ -3589,25 +3593,26 @@ parsecred(char *namelist, struct expcred *cr) * Explicit credential specified as a colon separated list: * uid:gid:gid:... */ - if (pw != NULL) + if (pw != NULL) { cr->cr_uid = pw->pw_uid; - else if (isdigit(*name) || *name == '-') - cr->cr_uid = atoi(name); - else { + } 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' && cr->cr_ngroups < NGROUPS_MAX) { name = strsep_quote(&names, ":"); - if (isdigit(*name) || *name == '-') { - groups[cr->cr_ngroups++] = atoi(name); - } else { + name_ul = strtoul(name, &end, 10); + if (*end != '\0' || end == name) { if ((gr = getgrnam(name)) == NULL) { syslog(LOG_ERR, "unknown group: %s", name); continue; } groups[cr->cr_ngroups++] = gr->gr_gid; + } else { + groups[cr->cr_ngroups++] = name_ul; } } if (names != NULL && *names != '\0' && cr->cr_ngroups == NGROUPS_MAX)