<div class="content" name="LsarGetUserName" uuid="4e3f0a3f-86ae-4d50-aa40-ec25013a89e3"><p>The LsarGetUserName method returns the name and the <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_45a1c9f1-0263-49a8-97c7-7aca1a99308c" data-linktype="relative-path">domain name</a> of the <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_f3ef2572-95cf-4c5c-b3c9-551fd648f409" data-linktype="relative-path">security principal</a> that is
invoking the method.</p><dl>
<dd>
<div><pre> NTSTATUS LsarGetUserName(
   [in, unique, string] wchar_t* SystemName,
   [in, out] PRPC_UNICODE_STRING* UserName,
   [in, out, unique] PRPC_UNICODE_STRING* DomainName
 );
</pre></div>
</dd></dl><p><b>SystemName: </b>This parameter has no effect on
message processing in any environment. It MUST be ignored.</p><p><b>UserName: </b>On return, contains the name of the security
principal that is making the call. The string MUST be of the form
sAMAccountName. On input, this parameter MUST be ignored. The
RPC_UNICODE_STRING structure is defined in <a href="../ms-dtyp/cca27429-5689-4a16-b2b4-9325d93e4ba2" data-linktype="relative-path">[MS-DTYP]</a>
section <a href="../ms-dtyp/94a16bb6-c610-4cb9-8db6-26f15f560061" data-linktype="relative-path">2.3.10</a>.</p><p><b>DomainName: </b>On return, contains the domain
name of the security principal that is invoking the method. This string MUST be
a NetBIOS name. On input, this parameter MUST be ignored.</p><p><b>Return Values: </b>The following table contains a
summary of the return values that an implementation MUST return, as specified
by the message processing shown after the table.</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Return value/code</p>
   </th>
   <th>
   <p>Description</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>0x00000000 STATUS_SUCCESS</td>
  <td>The request was successfully completed.</td>
 </tr><tr>
  <td>0xC0000022 STATUS_ACCESS_DENIED</td>
  <td>The caller does not have the permissions to perform this operation.</td>
 </tr></tbody></table>
</dd></dl><p>The server MUST determine the <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_83f2020d-0804-4840-a5ac-e06439d50f8d" data-linktype="relative-path">SID</a> of the caller; to do
so, the server MUST invoke the GetRpcImpersonationAccessToken abstract
interface (<a href="../ms-rpce/290c38b1-92fe-4229-91e6-4fc376610c15" data-linktype="relative-path">[MS-RPCE]</a>
section <a href="../ms-rpce/a996aa17-8e04-4a25-806a-a3c724230e12" data-linktype="relative-path">3.3.3.4.3.1</a>).</p><p>If GetRpcImpersonationAccessToken succeeds, the server MUST
use the SID in the Token.Sids[OwnerIndex] element ([MS-DTYP] section <a href="../ms-dtyp/efc83c32-5275-4dff-a3e2-973c9624711b" data-linktype="relative-path">2.5.2</a>)
for further processing.</p><p>If GetRpcImpersonationAccessToken fails, the server MUST use
the ANONYMOUS SID ([MS-DTYP] section <a href="../ms-dtyp/81d92bba-d22b-4a8c-908a-554ab29148ab" data-linktype="relative-path">2.4.2.4</a>)
for further processing.</p><p>The server MUST locate the security principal that is making
the request using the SID that was determined previously. To do so, a search
MUST be performed in the following views and MUST end as soon as the security
principal is located in some view:</p><ul><li><p><span><span> 
</span></span>Predefined Translation View.</p>
</li><li><p><span><span> 
</span></span>Configurable Translation View.</p>
</li><li><p><span><span> 
</span></span>Account Domain View of the account database served on that
machine.</p>
<ul><li><p><span><span>  </span></span>If
the machine is not joined to a <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_b0276eb2-4e65-4cf1-a718-e0920a614aca" data-linktype="relative-path">domain</a>, the search ends
here.</p>
</li></ul></li><li><p><span><span> 
</span></span>If this machine is not a <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_76a05049-3531-4abd-aec8-30e19954b4bd" data-linktype="relative-path">domain controller</a>: Account
Domain View of the domain to which this machine is joined.</p>
</li><li><p><span><span> 
</span></span>Forest View of the <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_fd104241-4fb3-457c-b2c4-e0c18bb20b62" data-linktype="relative-path">forest</a> of the domain to
which this machine is joined.</p>
</li><li><p><span><span> 
</span></span>Forest Views of <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_3b76a71f-9697-4836-9c69-09899b23c21b" data-linktype="relative-path">trusted
forests</a> for the forest of the domain to which this machine is joined.</p>
</li><li><p><span><span> 
</span></span>Account Domain Views of externally <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_f2f00d47-6cf2-4b32-b8f7-b63e38e2e9c4" data-linktype="relative-path">trusted domains</a> for the
domain to which this machine is joined.</p>
</li></ul><p>After the security principal is located, the <a href="e79f2680-84d9-4d34-bc78-5ab9e1255653#gt_ae65dac0-cd24-4e83-a946-6d1097b71553" data-linktype="relative-path">RPC server</a> MUST return the
security principal name in the <i>UserName</i> parameter and MUST return the
domain NetBIOS name in the <i>DomainName</i> parameter if <i>DomainName</i> is
not NULL. The return value MUST be set to STATUS_SUCCESS in this case. In other
cases, an implementation-specific negative value MUST be returned.</p></div>