[ADVAPI32/LSASRV]

- LookupAccountNameW: Call LsaLookupNames instead of returning a dummy name.
- Implement LsaLookupNames. Calls LsarLookupNames.
- LsarLookupNames: return dummy names.

svn path=/trunk/; revision=48108
This commit is contained in:
Eric Kohl 2010-07-18 20:34:34 +00:00
parent 8091e98e96
commit 5ef81f0fae
3 changed files with 197 additions and 99 deletions

View file

@ -348,47 +348,47 @@ LsaFreeMemory(PVOID Buffer)
*/ */
NTSTATUS NTSTATUS
WINAPI WINAPI
LsaLookupNames( LsaLookupNames(IN LSA_HANDLE PolicyHandle,
LSA_HANDLE PolicyHandle, IN ULONG Count,
ULONG Count, IN PLSA_UNICODE_STRING Names,
PLSA_UNICODE_STRING Names, OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, OUT PLSA_TRANSLATED_SID *Sids)
PLSA_TRANSLATED_SID *Sids)
{ {
PLSA_TRANSLATED_SID2 Sids2; LSAPR_TRANSLATED_SIDS TranslatedSids;
LSA_TRANSLATED_SID *TranslatedSids; ULONG MappedCount = 0;
ULONG i;
NTSTATUS Status; NTSTATUS Status;
TRACE("(%p,0x%08x,%p,%p,%p)\n", PolicyHandle, Count, Names, TRACE("(%p,0x%08x,%p,%p,%p)\n", PolicyHandle, Count, Names,
ReferencedDomains, Sids); ReferencedDomains, Sids);
/* Call LsaLookupNames2, which supersedes this function */ RpcTryExcept
Status = LsaLookupNames2(PolicyHandle, Count, 0, Names, ReferencedDomains, &Sids2); {
if (!NT_SUCCESS(Status)) *ReferencedDomains = NULL;
return Status; *Sids = NULL;
/* Translate the returned structure */ TranslatedSids.Entries = Count;
TranslatedSids = RtlAllocateHeap(RtlGetProcessHeap(), 0, Count * sizeof(LSA_TRANSLATED_SID)); TranslatedSids.Sids = *Sids;
if (!TranslatedSids)
{ Status = LsarLookupNames((LSAPR_HANDLE)PolicyHandle,
LsaFreeMemory(Sids2); Count,
return SCESTATUS_NOT_ENOUGH_RESOURCE; (PRPC_UNICODE_STRING)Names,
(PLSAPR_REFERENCED_DOMAIN_LIST *)ReferencedDomains,
&TranslatedSids,
LsapLookupWksta,
&MappedCount);
*Sids = (PLSA_TRANSLATED_SID)TranslatedSids.Sids;
} }
RtlZeroMemory(Sids, Count * sizeof(PLSA_TRANSLATED_SID)); RpcExcept(EXCEPTION_EXECUTE_HANDLER)
for (i = 0; i < Count; i++)
{ {
TranslatedSids[i].Use = Sids2[i].Use; if (TranslatedSids.Sids != NULL)
if (Sids2[i].Use != SidTypeInvalid && Sids2[i].Use != SidTypeUnknown)
{ {
TranslatedSids[i].DomainIndex = Sids2[i].DomainIndex; MIDL_user_free(TranslatedSids.Sids);
if (Sids2[i].Use != SidTypeDomain)
TranslatedSids[i].RelativeId = *GetSidSubAuthority(Sids2[i].Sid, 0);
} }
}
LsaFreeMemory(Sids2);
*Sids = TranslatedSids; Status = I_RpcMapWin32Status(RpcExceptionCode());
}
RpcEndExcept;
return Status; return Status;
} }
@ -487,12 +487,11 @@ LsaLookupPrivilegeValue(IN LSA_HANDLE PolicyHandle,
*/ */
NTSTATUS NTSTATUS
WINAPI WINAPI
LsaLookupSids( LsaLookupSids(IN LSA_HANDLE PolicyHandle,
LSA_HANDLE PolicyHandle, IN ULONG Count,
ULONG Count, IN PSID *Sids,
PSID *Sids, OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, OUT PLSA_TRANSLATED_NAME *Names)
PLSA_TRANSLATED_NAME *Names)
{ {
LSAPR_SID_ENUM_BUFFER SidEnumBuffer; LSAPR_SID_ENUM_BUFFER SidEnumBuffer;
LSAPR_TRANSLATED_NAMES TranslatedNames; LSAPR_TRANSLATED_NAMES TranslatedNames;

View file

@ -1177,7 +1177,7 @@ LookupAccountNameA(LPCSTR SystemName,
/****************************************************************************** /******************************************************************************
* LookupAccountNameW [ADVAPI32.@] * LookupAccountNameW [ADVAPI32.@]
* *
* @unimplemented * @implemented
*/ */
BOOL BOOL
WINAPI WINAPI
@ -1189,78 +1189,94 @@ LookupAccountNameW(LPCWSTR lpSystemName,
LPDWORD cchReferencedDomainName, LPDWORD cchReferencedDomainName,
PSID_NAME_USE peUse) PSID_NAME_USE peUse)
{ {
/* Default implementation: Always return a default SID */ OBJECT_ATTRIBUTES ObjectAttributes = {0};
SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY}; UNICODE_STRING SystemName;
BOOL ret; UNICODE_STRING AccountName;
PSID pSid; LSA_HANDLE PolicyHandle = NULL;
static const WCHAR dm[] = {'D','O','M','A','I','N',0}; PLSA_REFERENCED_DOMAIN_LIST ReferencedDomains = NULL;
unsigned int i; PLSA_TRANSLATED_SID TranslatedSid = NULL;
PSID pDomainSid;
DWORD dwDomainNameLength;
DWORD dwSidLength;
UCHAR nSubAuthorities;
BOOL bResult;
NTSTATUS Status;
TRACE("%s %s %p %p %p %p %p - stub\n", lpSystemName, lpAccountName, TRACE("%s %s %p %p %p %p %p\n", lpSystemName, lpAccountName,
Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse); Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
if (!ADVAPI_IsLocalComputer(lpSystemName)) RtlInitUnicodeString(&SystemName,
lpSystemName);
Status = LsaOpenPolicy(lpSystemName ? &SystemName : NULL,
&ObjectAttributes,
POLICY_LOOKUP_NAMES,
&PolicyHandle);
if (!NT_SUCCESS(Status))
{ {
SetLastError(RPC_S_SERVER_UNAVAILABLE); SetLastError(LsaNtStatusToWinError(Status));
return FALSE; return FALSE;
} }
for (i = 0; i < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); i++) RtlInitUnicodeString(&AccountName,
lpAccountName);
Status = LsaLookupNames(PolicyHandle,
1,
&AccountName,
&ReferencedDomains,
&TranslatedSid);
LsaClose(PolicyHandle);
if (!NT_SUCCESS(Status) || Status == STATUS_SOME_NOT_MAPPED)
{ {
if (!wcscmp(lpAccountName, ACCOUNT_SIDS[i].account)) SetLastError(LsaNtStatusToWinError(Status));
{ bResult = FALSE;
if (*cchReferencedDomainName)
*ReferencedDomainName = '\0';
*cchReferencedDomainName = 0;
*peUse = SidTypeWellKnownGroup;
return CreateWellKnownSid(ACCOUNT_SIDS[i].type, NULL, Sid, cbSid);
}
}
ret = AllocateAndInitializeSid(&identifierAuthority,
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);
return FALSE;
}
if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
CopySid(*cbSid, Sid, pSid);
if (*cbSid < GetLengthSid(pSid))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
ret = FALSE;
}
*cbSid = GetLengthSid(pSid);
if (ReferencedDomainName != NULL && (*cchReferencedDomainName > wcslen(dm)))
wcscpy(ReferencedDomainName, dm);
if ((*cchReferencedDomainName <= wcslen(dm)) || (!ret))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
ret = FALSE;
*cchReferencedDomainName = wcslen(dm) + 1;
} }
else else
{ {
*cchReferencedDomainName = wcslen(dm); pDomainSid = ReferencedDomains->Domains[TranslatedSid->DomainIndex].Sid;
nSubAuthorities = *GetSidSubAuthorityCount(pDomainSid);
dwSidLength = GetSidLengthRequired(nSubAuthorities + 1);
dwDomainNameLength = ReferencedDomains->Domains->Name.Length / sizeof(WCHAR);
if (*cbSid < dwSidLength ||
*cchReferencedDomainName < dwDomainNameLength + 1)
{
*cbSid = dwSidLength;
*cchReferencedDomainName = dwDomainNameLength + 1;
bResult = FALSE;
}
else
{
CopySid(*cbSid, Sid, pDomainSid);
*GetSidSubAuthorityCount(Sid) = nSubAuthorities + 1;
*GetSidSubAuthority(Sid, (DWORD)nSubAuthorities) = TranslatedSid->RelativeId;
RtlCopyMemory(ReferencedDomainName, ReferencedDomains->Domains->Name.Buffer, dwDomainNameLength * sizeof(WCHAR));
ReferencedDomainName[dwDomainNameLength] = L'\0';
*cchReferencedDomainName = dwDomainNameLength;
*peUse = TranslatedSid->Use;
bResult = TRUE;
}
if (bResult == FALSE)
SetLastError(ERROR_INSUFFICIENT_BUFFER);
} }
FreeSid(pSid); if (ReferencedDomains != NULL)
LsaFreeMemory(ReferencedDomains);
return ret; if (TranslatedSid != NULL)
LsaFreeMemory(TranslatedSid);
return bResult;
} }
@ -1499,11 +1515,11 @@ LookupPrivilegeNameW(LPCWSTR lpSystemName,
&PrivilegeName); &PrivilegeName);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
if (PrivilegeName->Length + sizeof(WCHAR) > (*cchName) * sizeof(WCHAR)) if (PrivilegeName->Length + sizeof(WCHAR) > *cchName * sizeof(WCHAR))
{ {
Status = STATUS_BUFFER_TOO_SMALL; Status = STATUS_BUFFER_TOO_SMALL;
(*cchName) = (PrivilegeName->Length + sizeof(WCHAR)) / sizeof(WCHAR); *cchName = (PrivilegeName->Length + sizeof(WCHAR)) / sizeof(WCHAR);
} }
else else
{ {
@ -1512,7 +1528,7 @@ LookupPrivilegeNameW(LPCWSTR lpSystemName,
PrivilegeName->Length); PrivilegeName->Length);
lpName[PrivilegeName->Length / sizeof(WCHAR)] = 0; lpName[PrivilegeName->Length / sizeof(WCHAR)] = 0;
(*cchName) = PrivilegeName->Length / sizeof(WCHAR); *cchName = PrivilegeName->Length / sizeof(WCHAR);
} }
LsaFreeMemory(PrivilegeName->Buffer); LsaFreeMemory(PrivilegeName->Buffer);

View file

@ -333,8 +333,91 @@ NTSTATUS LsarLookupNames(
LSAP_LOOKUP_LEVEL LookupLevel, LSAP_LOOKUP_LEVEL LookupLevel,
DWORD *MappedCount) DWORD *MappedCount)
{ {
UNIMPLEMENTED; SID_IDENTIFIER_AUTHORITY IdentifierAuthority = {SECURITY_NT_AUTHORITY};
return STATUS_NOT_IMPLEMENTED; static const UNICODE_STRING DomainName = RTL_CONSTANT_STRING(L"DOMAIN");
PLSAPR_REFERENCED_DOMAIN_LIST OutputDomains = NULL;
PLSA_TRANSLATED_SID OutputSids = NULL;
ULONG OutputSidsLength;
ULONG i;
PSID Sid;
ULONG SidLength;
NTSTATUS Status;
TRACE("LsarLookupNames(%p, %lu, %p, %p, %p, %d, %p)\n",
PolicyHandle, Count, Names, ReferencedDomains, TranslatedSids,
LookupLevel, MappedCount);
TranslatedSids->Entries = Count;
TranslatedSids->Sids = NULL;
*ReferencedDomains = NULL;
OutputSidsLength = Count * sizeof(LSA_TRANSLATED_SID);
OutputSids = MIDL_user_allocate(OutputSidsLength);
if (OutputSids == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(OutputSids, OutputSidsLength);
OutputDomains = MIDL_user_allocate(sizeof(LSAPR_REFERENCED_DOMAIN_LIST));
if (OutputDomains == NULL)
{
MIDL_user_free(OutputSids);
return STATUS_INSUFFICIENT_RESOURCES;
}
OutputDomains->Entries = Count;
OutputDomains->Domains = MIDL_user_allocate(Count * sizeof(LSA_TRUST_INFORMATION));
if (OutputDomains->Domains == NULL)
{
MIDL_user_free(OutputDomains);
MIDL_user_free(OutputSids);
return STATUS_INSUFFICIENT_RESOURCES;
}
Status = RtlAllocateAndInitializeSid(&IdentifierAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&Sid);
if (!NT_SUCCESS(Status))
{
MIDL_user_free(OutputDomains->Domains);
MIDL_user_free(OutputDomains);
MIDL_user_free(OutputSids);
return Status;
}
SidLength = RtlLengthSid(Sid);
for (i = 0; i < Count; i++)
{
OutputDomains->Domains[i].Sid = MIDL_user_allocate(SidLength);
RtlCopyMemory(OutputDomains->Domains[i].Sid, Sid, SidLength);
OutputDomains->Domains[i].Name.Buffer = MIDL_user_allocate(DomainName.MaximumLength);
OutputDomains->Domains[i].Name.Length = DomainName.Length;
OutputDomains->Domains[i].Name.MaximumLength = DomainName.MaximumLength;
RtlCopyMemory(OutputDomains->Domains[i].Name.Buffer, DomainName.Buffer, DomainName.MaximumLength);
}
for (i = 0; i < Count; i++)
{
OutputSids[i].Use = SidTypeWellKnownGroup;
OutputSids[i].RelativeId = DOMAIN_ALIAS_RID_ADMINS;
OutputSids[i].DomainIndex = i;
}
*ReferencedDomains = OutputDomains;
*MappedCount = Count;
TranslatedSids->Entries = Count;
TranslatedSids->Sids = OutputSids;
return STATUS_SUCCESS;
} }