From 35a75304b795aac3f50511e61bd4cd13e2860cd6 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Mon, 4 Apr 2011 22:08:45 +0000 Subject: [PATCH] [ADVAPI32/LSASRV] - Implement LsaLookupNames2 in advapi32.dll. - Implement LsarLookupNames3 in lsasrv.dll as a mock-up which returns a hard-coded user account (Administrator). This fixes several wine tests. svn path=/trunk/; revision=51257 --- reactos/dll/win32/advapi32/sec/lsa.c | 68 +++++++++++---- reactos/dll/win32/lsasrv/lsarpc.c | 124 ++++++++++++++++++++++++++- 2 files changed, 170 insertions(+), 22 deletions(-) diff --git a/reactos/dll/win32/advapi32/sec/lsa.c b/reactos/dll/win32/advapi32/sec/lsa.c index 246fbc5ae29..ec76774bbfd 100644 --- a/reactos/dll/win32/advapi32/sec/lsa.c +++ b/reactos/dll/win32/advapi32/sec/lsa.c @@ -430,20 +430,22 @@ LsaLookupNames(IN LSA_HANDLE PolicyHandle, OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, OUT PLSA_TRANSLATED_SID *Sids) { - LSAPR_TRANSLATED_SIDS TranslatedSids; + LSAPR_TRANSLATED_SIDS TranslatedSids = {0, NULL}; ULONG MappedCount = 0; NTSTATUS Status; TRACE("(%p,0x%08x,%p,%p,%p)\n", PolicyHandle, Count, Names, ReferencedDomains, Sids); + if (ReferencedDomains == NULL || Sids == NULL) + return STATUS_INVALID_PARAMETER; + RpcTryExcept { *ReferencedDomains = NULL; *Sids = NULL; TranslatedSids.Entries = Count; - TranslatedSids.Sids = *Sids; Status = LsarLookupNames((LSAPR_HANDLE)PolicyHandle, Count, @@ -458,9 +460,7 @@ LsaLookupNames(IN LSA_HANDLE PolicyHandle, RpcExcept(EXCEPTION_EXECUTE_HANDLER) { if (TranslatedSids.Sids != NULL) - { MIDL_user_free(TranslatedSids.Sids); - } Status = I_RpcMapWin32Status(RpcExceptionCode()); } @@ -471,27 +471,56 @@ LsaLookupNames(IN LSA_HANDLE PolicyHandle, /* - * @unimplemented + * @implemented */ NTSTATUS WINAPI -LsaLookupNames2( - LSA_HANDLE PolicyHandle, - ULONG Flags, - ULONG Count, - PLSA_UNICODE_STRING Names, - PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, - PLSA_TRANSLATED_SID2 *Sids) +LsaLookupNames2(IN LSA_HANDLE PolicyHandle, + IN ULONG Flags, + IN ULONG Count, + IN PLSA_UNICODE_STRING Names, + OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, + OUT PLSA_TRANSLATED_SID2 *Sids) { - FIXME("(%p,0x%08x,0x%08x,%p,%p,%p) stub\n", PolicyHandle, Flags, - Count, Names, ReferencedDomains, Sids); - if (Names != NULL && Count > 0) + LSAPR_TRANSLATED_SIDS_EX2 TranslatedSids = {0, NULL}; + ULONG MappedCount = 0; + NTSTATUS Status; + + TRACE("(%p,0x%08x,0x%08x,%p,%p,%p) stub\n", PolicyHandle, Flags, + Count, Names, ReferencedDomains, Sids); + + if (ReferencedDomains == NULL || Sids == NULL) + return STATUS_INVALID_PARAMETER; + + RpcTryExcept { - *ReferencedDomains = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(LSA_REFERENCED_DOMAIN_LIST)); - *Sids = RtlAllocateHeap(RtlGetProcessHeap(), 0, Count * sizeof(LSA_TRANSLATED_SID2)); - return STATUS_SOME_NOT_MAPPED; + *ReferencedDomains = NULL; + *Sids = NULL; + + TranslatedSids.Entries = Count; + + Status = LsarLookupNames3((LSAPR_HANDLE)PolicyHandle, + Count, + (PRPC_UNICODE_STRING)Names, + (PLSAPR_REFERENCED_DOMAIN_LIST *)ReferencedDomains, + &TranslatedSids, + LsapLookupWksta, + &MappedCount, + Flags, + 2); + + *Sids = (PLSA_TRANSLATED_SID2)TranslatedSids.Sids; } - return STATUS_NONE_MAPPED; + RpcExcept(EXCEPTION_EXECUTE_HANDLER) + { + if (TranslatedSids.Sids != NULL) + MIDL_user_free(TranslatedSids.Sids); + + Status = I_RpcMapWin32Status(RpcExceptionCode()); + } + RpcEndExcept; + + return Status; } @@ -762,6 +791,7 @@ LsaQueryDomainInformationPolicy( return STATUS_NOT_IMPLEMENTED; } + /* * @unimplemented */ diff --git a/reactos/dll/win32/lsasrv/lsarpc.c b/reactos/dll/win32/lsasrv/lsarpc.c index 7887a7d5abf..c4c94970121 100644 --- a/reactos/dll/win32/lsasrv/lsarpc.c +++ b/reactos/dll/win32/lsasrv/lsarpc.c @@ -554,7 +554,7 @@ NTSTATUS WINAPI LsarLookupNames( for (i = 0; i < Count; i++) { OutputSids[i].Use = SidTypeWellKnownGroup; - OutputSids[i].RelativeId = DOMAIN_ALIAS_RID_ADMINS; + OutputSids[i].RelativeId = DOMAIN_USER_RID_ADMIN; //DOMAIN_ALIAS_RID_ADMINS; OutputSids[i].DomainIndex = i; } @@ -1293,8 +1293,126 @@ NTSTATUS WINAPI LsarLookupNames3( DWORD LookupOptions, DWORD ClientRevision) { - UNIMPLEMENTED; - return STATUS_NOT_IMPLEMENTED; + SID_IDENTIFIER_AUTHORITY IdentifierAuthority = {SECURITY_NT_AUTHORITY}; + static const UNICODE_STRING DomainName = RTL_CONSTANT_STRING(L"DOMAIN"); + PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer = NULL; + PLSAPR_TRANSLATED_SID_EX2 SidsBuffer = NULL; + ULONG SidsBufferLength; + ULONG DomainSidLength; + ULONG AccountSidLength; + PSID DomainSid; + PSID AccountSid; + ULONG i; + NTSTATUS Status; + + TRACE("LsarLookupNames3(%p, %lu, %p, %p, %p, %d, %p, %lu, %lu)\n", + PolicyHandle, Count, Names, ReferencedDomains, TranslatedSids, + LookupLevel, MappedCount, LookupOptions, ClientRevision); + + if (Count == 0) + return STATUS_NONE_MAPPED; + + TranslatedSids->Entries = Count; + TranslatedSids->Sids = NULL; + *ReferencedDomains = NULL; + + SidsBufferLength = Count * sizeof(LSAPR_TRANSLATED_SID_EX2); + SidsBuffer = MIDL_user_allocate(SidsBufferLength); + if (SidsBuffer == NULL) + return STATUS_INSUFFICIENT_RESOURCES; + + for (i = 0; i < Count; i++) + { + SidsBuffer[i].Use = SidTypeUser; + SidsBuffer[i].Sid = NULL; + SidsBuffer[i].DomainIndex = -1; + SidsBuffer[i].Flags = 0; + } + + DomainsBuffer = MIDL_user_allocate(sizeof(LSAPR_REFERENCED_DOMAIN_LIST)); + if (DomainsBuffer == NULL) + { + MIDL_user_free(SidsBuffer); + return STATUS_INSUFFICIENT_RESOURCES; + } + + DomainsBuffer->Entries = Count; + DomainsBuffer->Domains = MIDL_user_allocate(Count * sizeof(LSA_TRUST_INFORMATION)); + if (DomainsBuffer->Domains == NULL) + { + MIDL_user_free(DomainsBuffer); + MIDL_user_free(SidsBuffer); + return STATUS_INSUFFICIENT_RESOURCES; + } + + Status = RtlAllocateAndInitializeSid(&IdentifierAuthority, + 2, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, + 0, 0, 0, 0, 0, 0, + &DomainSid); + if (!NT_SUCCESS(Status)) + { + MIDL_user_free(DomainsBuffer->Domains); + MIDL_user_free(DomainsBuffer); + MIDL_user_free(SidsBuffer); + return Status; + } + + DomainSidLength = RtlLengthSid(DomainSid); + + for (i = 0; i < Count; i++) + { + DomainsBuffer->Domains[i].Sid = MIDL_user_allocate(DomainSidLength); + RtlCopyMemory(DomainsBuffer->Domains[i].Sid, + DomainSid, + DomainSidLength); + + DomainsBuffer->Domains[i].Name.Buffer = MIDL_user_allocate(DomainName.MaximumLength); + DomainsBuffer->Domains[i].Name.Length = DomainName.Length; + DomainsBuffer->Domains[i].Name.MaximumLength = DomainName.MaximumLength; + RtlCopyMemory(DomainsBuffer->Domains[i].Name.Buffer, + DomainName.Buffer, + DomainName.MaximumLength); + } + + Status = RtlAllocateAndInitializeSid(&IdentifierAuthority, + 3, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, + DOMAIN_USER_RID_ADMIN, + 0, 0, 0, 0, 0, + &AccountSid); + if (!NT_SUCCESS(Status)) + { + MIDL_user_free(DomainsBuffer->Domains); + MIDL_user_free(DomainsBuffer); + MIDL_user_free(SidsBuffer); + return Status; + } + + AccountSidLength = RtlLengthSid(AccountSid); + + for (i = 0; i < Count; i++) + { + SidsBuffer[i].Use = SidTypeWellKnownGroup; + SidsBuffer[i].Sid = MIDL_user_allocate(AccountSidLength); + + RtlCopyMemory(SidsBuffer[i].Sid, + AccountSid, + AccountSidLength); + + SidsBuffer[i].DomainIndex = i; + SidsBuffer[i].Flags = 0; + } + + *ReferencedDomains = DomainsBuffer; + *MappedCount = Count; + + TranslatedSids->Entries = Count; + TranslatedSids->Sids = SidsBuffer; + + return STATUS_SUCCESS; }