RtlConvertSidToUnicodeString - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTRTL_H

NTSYSAPI
NTSTATUS
NTAPI
RtlConvertSidToUnicodeString(
    _Inout_ PUNICODE_STRING UnicodeString,
    _In_ PSID Sid,
    _In_ BOOLEAN AllocateDestinationString
    );

#endif

View code on GitHub
// ntifs.h

NTSYSAPI NTSTATUS RtlConvertSidToUnicodeString(
  [in, out] PUNICODE_STRING UnicodeString,
  [in]      PSID            Sid,
  [in]      BOOLEAN         AllocateDestinationString
);
View the official Windows Driver Kit DDI reference
// winternl.h

NTSTATUS RtlConvertSidToUnicodeString(
  [out] PUNICODE_STRING UnicodeString,
  [in]  PSID            Sid,
  [in]  BOOLEAN         AllocateDestinationString
);
View the official Win32 API reference

NtDoc

This function is documented in Windows Driver Kit.

Windows Driver Kit DDI reference (nf-ntifs-rtlconvertsidtounicodestring)

RtlConvertSidToUnicodeString function

Description

The RtlConvertSidToUnicodeString routine generates a printable Unicode string representation of a security identifier (SID).

Parameters

UnicodeString [in, out]

A pointer to a UNICODE_STRING structure to contain the generated Unicode string. The UnicodeString->MaximumLength member is set only if AllocateDestinationString is TRUE.

Sid [in]

A pointer to the SID structure that is to be converted to Unicode (the SID structure is unaffected).

AllocateDestinationString [in]

A Boolean flag that indicates whether this routine will allocate the UnicodeString buffer. If TRUE, only the UnicodeString->Buffer member is allocated and the rest of the UnicodeString structure must be allocated by the caller.

Return value

The RtlConvertSidToUnicodeString routine can return one of the following values:

Return code Description
STATUS_SUCCESS The conversion was successful.
STATUS_BUFFER_OVERFLOW This is returned if AllocateDestinationString is FALSE and the caller supplied UnicodeString buffer is too small to hold the converted Unicode string.
STATUS_NO_MEMORY This is returned if AllocateDestinationString is TRUE and there is insufficient memory to allocate the UnicodeString buffer.
STATUS_INVALID_SID The specified SID structure is not structurally valid.

Remarks

The generated Unicode string will take one of two forms. If the value of the IdentifierAuthority member of the SID is less than or equal to 2^32, the IdentifierAuthority member will be generated as decimal. For example, a SID with an IdentifierAuthority of 281,736 generates:

 S-1-281736-12-72-9-110

Otherwise the IdentifierAuthority will be generated as hexadecimal. For example, a SID with an IdentifierAuthority of 173,495,281,736 generates:

 S-1-0x28651FE848-12-72-9-110

All other members in the SID will be generated as decimal.

If AllocateDestinationString is TRUE, the allocated buffer must be deallocated by using RtlFreeUnicodeString.

See also

RtlFreeUnicodeString

SID

UNICODE_STRING


Win32 API reference (nf-winternl-rtlconvertsidtounicodestring)

RtlConvertSidToUnicodeString function

Description

[The RtlConvertSidToUnicodeString function is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, use the ConvertSidToStringSid function.]

The RtlConvertSidToUnicodeString function converts a security identifier (SID) to its Unicode character representation. This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Ntdll.dll.

Parameters

UnicodeString [out]

A pointer to the Unicode character representation of the security identifier.

Sid [in]

A pointer to the SID structure that represents the security identifier.

AllocateDestinationString [in]

If TRUE, then UnicodeString is allocated on behalf of the caller, and it is the caller's responsibility to free the allocated memory by calling the RtlFreeUnicodeString function. If FALSE, the caller is responsible for allocating and freeing UnicodeString.

Return value

The return value is an NTSTATUS code. A value of STATUS_SUCCESS (0x00000000L) is returned if the function succeeds.