From nobody Thu Oct 19 02:44:52 2023 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 4S9sWS3HHRz4xqxB; Thu, 19 Oct 2023 02:44:52 +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 4S9sWS2mXcz3gsZ; Thu, 19 Oct 2023 02:44:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697683492; 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=QmAOq7wySaitB/62r9PMV9n/63f53EsWfcnpr5zgOCc=; b=CLUsubmjxavstWO93y2dSgpoYlI401yLr6Bm2wb15jGHDH8ZNruY8oBgpKt6CACWS1GJXJ OEaELNGiaX9AjE32lRdx6UWbVXX5mDIEml9a+HEvLQHdF+UQUPShmhKwX76AvGhapjE67c FGJPIsUWTq8wOoY5fV3k8qFCp/2VAjNXT9EDDeJdfqsXrC5rn7KelErkeyD36bNkB44fYc 9yulS/GmDxa3m2EcloUSFKCp/cz/eogDGxisH3HSajWm7exvYRBb5z7cZuV3E8OEZGSAEZ 5W3D1Mvt3yAK7bb7lTQgs3rQoNRPLUk2GGg/v4B3C58qJMyN84l9EGLRBYU8vg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697683492; a=rsa-sha256; cv=none; b=UkViZ0kQgI7dE14c9HlxK5jcTulDZzSnvNkmbe6Cwl6hOoYaEIU2Vaa39weA/xAfPkKHHN k/2dA69GkDcTl94srMQJBDET/f7bXqi/yFGR244kKn3alp7S7HNXxwXWY9jYvx5SaDI0xM F1fNuGmwKsbGo6/s9CGeLSYK9ffzqzcn19sCDlY35HQf6bKrJ89yhYjEGd/wihj9hepVLB caNmHrpVwRC6V0yD+k7rVmLVQVDI+wMZ4iHJyyaeQeidy0s7N+qtYT2H7tj6hqrhYZasPB c4FfObMzKQ+k7xkwKeWpfRwoGXvzzXnYl2b7HI1q56UoZE3fGJupNkrhtlO3bQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697683492; 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=QmAOq7wySaitB/62r9PMV9n/63f53EsWfcnpr5zgOCc=; b=Huem5Lx3Qvfye+5zwQI5/lHwR6EK3ab3BLqVyWn87wHui7AoyCjdtU1lvaQKZLkR/RepHi cMl9lAi177F3JLrHngYOJM9Ffy6W0x7FRf8fI/wLDsFK9A8c6zMwQYEEUdbguJ3s5TKiF+ iDnb/EiOg+CHcqa1lX/iMsLou8VSVYBBLBxgFublOsqMB1Hxmn197iEhyOR8NJH3SrTP4D AaSheNcBsttvTQircYsrIv9E1SSub8RAWq8yDk6ts+4vEM9nr6mIbKzknJA4BiiiGMdr4F ZUg9Jm6ZXSyQN3TPwmLqWtokX96I8sN4pb0JLP7WGtVTh62IpeDLRI5iCKFr6A== 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 4S9sWS1sFqzXf5; Thu, 19 Oct 2023 02:44:52 +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 39J2iqqO010039; Thu, 19 Oct 2023 02:44:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39J2iqva010036; Thu, 19 Oct 2023 02:44:52 GMT (envelope-from git) Date: Thu, 19 Oct 2023 02:44:52 GMT Message-Id: <202310190244.39J2iqva010036@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: 767c97c501ae - main - install: handle -m +X more accurately 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: 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: 767c97c501ae72eb3d74bc23ddf5a1d570d8f841 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=767c97c501ae72eb3d74bc23ddf5a1d570d8f841 commit 767c97c501ae72eb3d74bc23ddf5a1d570d8f841 Author: Kyle Evans AuthorDate: 2023-10-19 02:43:06 +0000 Commit: Kyle Evans CommitDate: 2023-10-19 02:44:05 +0000 install: handle -m +X more accurately As described by chmod(1), +X in the mode may be used to optionally set the +x bit if the file is a directory if any of the execute/search bits are set in the original mode. The latter is not applicable because we assume -m is a fresh mask, but a functional +X could be useful in the former case if we're passing along a common INSTALL_MODE that's designed to install either 0644 or 0755 depending simply on whether it's a directory or not. Reviewed by: des Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D42273 --- usr.bin/xinstall/tests/install_test.sh | 16 ++++++++++++++++ usr.bin/xinstall/xinstall.c | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/usr.bin/xinstall/tests/install_test.sh b/usr.bin/xinstall/tests/install_test.sh index b42bdfd0dc60..cbe95f0dfbf3 100755 --- a/usr.bin/xinstall/tests/install_test.sh +++ b/usr.bin/xinstall/tests/install_test.sh @@ -481,6 +481,21 @@ set_owner_group_mode_unpriv_body() { atf_check_equal "$u:$g:10$cM" "$(stat -f"%u:%g:%p" testc)" } +atf_test_case set_optional_exec +set_optional_exec_head() { + atf_set "require.user" "unprivileged" +} +set_optional_exec_body() +{ + echo "abc" > testfile.src + + atf_check install -d -m ug+rX testdir + atf_check test -x testdir + + atf_check install -m ug+rX testfile.src testfile + atf_check test ! -x testfile +} + atf_init_test_cases() { atf_add_test_case copy_to_nonexistent atf_add_test_case copy_to_nonexistent_safe @@ -523,4 +538,5 @@ atf_init_test_cases() { atf_add_test_case mkdir_simple atf_add_test_case set_owner_group_mode atf_add_test_case set_owner_group_mode_unpriv + atf_add_test_case set_optional_exec } diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index d19bacbe8c1b..1ab9cac76f2f 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -189,6 +189,7 @@ main(int argc, char *argv[]) fset = 0; iflags = 0; + set = NULL; group = owner = NULL; while ((ch = getopt(argc, argv, "B:bCcD:df:g:h:l:M:m:N:o:pSsT:Uv")) != -1) @@ -255,11 +256,10 @@ main(int argc, char *argv[]) break; case 'm': haveopt_m = 1; + free(set); if (!(set = setmode(optarg))) errx(EX_USAGE, "invalid file mode: %s", optarg); - mode = getmode(set, 0); - free(set); break; case 'N': if (!setup_getid(optarg)) @@ -301,6 +301,14 @@ main(int argc, char *argv[]) usage(); } + /* + * Default permissions based on whether we're a directory or not, since + * an +X may mean that we need to set the execute bit. + */ + if (set != NULL) + mode = getmode(set, dodir ? S_IFDIR : 0) & ~S_IFDIR; + free(set); + if (getenv("DONTSTRIP") != NULL) { warnx("DONTSTRIP set - will not strip installed binaries"); dostrip = 0;