Author: fireball
Date: Thu May 24 17:23:33 2007
New Revision: 26880
URL:
http://svn.reactos.org/svn/reactos?rev=26880&view=rev
Log:
- Fix wrong access-rights when referencing the object (fixes NtEnumerateKey() API).
- Add DPRINTs for problems with objects referencing.
Modified:
trunk/reactos/ntoskrnl/cm/ntfunc.c
Modified: trunk/reactos/ntoskrnl/cm/ntfunc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cm/ntfunc.c?rev=2…
==============================================================================
--- trunk/reactos/ntoskrnl/cm/ntfunc.c (original)
+++ trunk/reactos/ntoskrnl/cm/ntfunc.c Thu May 24 17:23:33 2007
@@ -726,7 +726,11 @@
ExGetPreviousMode(),
(PVOID *)&KeyObject,
NULL);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ObReferenceObjectByHandle() failed with Status = 0x%08X\n");
+ return Status;
+ }
/* Setup the callback */
PostOperationInfo.Object = (PVOID)KeyObject;
@@ -772,6 +776,128 @@
DPRINT("NtEnumerateKey() KH 0x%x, Index 0x%x, KIC %d, Length %d\n",
KeyHandle, Index, KeyInformationClass, Length);
+
+ /* Verify that the handle is valid and is a registry key */
+ Status = ObReferenceObjectByHandle(KeyHandle,
+ KEY_ENUMERATE_SUB_KEYS,
+ CmpKeyObjectType,
+ ExGetPreviousMode(),
+ (PVOID *)&KeyObject,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ObReferenceObjectByHandle() failed with Status = 0x%08X\n");
+ return Status;
+ }
+
+ /* Setup the callback */
+ PostOperationInfo.Object = (PVOID)KeyObject;
+ EnumerateKeyInfo.Object = (PVOID)KeyObject;
+ EnumerateKeyInfo.Index = Index;
+ EnumerateKeyInfo.KeyInformationClass = KeyInformationClass;
+ EnumerateKeyInfo.Length = Length;
+ EnumerateKeyInfo.ResultLength = ResultLength;
+
+ /* Do the callback */
+ Status = CmiCallRegisteredCallbacks(RegNtPreEnumerateKey, &EnumerateKeyInfo);
+ if (NT_SUCCESS(Status))
+ {
+ /* Call the internal API */
+ Status = CmEnumerateKey(KeyObject,
+ Index,
+ KeyInformationClass,
+ KeyInformation,
+ Length,
+ ResultLength);
+
+ /* Do the post callback */
+ PostOperationInfo.Status = Status;
+ CmiCallRegisteredCallbacks(RegNtPostEnumerateKey, &PostOperationInfo);
+ }
+
+ /* Dereference and return status */
+ ObDereferenceObject(KeyObject);
+ return Status;
+}
+
+NTSTATUS
+NTAPI
+NtEnumerateValueKey(IN HANDLE KeyHandle,
+ IN ULONG Index,
+ IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
+ OUT PVOID KeyValueInformation,
+ IN ULONG Length,
+ OUT PULONG ResultLength)
+{
+ NTSTATUS Status;
+ PKEY_OBJECT KeyObject;
+ REG_ENUMERATE_VALUE_KEY_INFORMATION EnumerateValueKeyInfo;
+ REG_POST_OPERATION_INFORMATION PostOperationInfo;
+ PAGED_CODE();
+
+ DPRINT("NtEnumerateValueKey() KH 0x%x, Index 0x%x, KVIC %d, Length %d\n",
+ KeyHandle, Index, KeyValueInformationClass, Length);
+
+ /* Verify that the handle is valid and is a registry key */
+ Status = ObReferenceObjectByHandle(KeyHandle,
+ KEY_QUERY_VALUE,
+ CmpKeyObjectType,
+ ExGetPreviousMode(),
+ (PVOID *)&KeyObject,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ObReferenceObjectByHandle() failed with Status = 0x%08X\n");
+ return Status;
+ }
+
+ /* Setup the callback */
+ PostOperationInfo.Object = (PVOID)KeyObject;
+ EnumerateValueKeyInfo.Object = (PVOID)KeyObject;
+ EnumerateValueKeyInfo.Index = Index;
+ EnumerateValueKeyInfo.KeyValueInformationClass = KeyValueInformationClass;
+ EnumerateValueKeyInfo.KeyValueInformation = KeyValueInformation;
+ EnumerateValueKeyInfo.Length = Length;
+ EnumerateValueKeyInfo.ResultLength = ResultLength;
+
+ /* Do the callback */
+ Status = CmiCallRegisteredCallbacks(RegNtPreEnumerateValueKey,
+ &EnumerateValueKeyInfo);
+ if (NT_SUCCESS(Status))
+ {
+ /* Call the internal API */
+ Status = CmEnumerateValueKey(KeyObject,
+ Index,
+ KeyValueInformationClass,
+ KeyValueInformation,
+ Length,
+ ResultLength);
+
+ /* Do the post callback */
+ PostOperationInfo.Status = Status;
+ CmiCallRegisteredCallbacks(RegNtPostEnumerateValueKey, &PostOperationInfo);
+ }
+
+ ObDereferenceObject(KeyObject);
+ return Status;
+}
+
+NTSTATUS
+NTAPI
+NtQueryKey(IN HANDLE KeyHandle,
+ IN KEY_INFORMATION_CLASS KeyInformationClass,
+ OUT PVOID KeyInformation,
+ IN ULONG Length,
+ OUT PULONG ResultLength)
+{
+ NTSTATUS Status;
+ PKEY_OBJECT KeyObject;
+ REG_QUERY_KEY_INFORMATION QueryKeyInfo;
+ REG_POST_OPERATION_INFORMATION PostOperationInfo;
+ PAGED_CODE();
+
+ DPRINT("NtQueryKey() KH 0x%x, KIC %d, Length %d\n",
+ KeyHandle, KeyInformationClass, Length);
/* Verify that the handle is valid and is a registry key */
Status = ObReferenceObjectByHandle(KeyHandle,
@@ -782,31 +908,34 @@
ExGetPreviousMode(),
(PVOID *)&KeyObject,
NULL);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ObReferenceObjectByHandle() failed with Status = 0x%08X\n");
+ return Status;
+ }
/* Setup the callback */
PostOperationInfo.Object = (PVOID)KeyObject;
- EnumerateKeyInfo.Object = (PVOID)KeyObject;
- EnumerateKeyInfo.Index = Index;
- EnumerateKeyInfo.KeyInformationClass = KeyInformationClass;
- EnumerateKeyInfo.Length = Length;
- EnumerateKeyInfo.ResultLength = ResultLength;
+ QueryKeyInfo.Object = (PVOID)KeyObject;
+ QueryKeyInfo.KeyInformationClass = KeyInformationClass;
+ QueryKeyInfo.KeyInformation = KeyInformation;
+ QueryKeyInfo.Length = Length;
+ QueryKeyInfo.ResultLength = ResultLength;
/* Do the callback */
- Status = CmiCallRegisteredCallbacks(RegNtPreEnumerateKey, &EnumerateKeyInfo);
+ Status = CmiCallRegisteredCallbacks(RegNtPreQueryKey, &QueryKeyInfo);
if (NT_SUCCESS(Status))
{
/* Call the internal API */
- Status = CmEnumerateKey(KeyObject,
- Index,
- KeyInformationClass,
- KeyInformation,
- Length,
- ResultLength);
+ Status = CmQueryKey(KeyObject,
+ KeyInformationClass,
+ KeyInformation,
+ Length,
+ ResultLength);
/* Do the post callback */
PostOperationInfo.Status = Status;
- CmiCallRegisteredCallbacks(RegNtPostEnumerateKey, &PostOperationInfo);
+ CmiCallRegisteredCallbacks(RegNtPostQueryKey, &PostOperationInfo);
}
/* Dereference and return status */
@@ -816,21 +945,21 @@
NTSTATUS
NTAPI
-NtEnumerateValueKey(IN HANDLE KeyHandle,
- IN ULONG Index,
- IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
- OUT PVOID KeyValueInformation,
- IN ULONG Length,
- OUT PULONG ResultLength)
+NtQueryValueKey(IN HANDLE KeyHandle,
+ IN PUNICODE_STRING ValueName,
+ IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
+ OUT PVOID KeyValueInformation,
+ IN ULONG Length,
+ OUT PULONG ResultLength)
{
NTSTATUS Status;
PKEY_OBJECT KeyObject;
- REG_ENUMERATE_VALUE_KEY_INFORMATION EnumerateValueKeyInfo;
+ REG_QUERY_VALUE_KEY_INFORMATION QueryValueKeyInfo;
REG_POST_OPERATION_INFORMATION PostOperationInfo;
PAGED_CODE();
- DPRINT("NtEnumerateValueKey() KH 0x%x, Index 0x%x, KVIC %d, Length %d\n",
- KeyHandle, Index, KeyValueInformationClass, Length);
+ DPRINT("NtQueryValueKey() KH 0x%x, VN '%wZ', KVIC %d, Length
%d\n",
+ KeyHandle, ValueName, KeyValueInformationClass, Length);
/* Verify that the handle is valid and is a registry key */
Status = ObReferenceObjectByHandle(KeyHandle,
@@ -839,122 +968,11 @@
ExGetPreviousMode(),
(PVOID *)&KeyObject,
NULL);
- if (!NT_SUCCESS(Status)) return Status;
-
- /* Setup the callback */
- PostOperationInfo.Object = (PVOID)KeyObject;
- EnumerateValueKeyInfo.Object = (PVOID)KeyObject;
- EnumerateValueKeyInfo.Index = Index;
- EnumerateValueKeyInfo.KeyValueInformationClass = KeyValueInformationClass;
- EnumerateValueKeyInfo.KeyValueInformation = KeyValueInformation;
- EnumerateValueKeyInfo.Length = Length;
- EnumerateValueKeyInfo.ResultLength = ResultLength;
-
- /* Do the callback */
- Status = CmiCallRegisteredCallbacks(RegNtPreEnumerateValueKey,
- &EnumerateValueKeyInfo);
- if (NT_SUCCESS(Status))
- {
- /* Call the internal API */
- Status = CmEnumerateValueKey(KeyObject,
- Index,
- KeyValueInformationClass,
- KeyValueInformation,
- Length,
- ResultLength);
-
- /* Do the post callback */
- PostOperationInfo.Status = Status;
- CmiCallRegisteredCallbacks(RegNtPostEnumerateValueKey, &PostOperationInfo);
- }
-
- ObDereferenceObject(KeyObject);
- return Status;
-}
-
-NTSTATUS
-NTAPI
-NtQueryKey(IN HANDLE KeyHandle,
- IN KEY_INFORMATION_CLASS KeyInformationClass,
- OUT PVOID KeyInformation,
- IN ULONG Length,
- OUT PULONG ResultLength)
-{
- NTSTATUS Status;
- PKEY_OBJECT KeyObject;
- REG_QUERY_KEY_INFORMATION QueryKeyInfo;
- REG_POST_OPERATION_INFORMATION PostOperationInfo;
- PAGED_CODE();
-
- DPRINT("NtQueryKey() KH 0x%x, KIC %d, Length %d\n",
- KeyHandle, KeyInformationClass, Length);
-
- /* Verify that the handle is valid and is a registry key */
- Status = ObReferenceObjectByHandle(KeyHandle,
- (KeyInformationClass !=
- KeyNameInformation) ?
- KEY_QUERY_VALUE : 0,
- CmpKeyObjectType,
- ExGetPreviousMode(),
- (PVOID *)&KeyObject,
- NULL);
- if (!NT_SUCCESS(Status)) return Status;
-
- /* Setup the callback */
- PostOperationInfo.Object = (PVOID)KeyObject;
- QueryKeyInfo.Object = (PVOID)KeyObject;
- QueryKeyInfo.KeyInformationClass = KeyInformationClass;
- QueryKeyInfo.KeyInformation = KeyInformation;
- QueryKeyInfo.Length = Length;
- QueryKeyInfo.ResultLength = ResultLength;
-
- /* Do the callback */
- Status = CmiCallRegisteredCallbacks(RegNtPreQueryKey, &QueryKeyInfo);
- if (NT_SUCCESS(Status))
- {
- /* Call the internal API */
- Status = CmQueryKey(KeyObject,
- KeyInformationClass,
- KeyInformation,
- Length,
- ResultLength);
-
- /* Do the post callback */
- PostOperationInfo.Status = Status;
- CmiCallRegisteredCallbacks(RegNtPostQueryKey, &PostOperationInfo);
- }
-
- /* Dereference and return status */
- ObDereferenceObject(KeyObject);
- return Status;
-}
-
-NTSTATUS
-NTAPI
-NtQueryValueKey(IN HANDLE KeyHandle,
- IN PUNICODE_STRING ValueName,
- IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
- OUT PVOID KeyValueInformation,
- IN ULONG Length,
- OUT PULONG ResultLength)
-{
- NTSTATUS Status;
- PKEY_OBJECT KeyObject;
- REG_QUERY_VALUE_KEY_INFORMATION QueryValueKeyInfo;
- REG_POST_OPERATION_INFORMATION PostOperationInfo;
- PAGED_CODE();
-
- DPRINT("NtQueryValueKey() KH 0x%x, VN '%wZ', KVIC %d, Length
%d\n",
- KeyHandle, ValueName, KeyValueInformationClass, Length);
-
- /* Verify that the handle is valid and is a registry key */
- Status = ObReferenceObjectByHandle(KeyHandle,
- KEY_QUERY_VALUE,
- CmpKeyObjectType,
- ExGetPreviousMode(),
- (PVOID *)&KeyObject,
- NULL);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ObReferenceObjectByHandle() failed with Status = 0x%08X\n");
+ return Status;
+ }
/* Setup the callback */
PostOperationInfo.Object = (PVOID)KeyObject;
@@ -981,6 +999,8 @@
CmiCallRegisteredCallbacks(RegNtPostQueryValueKey, &PostOperationInfo);
}
+ DPRINT("NtQueryValueKey() returning 0x%08X\n", Status);
+
/* Dereference and return status */
ObDereferenceObject(KeyObject);
return Status;
@@ -1011,7 +1031,11 @@
ExGetPreviousMode(),
(PVOID *)&KeyObject,
NULL);
- if (!NT_SUCCESS(Status)) return(Status);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ObReferenceObjectByHandle() failed with Status = 0x%08X\n");
+ return Status;
+ }
/* Setup callback */
PostOperationInfo.Object = (PVOID)KeyObject;
@@ -1063,7 +1087,11 @@
PreviousMode,
(PVOID *)&KeyObject,
NULL);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ObReferenceObjectByHandle() failed with Status = 0x%08X\n");
+ return Status;
+ }
/* Do the callback */
DeleteValueKeyInfo.Object = (PVOID)KeyObject;