[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 static BOOLEAN
LsapIsPrefixSid(IN PSID PrefixSid, LsapIsPrefixSid(IN PSID PrefixSid,
IN PSID Sid) IN PSID Sid)
@ -2033,18 +2084,31 @@ LsapLookupWellKnownSids(PLSAPR_SID_ENUM_BUFFER SidEnumBuffer,
RtlCopyMemory(NamesBuffer[i].Name.Buffer, ptr->AccountName.Buffer, ptr->AccountName.MaximumLength); RtlCopyMemory(NamesBuffer[i].Name.Buffer, ptr->AccountName.Buffer, ptr->AccountName.MaximumLength);
ptr2= LsapLookupIsolatedWellKnownName(&ptr->DomainName); if (ptr->DomainName.Length == 0)
if (ptr2 != NULL)
{ {
Status = LsapAddDomainToDomainsList(DomainsBuffer, Status = LsapAddAuthorityToDomainsList(DomainsBuffer,
&ptr2->AccountName, SidEnumBuffer->SidInfo[i].Sid,
ptr2->Sid, &DomainIndex);
&DomainIndex);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
goto done; goto done;
NamesBuffer[i].DomainIndex = DomainIndex; NamesBuffer[i].DomainIndex = DomainIndex;
} }
else
{
ptr2= LsapLookupIsolatedWellKnownName(&ptr->DomainName);
if (ptr2 != NULL)
{
Status = LsapAddDomainToDomainsList(DomainsBuffer,
&ptr2->AccountName,
ptr2->Sid,
&DomainIndex);
if (!NT_SUCCESS(Status))
goto done;
NamesBuffer[i].DomainIndex = DomainIndex;
}
}
TRACE("Mapped to: %wZ\n", &NamesBuffer[i].Name); TRACE("Mapped to: %wZ\n", &NamesBuffer[i].Name);