Eryk Sun <eryk...@gmail.com> added the comment:

With increasing use of os.access() in shutil and tempfile, it would be nice to 
have a real implementation of os.access() for Windows. 

Instead of manually evaluating the security of the file/directory, as 
issue2528.2.patch attempts to do, I'd rather just open the file with the 
desired access (e.g. GENERIC_READ, GENERIC_WRITE, GENERIC_EXECUTE). An 
open-based check supports checking for sharing violations, filesystem policy 
(e.g. FILE_READ_ATTRIBUTES granted by the parent directory), non-filesystem 
devices, and access policy implemented by filter drivers in the device stack. 

The code to open the file/directory can be factored out and generalized from 
the stat() implementation. The common open function can implement the flags 
AT_SYMLINK_NOFOLLOW and AT_EACCESS (without which it should temporarily revert 
to the process access token). Also, when a directory is opened with 
GENERIC_WRITE access, it can re-try the open with FILE_DELETE_CHILD access, 
which POSIX includes in write access for a directory.

An S_OK flag could also be supported to ignore a sharing violation in Windows. 
[MS-FSA] section 2.1.5.1.2 (Open of an Existing File) specifies that access 
sharing is checked after the readonly attribute and file security access check. 
So if an open fails with a sharing violation, the caller knows that access was 
otherwise granted.

----------
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue2528>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to