From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id D4C251F4D7 for ; Thu, 28 Apr 2022 21:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352765AbiD1V7K convert rfc822-to-8bit (ORCPT ); Thu, 28 Apr 2022 17:59:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352697AbiD1V6z (ORCPT ); Thu, 28 Apr 2022 17:58:55 -0400 Received: from elephants.elehost.com (elephants.elehost.com [216.66.27.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F6404EDD8 for ; Thu, 28 Apr 2022 14:55:38 -0700 (PDT) Received: from Mazikeen (cpe00fc8d49d843-cm00fc8d49d840.cpe.net.cable.rogers.com [174.119.96.21] (may be forged)) (authenticated bits=0) by elephants.elehost.com (8.16.1/8.16.1) with ESMTPSA id 23SLtXnj029425 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 28 Apr 2022 17:55:33 -0400 (EDT) (envelope-from rsbecker@nexbridge.com) Reply-To: From: To: "'Carlo Arenas'" Cc: "'Junio C Hamano'" , References: <20220428033544.68188-1-carenas@gmail.com> <20220428105852.94449-1-carenas@gmail.com> <20220428105852.94449-4-carenas@gmail.com> <000001d85b39$9d5cfc90$d816f5b0$@nexbridge.com> <000801d85b40$ac11ec80$0435c580$@nexbridge.com> In-Reply-To: Subject: RE: [PATCH v2 3/3] t: add tests for safe.directory when running with sudo Date: Thu, 28 Apr 2022 17:55:28 -0400 Organization: Nexbridge Inc. Message-ID: <000f01d85b4a$af8c3aa0$0ea4afe0$@nexbridge.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8BIT X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQEhoH1klsquz/XrUeoh6UIeie+nGgNSFEhJAdygO20BcR/rTQHiUZcMAngeyfgBGrLMqwDSjnBurgwVb4A= Content-Language: en-ca Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On April 28, 2022 4:56 PM, Carlo Arenas wrote: >On Thu, Apr 28, 2022 at 1:43 PM wrote: >> 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. > >my bad; is_root is a helper function i provided as part of this file; the latest version >which should work in your posix system AND was specifically written to hopefully >not break with NON-STOP based on what you told us about it looks like (hand >edited and not tested) : > >is_root() { > id -u >u > id -u root >r > cmp u r >} This is about as portable as I can find and works even in ksh. It could be optimized. is_root() { id -u >u id -u root >r cmp -s u r if [ $? -ne 0 ]; then echo 0 else echo 1 fi } if [ `is_root` -ne 0 ]; then echo root else echo Not root fi