From: Eric Blake <ebb9@byu.net>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: dash@vger.kernel.org
Subject: Re: test -x should use faccessat, not stat
Date: Mon, 15 Feb 2010 06:31:14 -0700 [thread overview]
Message-ID: <4B794CA2.1080707@byu.net> (raw)
In-Reply-To: <20100214061137.GA9882@gondor.apana.org.au>
According to Herbert Xu on 2/13/2010 11:11 PM:
> Eric Blake <ebb9@byu.net> wrote:
>> This report was originally raised on the cygwin list:
>>
>> http://cygwin.com/ml/cygwin/2010-02/msg00239.html
>>
>> In short, in the presence of ACLs, dash's implementation of test -r, test -w,
>> and test -x gives incorrect answers, when the current user has permissions to
>> access a file that were granted by ACLs but not by the current stat()
>> permissions. dash should be using faccessat(,AT_EACCESS) (or
>> eaccess/euidaccess) if available, rather than stat(), to determine whether a
>> file is accessible.
>
> What does bash to in this case?
The bash source code shows the following:
In test.c, unary_test() calls sh_eaccess for test -r, -w, and -x.
In lib/sh/eaccess.c, bash currently uses:
int
sh_eaccess (path, mode)
char *path;
int mode;
{
if (path_is_devfd (path))
return (sh_stataccess (path, mode));
#if defined (HAVE_EACCESS) /* FreeBSD */
return (eaccess (path, mode));
#elif defined (EFF_ONLY_OK) /* SVR4(?), SVR4.2 */
return access (path, mode|EFF_ONLY_OK);
#else
if (mode == F_OK)
return (sh_stataccess (path, mode));
# if HAVE_DECL_SETREGID
if (current_user.uid != current_user.euid || current_user.gid !=
current_user.egid)
return (sh_euidaccess (path, mode));
# endif
if (current_user.uid == current_user.euid && current_user.gid ==
current_user.egid)
return (access (path, mode));
return (sh_stataccess (path, mode));
#endif
}
But this could probably be improved to take advantage of the standardized
faccessat(path,mode,AT_EACCESS) in the case where that exists.
Furthermore, the link to the post on the cygwin list shows that bash, zsh,
and pdksh all honored ACLs, and that dash is the odd man out for not
recognizing when the current user has rights due to ACLs that are not
visible through the stat mode bits.
Finally, it is worth pointing out that on at least cygwin, faccessat and
friends are faster than stat. Do you want me to prepare the patch?
--
Don't work too hard, make some time for fun as well!
Eric Blake ebb9@byu.net
next prev parent reply other threads:[~2010-02-15 13:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-10 15:32 test -x should use faccessat, not stat Eric Blake
2010-02-14 6:11 ` Herbert Xu
2010-02-15 13:31 ` Eric Blake [this message]
2010-02-16 12:04 ` Herbert Xu
2010-04-02 14:03 ` Herbert Xu
2010-04-02 14:57 ` Eric Blake
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B794CA2.1080707@byu.net \
--to=ebb9@byu.net \
--cc=dash@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
/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