Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void SetIdentifierAuthority32(SID_IDENTIFIER_AUTHORITY&sia, DWORD value)
- {
- sia.Value[5] = (BYTE)((value & 0x000000FF) >> 0);
- sia.Value[4] = (BYTE)((value & 0x0000FF00) >> 8);
- sia.Value[3] = (BYTE)((value & 0x00FF0000) >> 16);
- sia.Value[2] = (BYTE)((value & 0xFF000000) >> 24);
- sia.Value[1] = sia.Value[0] = 0;
- }
- // Based on GetBinarySid function from http://www.codeguru.com/cpp/w-p/system/security/article.php/c5659.
- BOOL MyConvertStringSidToSid(TCHAR* szSid, PSID* ppSid)
- {
- *ppSid = NULL;
- SID_IDENTIFIER_AUTHORITY identAuthority;
- BYTE nByteAuthorityCount = 0;
- DWORD dwSubAuthority[8];
- static const struct { char id0, id1; BYTE ia, sa0, sa1; } sidmap[] = {
- {'A'|32,'N'|32, (5), (7) , 0}, // NT AUTHORITY\ANONYMOUS LOGON
- {'A'|32,'U'|32, (5), (11), 0}, // NT AUTHORITY\Authenticated Users
- {'B'|32,'A'|32, (5), (32), (544)-500}, // BUILTIN\Administrators
- {'B'|32,'U'|32, (5), (32), (545)-500}, // BUILTIN\Users
- {'I'|32,'U'|32, (5), (4) , 0}, // NT AUTHORITY\INTERACTIVE
- {'S'|32,'Y'|32, (5), (18), 0}, // NT AUTHORITY\SYSTEM
- {'W'|32,'D'|32, (1), (0) , 0}, // Everyone
- };
- // Try to lookup a SID string
- for (int i = 0; i < SIZE_OF_ARRAY(sidmap); ++i)
- {
- if ((szSid[0]|32) != sidmap[i].id0 || (szSid[1]|32) != sidmap[i].id1 || szSid[2]) continue;
- SetIdentifierAuthority32(identAuthority, sidmap[i].ia);
- dwSubAuthority[nByteAuthorityCount++] = sidmap[i].sa0;
- if (sidmap[i].sa1) dwSubAuthority[nByteAuthorityCount++] = (DWORD)sidmap[i].sa1 + 500;
- goto initSid;
- }
- // S-SID_REVISION- + identifierauthority- + subauthorities- + NULL
- // Skip S
- PTSTR ptr;
- if (!(ptr = CharPos(szSid, lstrlen(szSid), TEXT('-')))) return FALSE;
- ptr++;
- // Skip SID_REVISION
- if (!(ptr = CharPos(ptr, lstrlen(ptr), TEXT('-')))) return FALSE;
- ptr++;
- // Skip identifierauthority
- PTSTR ptr1;
- if (!(ptr1 = CharPos(ptr, lstrlen(ptr), TEXT('-')))) return FALSE;
- *ptr1 = 0;
- if ((*ptr == TEXT('0')) && (*(ptr+1) == TEXT('x')))
- {
- identAuthority.Value[0] = FromHex(ptr);
- identAuthority.Value[1] = FromHex(ptr + 2);
- identAuthority.Value[2] = FromHex(ptr + 4);
- identAuthority.Value[3] = FromHex(ptr + 8);
- identAuthority.Value[4] = FromHex(ptr + 10);
- identAuthority.Value[5] = FromHex(ptr + 12);
- }
- else
- {
- SetIdentifierAuthority32(identAuthority, myatou(ptr));
- }
- // Skip -
- *ptr1 = TEXT('-'), ptr = ptr1, ptr1++;
- for (int i = 0; i < 8; i++)
- {
- // Get subauthority.
- if (!(ptr = CharPos(ptr, lstrlen(ptr), TEXT('-')))) break;
- *ptr = 0, ptr++, nByteAuthorityCount++;
- }
- for (int i = 0; i < nByteAuthorityCount; i++)
- {
- // Get subauthority.
- dwSubAuthority[i] = myatou(ptr1);
- ptr1 += lstrlen(ptr1) + 1;
- }
- initSid:
- if (!AllocateAndInitializeSid(&identAuthority,
- nByteAuthorityCount,
- dwSubAuthority[0],
- dwSubAuthority[1],
- dwSubAuthority[2],
- dwSubAuthority[3],
- dwSubAuthority[4],
- dwSubAuthority[5],
- dwSubAuthority[6],
- dwSubAuthority[7],
- ppSid))
- *ppSid = NULL;
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement