WindowsApi:CreateDirectory
새로운 디렉터리 생성.
Remarks
SECURITY_ATTRIBUTES형의 변수가 들어가는데, NULL 이면 부모 폴더의 값을 그대로 가져온다.
All access permission
CreateDirectory
함수에서 SECURITY_ATTRIBUTES 값을 가지고 폴더에 모든 ACCESS 권한을 주는 예제이다.
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
PSID pEveryoneSID = NULL;
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
EXPLICIT_ACCESS ea[2];
PACL pacl = NULL;
if(!AllocateAndInitializeSid(&SIDAuthWorld,1, SECURITY_WORLD_RID,0,0,0,0,0,0,0,&pEveryoneSID))
{
AfxMessageBox("Fail to get Everyone SID!!!",0,0);
return;
}
ZeroMemory(&ea, 2*sizeof(EXPLICIT_ACCESS));
ea[0].grfAccessPermissions = GENERIC_ALL;
ea[0].grfAccessMode = SET_ACCESS;
ea[0].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName = (LPTSTR) pEveryoneSID;
SetEntriesInAcl(1,ea, NULL, &pacl);
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE,pacl , FALSE);
//SetSecurityDescriptorSacl(&sd, TRUE,pacl , FALSE);
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = TRUE;
::CreateDirectory(sysDirBuffer_tmp,&sa);
if(pEveryoneSID){
FreeSid(pEveryoneSID);
}
if(pacl){
LocalFree(pacl);
}