https://git.reactos.org/?p=reactos.git;a=commitdiff;h=11886ebec2ad98d4d9f0e…
commit 11886ebec2ad98d4d9f0e75e88bcaa355e11596d
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Mon Apr 18 09:48:03 2022 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Mon Apr 18 09:48:03 2022 +0200
[UMPNPMGR] PNP_GetRelatedDeviceInstance must return the root device as the parent of
non-existing devices
---
base/services/umpnpmgr/rpcserver.c | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/base/services/umpnpmgr/rpcserver.c b/base/services/umpnpmgr/rpcserver.c
index 470a9b67622..1262e46d661 100644
--- a/base/services/umpnpmgr/rpcserver.c
+++ b/base/services/umpnpmgr/rpcserver.c
@@ -413,6 +413,17 @@ IsRootDeviceInstanceID(
}
+static
+BOOL
+IsPresentDeviceInstanceID(
+ _In_ LPWSTR pszDeviceInstanceID)
+{
+ DWORD ulStatus, ulProblem;
+
+ return (GetDeviceStatus(pszDeviceInstanceID, &ulStatus, &ulProblem) ==
CR_SUCCESS);
+}
+
+
static
CONFIGRET
OpenConfigurationKey(
@@ -781,10 +792,29 @@ PNP_GetRelatedDeviceInstance(
if (!IsValidDeviceInstanceID(pDeviceID))
return CR_INVALID_DEVINST;
- /* The root device does not have a parent device or sibling devices */
- if ((ulRelationship == PNP_GET_PARENT_DEVICE_INSTANCE) ||
- (ulRelationship == PNP_GET_SIBLING_DEVICE_INSTANCE))
+ if (ulRelationship == PNP_GET_PARENT_DEVICE_INSTANCE)
+ {
+ /* The root device does not have a parent */
+ if (IsRootDeviceInstanceID(pDeviceID))
+ return CR_NO_SUCH_DEVINST;
+
+ /* Return the root device for non existing devices */
+ if (!IsPresentDeviceInstanceID(pDeviceID))
+ {
+ if ((wcslen(szRootDeviceInstanceID) + 1) > *pulLength)
+ {
+ *pulLength = wcslen(szRootDeviceInstanceID) + 1;
+ return CR_BUFFER_SMALL;
+ }
+
+ wcscpy(pRelatedDeviceId, szRootDeviceInstanceID);
+ *pulLength = wcslen(szRootDeviceInstanceID) + 1;
+ return CR_SUCCESS;
+ }
+ }
+ else if (ulRelationship == PNP_GET_SIBLING_DEVICE_INSTANCE)
{
+ /* The root device does not have siblings */
if (IsRootDeviceInstanceID(pDeviceID))
return CR_NO_SUCH_DEVINST;
}