From: Paul Eggert <eggert@cs.ucla.edu>
To: Joe Simmons-Talbott <josimmon@redhat.com>, libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>
Subject: Re: [PATCH v11] posix: Deprecate group_member for Linux
Date: Wed, 27 Mar 2024 14:57:37 -0600 [thread overview]
Message-ID: <3733a0a9-211f-4ce2-9bc1-c032144afd45@cs.ucla.edu> (raw)
In-Reply-To: <20240327184324.916402-1-josimmon@redhat.com>
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;
next prev parent reply other threads:[~2024-03-27 20:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-27 18:43 [PATCH v11] posix: Deprecate group_member for Linux Joe Simmons-Talbott
2024-03-27 20:57 ` Paul Eggert [this message]
2024-03-28 15:11 ` Joe Simmons-Talbott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3733a0a9-211f-4ce2-9bc1-c032144afd45@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=fweimer@redhat.com \
--cc=josimmon@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).