https://git.reactos.org/?p=reactos.git;a=commitdiff;h=17864b49e33d5da8f067aa...
commit 17864b49e33d5da8f067aa043d4dcb3a19e33cde Author: Eric Kohl eric.kohl@reactos.org AuthorDate: Tue Dec 31 17:59:10 2019 +0100 Commit: Eric Kohl eric.kohl@reactos.org CommitDate: Tue Dec 31 17:59:10 2019 +0100
[LSASRV] LsarLookupSids: Return proper domain information for nameless domains --- dll/win32/lsasrv/lookup.c | 76 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 6 deletions(-)
diff --git a/dll/win32/lsasrv/lookup.c b/dll/win32/lsasrv/lookup.c index 79cbffca57c..f593f2b86ae 100644 --- a/dll/win32/lsasrv/lookup.c +++ b/dll/win32/lsasrv/lookup.c @@ -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,18 +2084,31 @@ LsapLookupWellKnownSids(PLSAPR_SID_ENUM_BUFFER SidEnumBuffer,
RtlCopyMemory(NamesBuffer[i].Name.Buffer, ptr->AccountName.Buffer, ptr->AccountName.MaximumLength);
- ptr2= LsapLookupIsolatedWellKnownName(&ptr->DomainName); - if (ptr2 != NULL) + if (ptr->DomainName.Length == 0) { - Status = LsapAddDomainToDomainsList(DomainsBuffer, - &ptr2->AccountName, - ptr2->Sid, - &DomainIndex); + 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) + { + 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);