advapi32: Retrieve the current user SID from the server in lookup_user_account_name.
This commit is contained in:
parent
da3ee66505
commit
07ec73fcaa
@ -2555,30 +2555,28 @@ LookupAccountNameA(
|
|||||||
static BOOL lookup_user_account_name(PSID Sid, PDWORD cbSid, LPWSTR ReferencedDomainName,
|
static BOOL lookup_user_account_name(PSID Sid, PDWORD cbSid, LPWSTR ReferencedDomainName,
|
||||||
LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
|
LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
|
||||||
{
|
{
|
||||||
/* Default implementation: Always return a default SID */
|
char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
|
||||||
SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
|
DWORD len = sizeof(buffer);
|
||||||
|
HANDLE token;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
PSID pSid;
|
PSID pSid;
|
||||||
static const WCHAR dm[] = {'D','O','M','A','I','N',0};
|
static const WCHAR dm[] = {'D','O','M','A','I','N',0};
|
||||||
DWORD nameLen;
|
DWORD nameLen;
|
||||||
LPCWSTR domainName;
|
LPCWSTR domainName;
|
||||||
|
|
||||||
ret = AllocateAndInitializeSid(&identifierAuthority,
|
if (!OpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token))
|
||||||
2,
|
|
||||||
SECURITY_BUILTIN_DOMAIN_RID,
|
|
||||||
DOMAIN_ALIAS_RID_ADMINS,
|
|
||||||
0, 0, 0, 0, 0, 0,
|
|
||||||
&pSid);
|
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!RtlValidSid(pSid))
|
|
||||||
{
|
{
|
||||||
FreeSid(pSid);
|
if (GetLastError() != ERROR_NO_TOKEN) return FALSE;
|
||||||
return FALSE;
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token)) return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = GetTokenInformation(token, TokenUser, buffer, len, &len);
|
||||||
|
CloseHandle( token );
|
||||||
|
|
||||||
|
if (!ret) return FALSE;
|
||||||
|
|
||||||
|
pSid = ((TOKEN_USER *)buffer)->User.Sid;
|
||||||
|
|
||||||
if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
|
if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
|
||||||
CopySid(*cbSid, Sid, pSid);
|
CopySid(*cbSid, Sid, pSid);
|
||||||
if (*cbSid < GetLengthSid(pSid))
|
if (*cbSid < GetLengthSid(pSid))
|
||||||
@ -2605,8 +2603,6 @@ static BOOL lookup_user_account_name(PSID Sid, PDWORD cbSid, LPWSTR ReferencedDo
|
|||||||
if (ret)
|
if (ret)
|
||||||
*peUse = SidTypeUser;
|
*peUse = SidTypeUser;
|
||||||
|
|
||||||
FreeSid(pSid);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user