windowswinapivisual-c++windows-authenticationwindows-users

ConvertStringSidToSid for S-1-5 (NT AUTHORITY group)


I have a CSid object holding a well known sid for SYSTEM. Calling Domain() function I can see that the domain is "NT AUTHORITY".

In MSDN I found out this group's SID is "S-1-5", so I tried to use ConvertStringSidToSid() in order to get a PSID for that group but I got an error that the SID structure is incorrect.

Is there a way to get CSid for that group? is it possible?

Thanks a lot! :-)


Solution

  • You need to use AllocateAndInitializeSid() function for this. See this example in MSDN.

    PSID psid;
    SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
    
    if(! AllocateAndInitializeSid( &SIDAuth, 2,
                                   SECURITY_BUILTIN_DOMAIN_RID,
                                   DOMAIN_ALIAS_RID_ADMINS,
                                   0, 0, 0, 0, 0, 0,
                                   &psid) ) 
    {
        printf( "AllocateAndInitializeSid Error %u\n", GetLastError() );
        return FALSE;
    }