[LSASRV] LsarLookupSids: Return proper domain information for nameless domains

This commit is contained in:
Eric Kohl 2019-12-31 17:59:10 +01:00
parent 96692636e4
commit 17864b49e3

View file

@ -940,6 +940,57 @@ LsapAddDomainToDomainsList(PLSAPR_REFERENCED_DOMAIN_LIST ReferencedDomains,
}
static NTSTATUS
LsapAddAuthorityToDomainsList(
PLSAPR_REFERENCED_DOMAIN_LIST ReferencedDomains,
PSID Sid,
PULONG Index)
{
SID AuthoritySid;
ULONG i;
RtlInitializeSid(&AuthoritySid,
RtlIdentifierAuthoritySid(Sid),
0);
i = 0;
while (i < ReferencedDomains->Entries &&
ReferencedDomains->Domains[i].Sid != NULL)
{
if (RtlEqualSid(&AuthoritySid, ReferencedDomains->Domains[i].Sid))
{
*Index = i;
return STATUS_SUCCESS;
}
i++;
}
ReferencedDomains->Domains[i].Sid = MIDL_user_allocate(RtlLengthSid(&AuthoritySid));
if (ReferencedDomains->Domains[i].Sid == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
RtlCopySid(RtlLengthSid(&AuthoritySid), ReferencedDomains->Domains[i].Sid, &AuthoritySid);
ReferencedDomains->Domains[i].Name.Length = 0;
ReferencedDomains->Domains[i].Name.MaximumLength = sizeof(WCHAR);
ReferencedDomains->Domains[i].Name.Buffer = MIDL_user_allocate(sizeof(WCHAR));
if (ReferencedDomains->Domains[i].Name.Buffer == NULL)
{
MIDL_user_free(ReferencedDomains->Domains[i].Sid);
ReferencedDomains->Domains[i].Sid = NULL;
return STATUS_INSUFFICIENT_RESOURCES;
}
ReferencedDomains->Domains[i].Name.Buffer[0] = UNICODE_NULL;
ReferencedDomains->Entries++;
*Index = i;
return STATUS_SUCCESS;
}
static BOOLEAN
LsapIsPrefixSid(IN PSID PrefixSid,
IN PSID Sid)
@ -2033,6 +2084,18 @@ LsapLookupWellKnownSids(PLSAPR_SID_ENUM_BUFFER SidEnumBuffer,
RtlCopyMemory(NamesBuffer[i].Name.Buffer, ptr->AccountName.Buffer, ptr->AccountName.MaximumLength);
if (ptr->DomainName.Length == 0)
{
Status = LsapAddAuthorityToDomainsList(DomainsBuffer,
SidEnumBuffer->SidInfo[i].Sid,
&DomainIndex);
if (!NT_SUCCESS(Status))
goto done;
NamesBuffer[i].DomainIndex = DomainIndex;
}
else
{
ptr2= LsapLookupIsolatedWellKnownName(&ptr->DomainName);
if (ptr2 != NULL)
{
@ -2045,6 +2108,7 @@ LsapLookupWellKnownSids(PLSAPR_SID_ENUM_BUFFER SidEnumBuffer,
NamesBuffer[i].DomainIndex = DomainIndex;
}
}
TRACE("Mapped to: %wZ\n", &NamesBuffer[i].Name);