Skip to content

Commit 8ed5466

Browse files
authored
gh-118486: Switch mkdir(mode=0o700) on Windows to use OWNER RIGHTS instead of CURRENT_USER (GH-118515)
1 parent 16acecd commit 8ed5466

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Modules/posixmodule.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5587,6 +5587,7 @@ struct _Py_SECURITY_ATTRIBUTE_DATA {
55875587
PACL acl;
55885588
SECURITY_DESCRIPTOR sd;
55895589
EXPLICIT_ACCESS_W ea[4];
5590+
char sid[64];
55905591
};
55915592

55925593
static int
@@ -5616,13 +5617,25 @@ initializeMkdir700SecurityAttributes(
56165617
return GetLastError();
56175618
}
56185619

5620+
int use_alias = 0;
5621+
DWORD cbSid = sizeof(data->sid);
5622+
if (!CreateWellKnownSid(WinCreatorOwnerRightsSid, NULL, (PSID)data->sid, &cbSid)) {
5623+
use_alias = 1;
5624+
}
5625+
56195626
data->securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
56205627
data->ea[0].grfAccessPermissions = GENERIC_ALL;
56215628
data->ea[0].grfAccessMode = SET_ACCESS;
56225629
data->ea[0].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
5623-
data->ea[0].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
5624-
data->ea[0].Trustee.TrusteeType = TRUSTEE_IS_ALIAS;
5625-
data->ea[0].Trustee.ptstrName = L"CURRENT_USER";
5630+
if (use_alias) {
5631+
data->ea[0].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
5632+
data->ea[0].Trustee.TrusteeType = TRUSTEE_IS_ALIAS;
5633+
data->ea[0].Trustee.ptstrName = L"CURRENT_USER";
5634+
} else {
5635+
data->ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
5636+
data->ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
5637+
data->ea[0].Trustee.ptstrName = (LPWCH)(SID*)data->sid;
5638+
}
56265639

56275640
data->ea[1].grfAccessPermissions = GENERIC_ALL;
56285641
data->ea[1].grfAccessMode = SET_ACCESS;

0 commit comments

Comments
 (0)