- LsapRegQueryKeyInfo: Return the maximum sub key name length too.
- LsarEnumerateAccounts: User the maximum sub key name length to allocate a large enough buffer instead of using a fixed size one.
- LsarAddAccountRights: Use the proper value size to retrieve the system access attribute.

svn path=/trunk/; revision=72215
This commit is contained in:
Eric Kohl 2016-08-13 16:26:23 +00:00
parent caa5c5b12d
commit 3890a9cf57
3 changed files with 36 additions and 10 deletions

View file

@ -654,10 +654,11 @@ NTSTATUS WINAPI LsarEnumerateAccounts(
{ {
LSAPR_ACCOUNT_ENUM_BUFFER EnumBuffer = {0, NULL}; LSAPR_ACCOUNT_ENUM_BUFFER EnumBuffer = {0, NULL};
PLSA_DB_OBJECT PolicyObject = NULL; PLSA_DB_OBJECT PolicyObject = NULL;
WCHAR AccountKeyName[64]; PWSTR AccountKeyBuffer = NULL;
HANDLE AccountsKeyHandle = NULL; HANDLE AccountsKeyHandle = NULL;
HANDLE AccountKeyHandle; HANDLE AccountKeyHandle;
HANDLE SidKeyHandle; HANDLE SidKeyHandle;
ULONG AccountKeyBufferSize;
ULONG EnumIndex; ULONG EnumIndex;
ULONG EnumCount; ULONG EnumCount;
ULONG RequiredLength; ULONG RequiredLength;
@ -693,6 +694,23 @@ NTSTATUS WINAPI LsarEnumerateAccounts(
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
Status = LsapRegQueryKeyInfo(AccountsKeyHandle,
NULL,
&AccountKeyBufferSize,
NULL);
if (!NT_SUCCESS(Status))
{
ERR("LsapRegQueryKeyInfo returned 0x%08lx\n", Status);
return Status;
}
AccountKeyBufferSize += sizeof(WCHAR);
AccountKeyBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, AccountKeyBufferSize);
if (AccountKeyBuffer == NULL)
{
return STATUS_NO_MEMORY;
}
EnumIndex = *EnumerationContext; EnumIndex = *EnumerationContext;
EnumCount = 0; EnumCount = 0;
RequiredLength = 0; RequiredLength = 0;
@ -701,16 +719,16 @@ NTSTATUS WINAPI LsarEnumerateAccounts(
{ {
Status = LsapRegEnumerateSubKey(AccountsKeyHandle, Status = LsapRegEnumerateSubKey(AccountsKeyHandle,
EnumIndex, EnumIndex,
64 * sizeof(WCHAR), AccountKeyBufferSize,
AccountKeyName); AccountKeyBuffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
break; break;
TRACE("EnumIndex: %lu\n", EnumIndex); TRACE("EnumIndex: %lu\n", EnumIndex);
TRACE("Account key name: %S\n", AccountKeyName); TRACE("Account key name: %S\n", AccountKeyBuffer);
Status = LsapRegOpenKey(AccountsKeyHandle, Status = LsapRegOpenKey(AccountsKeyHandle,
AccountKeyName, AccountKeyBuffer,
KEY_READ, KEY_READ,
&AccountKeyHandle); &AccountKeyHandle);
TRACE("LsapRegOpenKey returned %08lX\n", Status); TRACE("LsapRegOpenKey returned %08lX\n", Status);
@ -766,16 +784,16 @@ NTSTATUS WINAPI LsarEnumerateAccounts(
{ {
Status = LsapRegEnumerateSubKey(AccountsKeyHandle, Status = LsapRegEnumerateSubKey(AccountsKeyHandle,
EnumIndex, EnumIndex,
64 * sizeof(WCHAR), AccountKeyBufferSize,
AccountKeyName); AccountKeyBuffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
break; break;
TRACE("EnumIndex: %lu\n", EnumIndex); TRACE("EnumIndex: %lu\n", EnumIndex);
TRACE("Account key name: %S\n", AccountKeyName); TRACE("Account key name: %S\n", AccountKeyBuffer);
Status = LsapRegOpenKey(AccountsKeyHandle, Status = LsapRegOpenKey(AccountsKeyHandle,
AccountKeyName, AccountKeyBuffer,
KEY_READ, KEY_READ,
&AccountKeyHandle); &AccountKeyHandle);
TRACE("LsapRegOpenKey returned %08lX\n", Status); TRACE("LsapRegOpenKey returned %08lX\n", Status);
@ -845,6 +863,9 @@ done:
} }
} }
if (AccountKeyBuffer != NULL)
RtlFreeHeap(RtlGetProcessHeap(), 0, AccountKeyBuffer);
if (AccountsKeyHandle != NULL) if (AccountsKeyHandle != NULL)
LsapRegCloseKey(AccountsKeyHandle); LsapRegCloseKey(AccountsKeyHandle);
@ -2520,7 +2541,7 @@ NTSTATUS WINAPI LsarAddAccountRights(
if (ulNewRights > 0) if (ulNewRights > 0)
{ {
Size = 0; Size = sizeof(ACCESS_MASK);
/* Get the system access flags, if the attribute exists */ /* Get the system access flags, if the attribute exists */
Status = LsapGetObjectAttribute(AccountObject, Status = LsapGetObjectAttribute(AccountObject,

View file

@ -364,6 +364,7 @@ LsapRegOpenKey(IN HANDLE ParentKeyHandle,
NTSTATUS NTSTATUS
LsapRegQueryKeyInfo(IN HANDLE KeyHandle, LsapRegQueryKeyInfo(IN HANDLE KeyHandle,
OUT PULONG SubKeyCount, OUT PULONG SubKeyCount,
OUT PULONG MaxSubKeyNameLength,
OUT PULONG ValueCount); OUT PULONG ValueCount);
NTSTATUS NTSTATUS

View file

@ -175,6 +175,7 @@ LsapRegOpenKey(IN HANDLE ParentKeyHandle,
NTSTATUS NTSTATUS
LsapRegQueryKeyInfo(IN HANDLE KeyHandle, LsapRegQueryKeyInfo(IN HANDLE KeyHandle,
OUT PULONG SubKeyCount, OUT PULONG SubKeyCount,
OUT PULONG MaxSubKeyNameLength,
OUT PULONG ValueCount) OUT PULONG ValueCount)
{ {
KEY_FULL_INFORMATION FullInfoBuffer; KEY_FULL_INFORMATION FullInfoBuffer;
@ -196,6 +197,9 @@ LsapRegQueryKeyInfo(IN HANDLE KeyHandle,
if (SubKeyCount != NULL) if (SubKeyCount != NULL)
*SubKeyCount = FullInfoBuffer.SubKeys; *SubKeyCount = FullInfoBuffer.SubKeys;
if (MaxSubKeyNameLength != NULL)
*MaxSubKeyNameLength = FullInfoBuffer.MaxNameLen;
if (ValueCount != NULL) if (ValueCount != NULL)
*ValueCount = FullInfoBuffer.Values; *ValueCount = FullInfoBuffer.Values;