Title: shutil.chown should not be defined in Windows
Type: behavior Stage: needs patch
Components: Library (Lib), Windows Versions: Python 3.10, Python 3.9, Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, kamilturek, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: easy

Created on 2018-03-25 22:55 by eryksun, last changed 2021-03-21 12:45 by kamilturek.

Messages (3)
msg314436 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2018-03-25 22:55
shutil.chown is defined in Windows even though it's only written for Unix and only documented as available in Unix. Defining it should be skipped on Windows.

Possibly in 3.8 shutil.chown could be implemented on Windows by calling a new os.set_owner function that supports user/group names and SID strings. It could copy how icacls.exe allows using SDDL aliases and string SIDs that begin with an asterisk (e.g. "*BA" and "*S-1-32-544" for BUILTIN\Administrators). If the string starts with an asterisk, get the SID via ConvertStringSidToSid. Otherwise get the SID via LookupAccountName. Then to modify the file's user and group, try to enable SeRestorePrivilege for the current thread and call Set[Named]SecurityInfo.
msg314437 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2018-03-25 23:00
Oops, the SID for BUILTIN\Administrators is S-1-5-32-544. I left out the authority ID (5).
msg389139 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-03-20 02:24
Apparently there's no one else interested in implementing shutil.chown() in Windows. Okay, but as long as that's the case, the definition should be skipped in Windows, which is an easy problem.
Date User Action Args
2021-03-21 12:45:57kamiltureksetnosy: + kamilturek
2021-03-20 02:26:15eryksunsettitle: shutil.chown on Windows -> shutil.chown should not be defined in Windows
2021-03-20 02:24:48eryksunsetkeywords: + easy

messages: + msg389139
components: - IO
versions: + Python 3.9, Python 3.10, - Python 3.6, Python 3.7
2018-03-25 23:00:21eryksunsetmessages: + msg314437
2018-03-25 22:55:36eryksuncreate