函数功能创建一个SID(安全描述符)
函数原型BOOL WINAPI CreateWellKnownSid( __in WELL_KNOWN_SID_TYPE WellKnownSidType, __in_opt PSID DomainSid, __out_opt PSID pSid, __inout DWORD *cbSid);
参数:
WellKnownSidType SID类型,WELL_KNOWN_SID_TYPE是枚举类型,它包含一系列的安全描述符类型
DomainSid 指向创建了SID的域的指针,为NULL时表示使用本地计算机
pSid 指向存储SID的地址
cbSid 指向存储pSid的大小的地址
返回值函数成功执行,返回非0的值;
执行失败,返回值为0。想进一步了解错误信息,执行GetLastError.
举例DWORD SidSize; PSID TheSID;LPTSTR p;SidSize = SECURITY_MAX_SID_SIZE; // Allocate enough memory for the largest possible SID. if(!(TheSID = LocalAlloc(LMEM_FIXED, SidSize))){ fprintf(stderr, "Could not allocate memory.
"); exit(1);} // Create a SID for the Everyone group on the local computer. if(!CreateWellKnownSid(WinWorldSid, NULL, TheSID, &SidSize)){ fprintf(stderr, "CreateWellKnownSid Error %u", GetLastError());}else{ // Get the string version of the SID (S-1-1-0). if(!(ConvertSidToStringSid(TheSID, &p))) { fprintf(stderr, "Error during ConvertSidToStringSid.
"); exit(1); } // Use the string SID as needed. // ... // When done, free the memory used. LocalFree(p); LocalFree(TheSID); }