From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id C810A1F44D for ; Wed, 27 Mar 2024 20:58:02 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; unprotected) header.d=cs.ucla.edu header.i=@cs.ucla.edu header.a=rsa-sha256 header.s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C header.b=StXlbGHw; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 946FC385E449 for ; Wed, 27 Mar 2024 20:58:01 +0000 (GMT) Received: from mail.cs.ucla.edu (mail.cs.ucla.edu [131.179.128.66]) by sourceware.org (Postfix) with ESMTPS id A3AF33858D34 for ; Wed, 27 Mar 2024 20:57:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3AF33858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A3AF33858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=131.179.128.66 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711573061; cv=none; b=OQwTvu1f0toZUKcdJmZ3K85EuQErmIFbgoOz8PGGxT+/YoJqP49YuHHxcAIn/4n84L2z8tp3k+FyhKnLjjqxNaTVtFXEOb6q2CmgiQJNUgnID66ituvjjHv5EV6EWOq8cfYc5ZgQjoGKPG36npYejQ9Hc1h0EuUfugmsmindWao= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711573061; c=relaxed/simple; bh=adi7O7727/47gR89mUlhoq7nouNGXCGt7XmSAS+YBy8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=hP4Qu11ET9lBKgS2CSq7DCOsI7FkzKUyO5GYom/oc7QvxMJ/ZacVkzAU68H52NiEjWz25ndz3GKlOcAAEzN0QpTvHzeeKUS268Bfp9wbd+4sDKXm2RYkMDqzpZB8shsN1ZcLS5wPEZkAL0GVVC4NVz52qsE6MI+Uucut1fjfISE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id CF3313C00E408; Wed, 27 Mar 2024 13:57:38 -0700 (PDT) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id ctbZ6ru8fJhe; Wed, 27 Mar 2024 13:57:38 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 818A53C00E409; Wed, 27 Mar 2024 13:57:38 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu 818A53C00E409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1711573058; bh=wcQiZ8lxeuwic28AtJl4/SQ3vp+2I8prfJhble7NtbM=; h=Message-ID:Date:MIME-Version:To:From; b=StXlbGHwzaWUSPG3WXnobIiI51PckOJ6nYL9IHhCRnqQ/73LcCjyyhae9NqokYh5R aglOTErtFxZq/yjFJ9HwLQIAJm+LPo065yGfTwqTASAKJpnPjDk0NjPiFBXTsQ9u30 rZXrQVqGTHb3QXKz+7lVdr1LR+RR7oLOyUeU7P6qDQpRJxbQYVBjbp+3dFgiFiJlgh 446ufbtBmspIGcLLww9mfEXh9WmyjcQVF0M/LcLskNVBze/+cmmLEbbGpDhpRih2d5 /N2DnUlUJSHBNgmZoiyoe7mnz7TEoNU9ZjEfRlMqrOTSqXdtzLlFp7TLzMxzy+SnW1 uoVE2RYVLQs1w== X-Virus-Scanned: amavis at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id L8pIojNEKLAc; Wed, 27 Mar 2024 13:57:38 -0700 (PDT) Received: from [10.10.33.175] (unknown [96.69.135.29]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id 394C43C00E408; Wed, 27 Mar 2024 13:57:38 -0700 (PDT) Message-ID: <3733a0a9-211f-4ce2-9bc1-c032144afd45@cs.ucla.edu> Date: Wed, 27 Mar 2024 14:57:37 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v11] posix: Deprecate group_member for Linux To: Joe Simmons-Talbott , libc-alpha@sourceware.org Cc: Florian Weimer References: <20240327184324.916402-1-josimmon@redhat.com> Content-Language: en-US From: Paul Eggert In-Reply-To: <20240327184324.916402-1-josimmon@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org On 3/27/24 12:43, Joe Simmons-Talbott wrote: > + int granted; > + > + if (uid == stats.st_uid) > + granted = (unsigned int) (stats.st_mode & (mode << 6)) >> 6; > + else > + { > + if (((flag & AT_EACCESS) && stats.st_gid == __getegid()) || > + (!(flag & AT_EACCESS) && stats.st_gid == __getgid())) > + granted = (unsigned int) (stats.st_mode & (mode << 3)) >> 3; > + else > + { > + int gm = __group_member2 (stats.st_gid); > + if (gm == -1) > + return -1; > + else if (gm) > + granted = (unsigned int) (stats.st_mode & (mode << 3)) >> 3; > + else > + granted = (stats.st_mode & mode); > + } > + } > > if (granted == mode) > return 0; This is still too complicated, with repetitions of AT_EACCESS that were not in the original. Come to think of it, it has unnecessary casts and repetitive shifting and masking, and that indentation of || is not GNU style. How about something like the following untested code instead? int shift; if (uid == stats.st_uid) shift = 6; else { int gm = (stats.st_gid == (flag & AT_EACCESS ? __getegid () : __getgid ())); if (!gm) { gm = __group_member2 (stats.st_gid); if (gm < 0) return gm; } shift = gm ? 3 : 0; } if ((stats.st_mode >> shift & mode) == mode) return 0;