Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-118486: Switch mkdir(mode=0o700) on Windows to use OWNER RIGHTS instead of CURRENT_USER#118515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…HTS instead of CURRENT_USER
@@ -5616,13 +5617,25 @@ initializeMkdir700SecurityAttributes( | |||
return GetLastError(); | |||
} | |||
int use_alias = 0; | |||
DWORD cbSid = sizeof(data->sid); | |||
if (!CreateWellKnownSid(WinCreatorOwnerRightsSid, NULL, (PSID)data->sid, &cbSid)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you prefer to use "CURRENT_USER", you could just move it to the end of the array. Then theSetEntriesInAclW()
call would use a count of 2 or 3 depending on whether the current user is an elevated administrator. The latter is determined by queryingTokenElevationType
. For example:
ULONGentry_count=3;TOKEN_ELEVATION_TYPEelevation_type;DWORDreturn_length;if (GetTokenInformation(GetCurrentProcessToken(),TokenElevationType,&elevation_type,sizeof(elevation_type),&return_length)&&elevation_type==TokenElevationTypeFull) {entry_count=2; }
GetCurrentProcessToken()
returns the pseudohandle(HANDLE)-4
, which has been supported since Windows 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks, but I definitely don't want to try to detect anything about the user's current state. That feels brittle (e.g. if more things are added that ought to be detected).
OWNER RIGHTS is good, and it's actually what I tried to find first. The fallback is just for completeness - I don't expectCreateWellKnownSid
to ever fail here, but at least if it does, we're probably not doing anything too bad.
…HTS instead of CURRENT_USER (pythonGH-118515)
Uh oh!
There was an error while loading.Please reload this page.
This ensures directories created while elevated are not accessible by the same user when non-elevated.
mkdir(mode=0o700)
to work on Windows #118486