Re: [PATCH v2 3/3] t: add tests for safe.directory when running with sudo
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 28, 2022, 20:51 UTC
- Message-ID
- <xmqqzgk5dj8n.fsf@gitster.g>
- In-Reply-To
- <000801d85b40$ac11ec80$0435c580$@nexbridge.com>
<rsbecker@nexbridge.com> writes:
>>I actually made sure that is_root was posix shell compatible, but got a little carried >>away when refactoring it to accomodate for reuse; eitherway it is gone in v3. > > I tried to find is_root in POSIX but could not. Do you have a reference? It is not in bash 4.3.48, which is on our older system.
What he meant was the implementation of is_root shell function he wrote in the patch uses construct from POSIX.
is_root() {
test -n "$1" && CMD="sudo -n"
test $($CMD id -u) = $(id -u root)
}Besides, as somebody else already pointed out, this will run random command that is in $CMD (perhaps from tester's environment) when it is run without $1 or an empty string in $1. But other than that, "id" being in POSIX.1, that looks fairly safe. Of course, sudo and sudo -n would not be in POSIX, but that is what this one is testing availablity for, so it is to be expected ;-)