From: Joe Simmons-Talbott <josimmon@redhat.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: libc-alpha@sourceware.org, Florian Weimer <fweimer@redhat.com>
Subject: Re: [PATCH v11] posix: Deprecate group_member for Linux
Date: Thu, 28 Mar 2024 11:11:18 -0400 [thread overview]
Message-ID: <CAAQBMsMW=oabfsQb5mbpyaGasgCnf6aDjWGgSbnxcsCUC=Fm1A@mail.gmail.com> (raw)
In-Reply-To: <3733a0a9-211f-4ce2-9bc1-c032144afd45@cs.ucla.edu>
On Wed, Mar 27, 2024 at 4:57 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
>
> 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;
>
I like that much better. I've posted a v12[1] with your suggestion
that was tested via 'make check'.
Thanks,
Joe
[1] https://sourceware.org/pipermail/libc-alpha/2024-March/155666.html
--
Joe Simmons-Talbott
prev parent reply other threads:[~2024-03-28 15:12 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
2024-03-28 15:11 ` Joe Simmons-Talbott [this message]
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='CAAQBMsMW=oabfsQb5mbpyaGasgCnf6aDjWGgSbnxcsCUC=Fm1A@mail.gmail.com' \
--to=josimmon@redhat.com \
--cc=eggert@cs.ucla.edu \
--cc=fweimer@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).