NTSTATUS
RtlAllocateAndInitializeSid(
  IN  PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
  IN  UCHAR SubAuthorityCount,
  IN  ULONG SubAuthority0,
  IN  ULONG SubAuthority1,
  IN  ULONG SubAuthority2,
  IN  ULONG SubAuthority3,
  IN  ULONG SubAuthority4,
  IN  ULONG SubAuthority5,
  IN  ULONG SubAuthority6,
  IN  ULONG SubAuthority7,
  OUT PSID *Sid
  );

Routine Description:

    This function allocates and initializes a sid with the specified
    number of sub-authorities (up to 8).  A sid allocated with this
    routine must be freed using RtlFreeSid().

    THIS ROUTINE IS CURRENTLY NOT CALLABLE FROM KERNEL MODE.

Arguments:

    IdentifierAuthority - Pointer to the Identifier Authority value to
        set in the SID.

    SubAuthorityCount - The number of sub-authorities to place in the SID.
        This also identifies how many of the SubAuthorityN parameters
        have meaningful values.  This must contain a value from 0 through
        8.

    SubAuthority0-7 - Provides the corresponding sub-authority value to
        place in the SID.  For example, a SubAuthorityCount value of 3
        indicates that SubAuthority0, SubAuthority1, and SubAuthority0
        have meaningful values and the rest are to be ignored.

    Sid - Receives a pointer to the SID data structure to initialize.

Return Value:

    STATUS_SUCCESS - The SID has been allocated and initialized.

    STATUS_NO_MEMORY - The attempt to allocate memory for the SID
        failed.

    STATUS_INVALID_SID - The number of sub-authorities specified did
        not fall in the valid range for this api (0 through 8).