[issue2528] Change os.access to check ACLs under Windows

Eryk Sun report at bugs.python.org
Thu Mar 11 21:11:01 EST 2021


Eryk Sun <eryksun at 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 <report at bugs.python.org>
<https://bugs.python.org/issue2528>
_______________________________________


More information about the Python-bugs-list mailing list