Open p5pRT opened 9 years ago
Follow-up of #125740.
When checking `-r/-w file'\, pp_ftrread (pp_sys.c:3071) does a `stat'\, then\, in `Perl_cando' (doio.c:2065) guesses whether to override its results.
Sometimes\, it guesses incorrectly: 1) In some cases where Cygwin uses an old ID mapping (https://rt.perl.org/Public/Bug/Display.html?id=125740#txn-1360344) 2) When a user is not a member of Administrators but holds SeBackupPrivilege/SeRestorePrivilege (https://rt.perl.org/Public/Bug/Display.html?id=125740#txn-1359529). Moreover\, Cygwin correctly makes SeBackupPrivilege override only read and SeRestorePrivilege - only write.
Since commit https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=commit;h=2c1ffdbf5e6f2767ab63e67834530539d36c6c0b, Cygwin supports the overriding itself in its faccessat/eaccess/access. So it's better not to second-guess it.
On Tue Aug 11 08:31:30 2015\, vano@mail.mipt.ru wrote:
Follow-up of #125740.
When checking `-r/-w file'\, pp_ftrread (pp_sys.c:3071) does a `stat'\, then\, in `Perl_cando' (doio.c:2065) guesses whether to override its results.
Sometimes\, it guesses incorrectly: 1) In some cases where Cygwin uses an old ID mapping (https://rt.perl.org/Public/Bug/Display.html?id=125740#txn-1360344) 2) When a user is not a member of Administrators but holds SeBackupPrivilege/SeRestorePrivilege (https://rt.perl.org/Public/Bug/Display.html?id=125740#txn-1359529). Moreover\, Cygwin correctly makes SeBackupPrivilege override only read and SeRestorePrivilege - only write.
Since commit https://cygwin.com/git/gitweb.cgi?p=newlib- cygwin.git;a=commit;h=2c1ffdbf5e6f2767ab63e67834530539d36c6c0b\, Cygwin supports the overriding itself in its faccessat/eaccess/access. So it's better not to second-guess it.
That the permission check operators work off the mode is explicitly documented (from =item -X in perlfunc.pod):
The interpretation of the file permission operators C\<-r>\, C\<-R>\, C\<-w>\, C\<-W>\, C\<-x>\, and C\<-X> is by default based solely on the mode of the file and the uids and gids of the user. There may be other reasons you can't actually read\, write\, or execute the file: for example network filesystem access controls\, ACLs (access control lists)\, read-only filesystems\, and unrecognized executable formats. Note that the use of these six specific operators to verify if some operation is possible is usually a mistake\, because it may be open to race conditions.
Also note that\, for the superuser on the local filesystems\, the C\<-r>\, C\<-R>\, C\<-w>\, and C\<-W> tests always return 1\, and C\<-x> and C\<-X> return 1 if any execute bit is set in the mode. Scripts run by the superuser may thus need to do a stat() to determine the actual mode of the file\, or temporarily set their effective uid to something else.
as is the mechanism to use access():
If you are using ACLs\, there is a pragma called C\
Is this documented behaviour what you were trying to report? If it was something else please provide some sample code.
Thanks\, Tony
The RT System itself - Status changed from 'new' to 'open'
That the permission check operators work off the mode is explicitly documented (from =item -X in perlfunc.pod):
\<...> Also note that\, for the superuser on the local filesystems\, the C\<-r>\, C\<-R>\, C\<-w>\, and C\<-W> tests always return 1\, and C\<-x> and C\<-X> return 1 if any execute bit is set in the mode. Scripts run by the superuser may thus need to do a stat() to determine the actual mode of the file\, or temporarily set their effective uid to something else.
\<...> Is this documented behaviour what you were trying to report? If it was something else please provide some sample code.
In these terms\, Perl incorrectly detects if the current user is a "superuser" (=a user who overrides permissions) in the specified cases.
-- Best regards\, Ivan mailto:vano@mail.mipt.ru
On Thu Aug 13 04:25:25 2015\, vano@mail.mipt.ru wrote:
That the permission check operators work off the mode is explicitly documented (from =item -X in perlfunc.pod):
\<...> Also note that\, for the superuser on the local filesystems\, the C\<- r>\, C\<-R>\, C\<-w>\, and C\<-W> tests always return 1\, and C\<-x> and C\<-X> return 1 if any execute bit is set in the mode. Scripts run by the superuser may thus need to do a stat() to determine the actual mode of the file\, or temporarily set their effective uid to something else.
\<...> Is this documented behaviour what you were trying to report? If it was something else please provide some sample code.
In these terms\, Perl incorrectly detects if the current user is a "superuser" (=a user who overrides permissions) in the specified cases.
Is there a correct check?
Or is cygwin's emulation of mode flags (because of Win32) sufficiently non-POSIX that it isn't possible to get even close to making it work?
Are you suggesting a fix? If it's "use access()" then you already have an option to do so.
Tony
Tony Cook via RT \<perlbug-followup \
In these terms\, Perl incorrectly detects if the current user is a "superuser" (=a user who overrides permissions) in the specified cases.
Is there a correct check?
Perl doesn't have the distinction of checking for "permission overrides"\, it just checks for some sort of "superuser/root". That would be someone with group 544 in his security token on Windows\, kinda-sort-of.
Or is cygwin's emulation of mode flags (because of Win32) sufficiently non-POSIX that it isn't possible to get even close to making it work?
There's a few things that don't translate well at the moment if ACL are structured in a peculiar way (mostly visible on network shares). Work is underway to address these.
Are you suggesting a fix? If it's "use access()" then you already have an option to do so.
That option would only be viable if it filled the stat cache and allowed stacked file tests\, otherwise you would have to re-structure the file tests everywhere. There's some mumbling that this issue maybe addressable sometime in the future\, but in any case this is a different question than "when should Perl ignore the bits it gets from stat and assume it knows better".
Regards\, Achim.
Wednesday\, August 19\, 2015\, 9:20:14 Tony:
Is there a correct check?
Or is cygwin's emulation of mode flags (because of Win32) sufficiently non-POSIX that it isn't possible to get even close to making it work?
Are you suggesting a fix? If it's "use access()" then you already have an option to do so.
It's not about using `access' or not using `access'. It's about implementing the function to return correct results (and as long as it does - who cares how it is implemented?). If using `access' is the only practical way - then what's wrong with it?
The only other way is\, well\, replicating Cygwin's logic implemented in its fhandler.cc::fhandler_base::fhaccess(). I don't want to do this because the copy will become invalid the next time they change their logic (hence the ticket's name).
-- Regards\, Ivan Pozdeev
The only other way is\, well\, replicating Cygwin's logic implemented in its fhandler.cc::fhandler_base::fhaccess(). I don't want to do this because the copy will become invalid the next time they change their logic (hence the ticket's name).
Yet another way is to declare -r/-w without "use filetest 'access'" officially broken in cases where `stat' bits aren't the only thing that governs access (cygwin/other nontrivial emulators\, selinux/similar modules\, network shares). Then the tests need to be rewritten to skip relevant checks in these cases.
This might actually be a good thing: interpreting the bits by hand where there can be other arbitrary factors is a fundamentally wrong thing to do.
-- Best regards\, Ivan mailto:vano@mail.mipt.ru
Migrated from rt.perl.org#125788 (status was 'open')
Searchable as RT125788$