From nobody Sun Dec 01 19:10:50 2024 X-Original-To: dev-commits-src-main@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 4Y1c2M2n2wz5g3X2; Sun, 01 Dec 2024 19:10:51 +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 4Y1c2M0sCpz46y1; Sun, 1 Dec 2024 19:10:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733080251; 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=gwJWgW1lyY9UBrYq7MVWTVGuSaD1IHlI1pkUR+8fCpk=; b=UNaRvtUbJVbucC1ax0GsQ9uvgaf8j/NRddfHES0cAXv1Q6qBo4M/IbbyEs6UABoo8PifwS yBetXOln0QGO5MzmsbI5Mlu7wD979GR1H52AlWID3bMlOhDtRE6vhmY6m2FZoNWWUFuOkG 5DTLeDQA7JpFNn5LqQclgnoES6LN027//2iB9wyXWNtbHGCYoPz2OidfW3LATLU8vqgasF Ibg3ScO6A1zB2Dug645DDCnlxO3nSIG7RVsOOid7Kn9RCD9toD01LXWLuiNJUSw3wqPDFV pb+1PtRHHQfMWmYMBnT2Ov4v9QmarJZCb0EIq3GV/IQHNWsdIyqZpSuRSBk+ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733080251; 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=gwJWgW1lyY9UBrYq7MVWTVGuSaD1IHlI1pkUR+8fCpk=; b=Bs04G3STOh8tpPU8cqbyJFVzARHp1kqj0ZZztK5LpYnybUfVqfnxNtKzwy7YnPbOGeDV2f WjYEVUbn7SbfMhVUHEkeYoSTgOPh2gbnSricjNjTKNSl7KyXnZLKMhSEMtbtaFxZEEABfx HpxY3Qu5DHvZGbPp3GbM0G0yqhMi+t91vdcGGnsSn/3GyetJivoBMH9Ljbrc+o6m+AyqPI nzXfxBzRF6JNEGSXXyPUgEzEGrg7xi2tMiy/UwAeye4VaEHS8ZsgLG31ZEX7QtKLfoAq++ 0k8u8VH6VVHdlhWRN542ds+vsjMfyOy36G1u9kpmSPn5XeWoagVgQYmNEO2Xjg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733080251; a=rsa-sha256; cv=none; b=aykemIFQLTAeglyOWjHvOCm74vIEzs5FUjXtXC2N0kfi1vWMDyF3hwHPTSFb39QtmU8x+J RlURViMbZ7KjzeOEugDHEserU8gL/9rGJXK5fjgdkg4/tvH/Q8tjzQydS3hQJPPh2bC3p5 NdCKHao8dqeysDjemYu8v9HZ0iFSP6z21ILVhuSrnfrOvH9W4W6Iak1lgTvsHf6kPHpLob IcZX8iGaBBf5o8pCtcAV3PBXTu/b+CeWuTPztJtdw5evTOlYwLwj5gn3mIlF/aPCwhTus9 5nGiI9qwG8NDD6JyUHMJp8zpIEVH+Afb5pULLNDscszmwv1+phrONJlHpvuIrQ== 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 4Y1c2M0QRgz15MK; Sun, 1 Dec 2024 19:10:51 +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 4B1JAo8r095823; Sun, 1 Dec 2024 19:10:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B1JAoYX095820; Sun, 1 Dec 2024 19:10:50 GMT (envelope-from git) Date: Sun, 1 Dec 2024 19:10:50 GMT Message-Id: <202412011910.4B1JAoYX095820@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 6a7238fd7c60 - main - pw: set the user's home directory mode if it existed List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 6a7238fd7c60f35191eadaa026d3d395c6140c47 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=6a7238fd7c60f35191eadaa026d3d395c6140c47 commit 6a7238fd7c60f35191eadaa026d3d395c6140c47 Author: Kyle Evans AuthorDate: 2024-12-01 19:05:57 +0000 Commit: Kyle Evans CommitDate: 2024-12-01 19:08:31 +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) Differential Revision: https://reviews.freebsd.org/D46443 --- 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;