chsvlib
chsv helper source code

◆ GetSidByPrincipalName() [1/2]

AutoSID Chusov::Win32::Security::GetSidByPrincipalName ( LPCWSTR  pszPrincipalName)

Returns a smart AutoSID pointer to a security identifier of a principal, specified by its name.

Parameters
[in]pszPrincipalNameis a zero terminated wide string specifying a name of the principal. It can have a form of "<domain_name>\<principal_name>", where the domain name is optional. If the domain name is specified, the SID is looked up in the specified domain only. Otherwise, the principal is sought within the current domain.
Returns
Returns a smart unique pointer to an allocated buffer containing the SID.
Warning
In order to be able to translate built-in accounts, like "\\BUILTIN\Administrators", which can be generated by an inverse call to the GetNameByPrincipalSid function, GetSidByPrincipalName specially treats "BUILTIN" domain names (independently of case). It does not look up for such a domain (which might exist), but instead compares the principal account name taken from pszPrincipalName with names generated from SIDs of well-known built-in system accounts. If this were not been implemented, in a case of absence of a "BUILTIN" domain the underlying call to LookupAccoundName would fail.
Exceptions
Chusov::Exceptions::InvalidParameterExceptionThe specified name has invalid (or unsupported) format.
std::bad_allocThe function was unable to allocate the required amount of memory.
Chusov::Exceptions::ChsvCodeExceptionSystem-level error occurred.
See also
AutoSID GetSidByPrincipalName(LPCWSTR pszPrincipalName, std::nothrow_t) throw().
Examples
chsvwinutilex\CreateDACL.cpp.