How can I convert a PSID type into a byte array that contains the byte value of the SID?
Something like:
PSID pSid;
byte sidBytes[68];//Max. length of SID in bytes is 68
if(GetAccountSid(
NULL, // default lookup logic
AccountName,// account to obtain SID
&pSid // buffer to allocate to contain resultant SID
)
{
ConvertPSIDToByteArray(pSid, sidBytes);
}
–how should I write the function ConvertPSIDToByteArray?
I think the function you might be looking for is ConvertSidToStringSid. The general idea is to convert the
PSIDstruct to aLPTSTRwhich is in fact of typewchar_t. You can then convert this using standard functions to a multi-byte char array using wcstombs which will then give you the SID in bytes. Alternatively, you can operate on thewchar_ttype directly and just write that out – there are functions for handling that. In either case, the result will beUTF-16 LEencoded and if you need to change from that you’ll have to do a conversion.