From nobody Wed Aug 3 19:04:28 2022 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 4Lyh9m3ChSz4YRL1; Wed, 3 Aug 2022 19:04:28 +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 4Lyh9m2Yn5z49hG; Wed, 3 Aug 2022 19:04:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659553468; 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=oSNoNHrOPhvK61K7IKMjyp7Zb6U3BSqtx2X7pA+6PqU=; b=ipX0Cn+DWPWsqhz9O6jOyKgy0BGl2W2nJo1K0z5lrnWGTzZMNz4u84znJSFopMIjUY2i7d /dYasCUSXbjw4gWdghCF3Gdemfh+iDGN85kv1PBy9/n/4iTkuLz/mTn64MO2o96nQAqBkD Rcu+9AwZEVGJSY8AGvYZDjLZf9cKE/+L0no/feNpXS4Karw9vqU5KDLQNFB22v64HjfIp2 Klayr4wY6aGNQSHU7iz7liWc435JWGEt6Afe2455k3HUmi46BIOOxamiyVI6OEnCq8PiUc gUZTCSGyYLGKuqTCh4APpdJ8Nvt6N7BUwV/mYMjwOt667rbBSC9/cTx3gTQTzA== 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 4Lyh9m1WbZz12TT; Wed, 3 Aug 2022 19:04:28 +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 273J4S5J021845; Wed, 3 Aug 2022 19:04:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 273J4SuL021844; Wed, 3 Aug 2022 19:04:28 GMT (envelope-from git) Date: Wed, 3 Aug 2022 19:04:28 GMT Message-Id: <202208031904.273J4SuL021844@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 36d67475f549 - main - xinstall: fix dounpriv logic, add tests 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 36d67475f5497664d33c41c2f6745dcb30b0ec42 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659553468; 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=oSNoNHrOPhvK61K7IKMjyp7Zb6U3BSqtx2X7pA+6PqU=; b=izDQ73XkByP5KwWjZbKC3cCwy47wyiHUucWN03adF1vWCBcA9hrQoyai5V8lFKQfdyMW4+ oFAThlaV/RvHcKgknR4HvmnsQXhWhWHPLE73Yj9yIxYmuBRzSM7my6F0cAPu80NbuT/9QN T4eSzZRIKKJ+nPJ4r7iHJLhDezK/l0CfOfxkjiGSn91MoG6LTNj6nYdnmL8F3IHYZyh37v SkpKggAbmmfkpmVvvB/GKTx+kMXsPaZ29n4TpktHQzlxERDixRH68RpjyKo8qSuoZite6N 46XPx5yWg+hRBtHYDLxDxbdP1wamVU1Qy1OEMA7AG2kZe9QDSR7WCV+RMJMIeA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659553468; a=rsa-sha256; cv=none; b=N/OF8Unle8R+KQNA0KAN/Dw8QeDLv/lsxbOnPa5zLRnQT5XEuLAZ/wBNMGVR8+gsa7r6om 6cNNS5fyRUVssbr2Jtsz4c+oDcJ2Ijiqd0bMKvBoEHUvFTV5coNnsTKlPT6gzXiDtoO40M ADUyewBc+raMwI26Ii6Cvjv7yFaDYBKCukW/MunkzqXMr8wWAUDUEUERw/v4qIMrGIxb6u 1GH3BkbIv/JiOBGk0pL45gXh7yI6cfQnuLaXcOHTy+E+997aGu+0GEn6IkBBuMuI7ZapHU hmkHkzEKNtYeX8f4zgyLlTF60ucmG0ZODx5tC98Y6T1yMyQLlU5lAkH+la1Eaw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=36d67475f5497664d33c41c2f6745dcb30b0ec42 commit 36d67475f5497664d33c41c2f6745dcb30b0ec42 Author: Dag-Erling Smørgrav AuthorDate: 2022-08-03 18:59:28 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2022-08-03 19:03:49 +0000 xinstall: fix dounpriv logic, add tests Sponsored by: Klara, Inc. MFC after: 1 week --- usr.bin/xinstall/tests/install_test.sh | 80 ++++++++++++++++++++++++++++++++++ usr.bin/xinstall/xinstall.c | 15 +++---- 2 files changed, 87 insertions(+), 8 deletions(-) diff --git a/usr.bin/xinstall/tests/install_test.sh b/usr.bin/xinstall/tests/install_test.sh index c723a6e0d280..e95f40fc19e7 100755 --- a/usr.bin/xinstall/tests/install_test.sh +++ b/usr.bin/xinstall/tests/install_test.sh @@ -404,6 +404,84 @@ symbolic_link_relative_absolute_common_body() { fi } +atf_test_case set_owner_group_mode +set_owner_group_mode_head() { + atf_set "require.user" "root" +} +set_owner_group_mode_body() { + local fu=65531 fg=65531 + local cu=65532 cg=65532 + local u="$(id -u)" + local g="$(id -g)" + local m=0755 cm=4444 + printf "test" >testf + atf_check chown "$fu:$fg" testf + atf_check chmod "$m" testf + + atf_check install testf testc + atf_check_equal "$u:$g:10$m" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -o "$cu" testf testc + atf_check_equal "$cu:$g:10$m" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -g "$cg" testf testc + atf_check_equal "$u:$cg:10$m" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -o "$cu" -g "$cg" testf testc + atf_check_equal "$cu:$cg:10$m" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -m "$cm" testf testc + atf_check_equal "$u:$g:10$cm" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -o "$cu" -m "$cm" testf testc + atf_check_equal "$cu:$g:10$cm" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -g "$cg" -m "$cm" testf testc + atf_check_equal "$u:$cg:10$cm" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -o "$cu" -g "$cg" -m "$cm" testf testc + atf_check_equal "$cu:$cg:10$cm" "$(stat -f"%u:%g:%p" testc)" +} + +atf_test_case set_owner_group_mode_unpriv +set_owner_group_mode_unpriv_head() { + atf_set "require.user" "root" +} +set_owner_group_mode_unpriv_body() { + local fu=65531 fg=65531 + local cu=65532 cg=65532 + local u="$(id -u)" + local g="$(id -g)" + local m=0755 cm=4444 cM=0444 + printf "test" >testf + atf_check chown "$fu:$fg" testf + atf_check chmod "$m" testf + + atf_check install -U testf testc + atf_check_equal "$u:$g:10$m" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -U -o "$cu" testf testc + atf_check_equal "$u:$g:10$m" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -U -g "$cg" testf testc + atf_check_equal "$u:$g:10$m" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -U -o "$cu" -g "$cg" testf testc + atf_check_equal "$u:$g:10$m" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -U -m "$cm" testf testc + atf_check_equal "$u:$g:10$cM" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -U -o "$cu" -m "$cm" testf testc + atf_check_equal "$u:$g:10$cM" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -U -g "$cg" -m "$cm" testf testc + atf_check_equal "$u:$g:10$cM" "$(stat -f"%u:%g:%p" testc)" + + atf_check install -U -o "$cu" -g "$cg" -m "$cm" testf testc + atf_check_equal "$u:$g:10$cM" "$(stat -f"%u:%g:%p" testc)" +} + atf_init_test_cases() { atf_add_test_case copy_to_nonexistent atf_add_test_case copy_to_nonexistent_safe @@ -444,4 +522,6 @@ atf_init_test_cases() { atf_add_test_case symbolic_link_relative_absolute_source_and_dest2 atf_add_test_case symbolic_link_relative_absolute_common atf_add_test_case mkdir_simple + atf_add_test_case set_owner_group_mode + atf_add_test_case set_owner_group_mode_unpriv } diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index 05b1444506db..ddad7ba9115e 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -1009,19 +1009,18 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags) #endif } - if (!dounpriv & - (gid != (gid_t)-1 && gid != to_sb.st_gid) || - (uid != (uid_t)-1 && uid != to_sb.st_uid)) + if (!dounpriv && ((gid != (gid_t)-1 && gid != to_sb.st_gid) || + (uid != (uid_t)-1 && uid != to_sb.st_uid))) { if (fchown(to_fd, uid, gid) == -1) { serrno = errno; (void)unlink(to_name); errno = serrno; err(EX_OSERR,"%s: chown/chgrp", to_name); } - + } if (mode != (to_sb.st_mode & ALLPERMS)) { if (fchmod(to_fd, - dounpriv ? mode & (S_IRWXU|S_IRWXG|S_IRWXO) : mode)) { + dounpriv ? mode & (S_IRWXU|S_IRWXG|S_IRWXO) : mode)) { serrno = errno; (void)unlink(to_name); errno = serrno; @@ -1036,7 +1035,7 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags) * trying to turn off UF_NODUMP. If we're trying to set real flags, * then warn if the fs doesn't support it, otherwise fail. */ - if (!dounpriv & !devnull && (flags & SETFLAGS || + if (!dounpriv && !devnull && (flags & SETFLAGS || (from_sb.st_flags & ~UF_NODUMP) != to_sb.st_flags) && fchflags(to_fd, flags & SETFLAGS ? fset : from_sb.st_flags & ~UF_NODUMP)) { @@ -1082,7 +1081,7 @@ compare(int from_fd, const char *from_name __unused, size_t from_len, return 1; do_digest = (digesttype != DIGEST_NONE && dresp != NULL && - *dresp == NULL); + *dresp == NULL); if (from_len <= MAX_CMP_SIZE) { if (do_digest) digest_init(&ctx); @@ -1390,7 +1389,7 @@ install_dir(char *path) ch = *p; *p = '\0'; again: - if (stat(path, &sb) < 0) { + if (stat(path, &sb) != 0) { if (errno != ENOENT || tried_mkdir) err(EX_OSERR, "stat %s", path); if (mkdir(path, 0755) < 0) {