From nobody Thu Feb 01 21:31:10 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 4TQsXZ451gz58jDK; Thu, 1 Feb 2024 21:31:10 +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 4TQsXZ2LzBz4bs8; Thu, 1 Feb 2024 21:31:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706823070; 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=Mt77MkzPaOalxlQUrIQasg4ZDxf86ZITEJNzn7R/NMg=; b=Gsscg4ErRGgegc0Vpw6JUrRfJ1AesBvWC62+AZLehTqYWmq0AwhWnUuzo6QIAzjdEtqC9J qkOd7TTeSE7dP1jGixFmoz0BBjoJ5rsD3cxdgjecAe4z3oeZ+fyVEVwGahqNhoxkec5S2i nIKuDgEjTUF2e37qepztQWRmT0fwTigkwCk69QkCGUAnk8Sq6xRktaPcHZxhQKK1i7I2y5 VuKU7T7We4enOiWWSxOUoUb52YE1Cb3PxwD6U9AfvNVUCTHo2aCcwtf+KiyApuDq8Q1qpq k5keK18ycIAUT8uYiRRZuH+8QusIxjfhIQqmsRnySm/MEsSW9uQynGS3I9Kwdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706823070; 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=Mt77MkzPaOalxlQUrIQasg4ZDxf86ZITEJNzn7R/NMg=; b=vdOM/GtSPmG45j6UI87dt57uBDtpZk3c/oy/jOTtzcr+0yO/oTiY+wGETY5v5NzQRZXNSP slJSD6NcxsOdTPDXHKpsZp3edsyYn+TZY5L6yzKyh2n/DszvAPnZ/H9LyuFkA0TdGGWihS iCY3KiGfKbTrP0TcorZcNeVSYcn0McVTuKl44q8QB3T55g9IY7uNoV2Xe0G+hLquSguYc7 KgZlQT0qhls3SEStIeXz0Hnc9dkzk+NIyapYZBIGeVyLyfZPexGEPCzoMr588Gn4Dj2D1Y MaSxOqfUeEbPa6GkpYpQsNYROAP/DuERb9wsSISEbV+OgJQjYpSOfa6BdgaVTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706823070; a=rsa-sha256; cv=none; b=FKFJxLEnmMHe7zX7wwNCfIFZp2FuN9twa79sN6lPdNTN4jt4y16EqqkScCMculpf4rBDUU KmF4ptEX8m+GLFYB17ekMn7UEC/nIO7d0tEDj2Ew7A5OTIpX7TaKZ45Oz3j0U8ZKM07jsk iIYJkRfLJ63dhhR0RHZOoADOQSeZLERGjYjLzbWrR7AMZoK3TBzlaUnKCLpAik1L9EaLcK 9MVbCTQwevDFpagGsllwuOkpL1v/AQrw5SC8O2dAJ+wQ8t8XhVusQQuh2i7aQ0lMxtmZA5 Hj+dTjBEtyEodI0ieBmbUXwNhjBNZM4+8gRkfMT0F6MojVt8PomqhZJsYIEfmA== 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 4TQsXZ1SmCz1Gw1; Thu, 1 Feb 2024 21:31:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 411LVAWo080517; Thu, 1 Feb 2024 21:31:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 411LVA06080514; Thu, 1 Feb 2024 21:31:10 GMT (envelope-from git) Date: Thu, 1 Feb 2024 21:31:10 GMT Message-Id: <202402012131.411LVA06080514@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: 787abe7d6eb6 - stable/14 - setusercontext(): Set umask in a separate function, setclassumask() 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 787abe7d6eb64cefe0d92a6a9f00324f960bd55e Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=787abe7d6eb64cefe0d92a6a9f00324f960bd55e commit 787abe7d6eb64cefe0d92a6a9f00324f960bd55e Author: Olivier Certner AuthorDate: 2023-06-20 16:46:31 +0000 Commit: Olivier Certner CommitDate: 2024-02-01 21:28:52 +0000 setusercontext(): Set umask in a separate function, setclassumask() Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40686 (cherry picked from commit 0dd1705f584947625892988afe59e4cedb5cdd09) Approved by: markj (mentor) --- lib/libutil/login_class.c | 59 ++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c index 2b85425d8d8e..69230db32961 100644 --- a/lib/libutil/login_class.c +++ b/lib/libutil/login_class.c @@ -381,6 +381,37 @@ setclasscontext(const char *classname, unsigned int flags) } +/* + * Private function setting umask from the login class. + */ +static void +setclassumask(login_cap_t *lc, const struct passwd *pwd) +{ + /* + * Make it unlikely that someone would input our default sentinel + * indicating no specification. + */ + const rlim_t def_val = INT64_MIN + 1, err_val = INT64_MIN; + const rlim_t val = login_getcapnum(lc, "umask", def_val, err_val); + + if (val != def_val) { + if (val < 0 || val > UINT16_MAX) { + /* We get here also on 'err_val'. */ + syslog(LOG_WARNING, + "%s%s%sLogin class '%s': " + "Invalid umask specification: '%s'", + pwd ? "Login '" : "", + pwd ? pwd->pw_name : "", + pwd ? "': " : "", + lc->lc_class, + login_getcapstr(lc, "umask", "", "")); + } else { + const mode_t mode = val; + + umask(mode); + } + } +} /* * Private function which takes care of processing @@ -394,32 +425,8 @@ setlogincontext(login_cap_t *lc, const struct passwd *pwd, unsigned long flags) if (flags & LOGIN_SETRESOURCES) setclassresources(lc); /* See if there's a umask override */ - if (flags & LOGIN_SETUMASK) { - /* - * Make it unlikely that someone would input our default sentinel - * indicating no specification. - */ - const rlim_t def_val = INT64_MIN + 1, err_val = INT64_MIN; - const rlim_t val = login_getcapnum(lc, "umask", def_val, err_val); - - if (val != def_val) { - if (val < 0 || val > UINT16_MAX) { - /* We get here also on 'err_val'. */ - syslog(LOG_WARNING, - "%s%s%sLogin class '%s': " - "Invalid umask specification: '%s'", - pwd ? "Login '" : "", - pwd ? pwd->pw_name : "", - pwd ? "': " : "", - lc->lc_class, - login_getcapstr(lc, "umask", "", "")); - } else { - const mode_t mode = val; - - umask(mode); - } - } - } + if (flags & LOGIN_SETUMASK) + setclassumask(lc, pwd); /* Set paths */ if (flags & LOGIN_SETPATH) setclassenvironment(lc, pwd, 1);