From nobody Tue Dec 10 23:38:02 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 4Y7FXW0Tdwz5g2bf; Tue, 10 Dec 2024 23:38:03 +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 4Y7FXV31mWz4lRm; Tue, 10 Dec 2024 23:38:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733873882; 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=kBaZWhKZox0QwYQ2Mogf7deny8PZR5BgTlLzpdEGJtY=; b=Jo+25cKQs9ixaG72/rD4dixzXhiZSrsxzQHJW5OlkAqxyjUjCbH3KoF563gkLIENr9om6g 5rAgX1ZHDB482fliy3p/druo7kr7qgxt+LS7Q/Zi9Ppv8zPHaspWE5TRVJV3cztzkuQtkz 5cS1NdPuxm0DzQdzuygYKUtNkmvk/j926+hGoj+eZYJmORkPZRugcMLVi1jMemhoVARSUP floisji7IhWQ/fsJjRcicmX04H8xBhevGDPlDQXHjMZM/H+aQeJwtDo8LhXx7R3Y2cIMV5 XSmlAXqLkRViU+IRKy/QD3RmIIKaptSobIKQpfWsv0tZ19OPQXEe4kaGTFyP5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733873882; 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=kBaZWhKZox0QwYQ2Mogf7deny8PZR5BgTlLzpdEGJtY=; b=vxMZuCUZWJBXyU6tM4m/4V4dOOKMq7H/PyqmGLPt/ng8UbPy2dLKmNDhzXLx9YDgAJdJz/ VKLmsBwp66WlluHbdRwU1Vrt8MaIG2dpn0KNaFM3xVKi68z6uqarSs+ntQZeCWTu+Mgz81 5ibwu/VxsZZQ/KUgaCo8teN1R1rdoV8sWLaHCciQ4s6kAVSyNwaKKdQ8znJev02gJDNPoD SlPkLPbM0UedmibvMSoUfT62ApnrVszLs4ScFDUwzwpHUere/Tvv1QJfcPpS7YlemL8FWH BhqRok5bZxOgn4ZsAukzmVG5o+M4CeMKqW8Zg7cnlRvPdz83KyFQU3YMF8oKgw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733873882; a=rsa-sha256; cv=none; b=vtbhNqhXMjVcOtwSB0I2YBIH529GU94+4i7SXji/v3gAzu/FxR8x5R388DVxgGVlJnFsg+ 7VH5Uy4YhTKL5l7OLWjVwn0TJqZXmDHVP+x0GzK/oSEzaC8MHNpswmR4LF3VsNOvILUlMH N0qa2reIT3TLFLUzFEAH5QmK70DgYMvSokbjDVyf6ryGhhTWvIl6SX0vSlLYxNhlg1vXH9 e+6aA0kEHXPlgI/q6/68fgeJOMijHjzKwMIPlWf8CZ66ApgfdO2idhcFNl17w35ZFIqNMp rVC/grvgAewXNIiKPRaOCayMnx5sdXB8b4KjeHjXibkNt7nIatZRw795QRx60Q== 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 4Y7FXV2bV1zkWY; Tue, 10 Dec 2024 23:38:02 +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 4BANc2If019890; Tue, 10 Dec 2024 23:38:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BANc2dB019887; Tue, 10 Dec 2024 23:38:02 GMT (envelope-from git) Date: Tue, 10 Dec 2024 23:38:02 GMT Message-Id: <202412102338.4BANc2dB019887@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: b50d2127d971 - stable/14 - pw: set the user's home directory mode if it existed 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: b50d2127d9718e54b68ffead90e9de8b5cee72f5 Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=b50d2127d9718e54b68ffead90e9de8b5cee72f5 commit b50d2127d9718e54b68ffead90e9de8b5cee72f5 Author: Kyle Evans AuthorDate: 2024-12-01 19:05:57 +0000 Commit: Kyle Evans CommitDate: 2024-12-10 23:05:51 +0000 pw: set the user's home directory mode if it existed The adduser(8) prompt allows one to set the mode of a new home directory, but pw(8) doesn't honor the -M mode if the home directory already exists at creation time. It doesn't seem to make sense to ignore the mode (which may lead to a security issue on the system being configured) when we'll happily chown an existing directory, so fix the inconsistency. PR: 280099 Reviewed by: des, jlduran (previous version) (cherry picked from commit 6a7238fd7c60f35191eadaa026d3d395c6140c47) --- usr.sbin/adduser/adduser.8 | 6 ++++-- usr.sbin/pw/cpdir.c | 27 +++++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/usr.sbin/adduser/adduser.8 b/usr.sbin/adduser/adduser.8 index 8ba623fedd9d..e21a7653f250 100644 --- a/usr.sbin/adduser/adduser.8 +++ b/usr.sbin/adduser/adduser.8 @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 11, 2024 +.Dd December 1, 2024 .Dt ADDUSER 8 .Os .Sh NAME @@ -246,7 +246,9 @@ file can reference the internal variables of the script. .It Fl M Ar mode Create the home directory with permissions set to -.Ar mode . +.Ar mode , +modified by the current +.Xr umask 2 . .It Fl N Do not read the default configuration file. .It Fl q diff --git a/usr.sbin/pw/cpdir.c b/usr.sbin/pw/cpdir.c index 504933ab88af..3dee8f7c43ac 100644 --- a/usr.sbin/pw/cpdir.c +++ b/usr.sbin/pw/cpdir.c @@ -49,13 +49,28 @@ copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid, if (*dir == '/') dir++; - if (mkdirat(rootfd, dir, mode) != 0 && errno != EEXIST) { - warn("mkdir(%s)", dir); - return; + if (mkdirat(rootfd, dir, mode) != 0) { + mode_t pumask; + + if (errno != EEXIST) { + warn("mkdir(%s)", dir); + return; + } + + pumask = umask(0); + umask(pumask); + + if (fchmodat(rootfd, dir, mode & ~pumask, + AT_SYMLINK_NOFOLLOW) == -1) + warn("chmod(%s)", dir); } - fchownat(rootfd, dir, uid, gid, AT_SYMLINK_NOFOLLOW); - if (flags > 0) - chflagsat(rootfd, dir, flags, AT_SYMLINK_NOFOLLOW); + + if (fchownat(rootfd, dir, uid, gid, AT_SYMLINK_NOFOLLOW) == -1) + warn("chown(%s)", dir); + + if (flags > 0 && chflagsat(rootfd, dir, flags, + AT_SYMLINK_NOFOLLOW) == -1) + warn("chflags(%s)", dir); if (skelfd == -1) return;