From 4f37d9685774da5ba628a1e92f69a891553cc3e0 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 30 Dec 2018 12:55:31 +0100 Subject: [PATCH] [UMPNPMGR] PNP_GetDeviceList: Implement the enumeration of device instances for a given enumerator. --- base/services/umpnpmgr/umpnpmgr.c | 75 ++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/base/services/umpnpmgr/umpnpmgr.c b/base/services/umpnpmgr/umpnpmgr.c index bae7fdda212..56faf3be3b5 100644 --- a/base/services/umpnpmgr/umpnpmgr.c +++ b/base/services/umpnpmgr/umpnpmgr.c @@ -544,6 +544,7 @@ GetDeviceInstanceList( PWSTR pPtr; CONFIGRET ret = CR_SUCCESS; + /* Open the device key */ dwError = RegOpenKeyExW(hEnumKey, pszDevice, 0, @@ -600,6 +601,76 @@ GetDeviceInstanceList( } +CONFIGRET +GetEnumeratorInstanceList( + _In_ PWSTR pszEnumerator, + _Inout_ PWSTR pszBuffer, + _Inout_ PDWORD pulLength) +{ + WCHAR szDeviceBuffer[MAX_DEVICE_ID_LEN]; + WCHAR szPathBuffer[512]; + HKEY hEnumeratorKey; + PWSTR pPtr; + DWORD dwIndex, dwDeviceLength, dwUsedLength, dwRemainingLength, dwPathLength; + DWORD dwError; + CONFIGRET ret = CR_SUCCESS; + + /* Open the enumerator key */ + dwError = RegOpenKeyExW(hEnumKey, + pszEnumerator, + 0, + KEY_ENUMERATE_SUB_KEYS, + &hEnumeratorKey); + if (dwError != ERROR_SUCCESS) + { + DPRINT("Failed to open the enumerator key (Error %lu)\n", dwError); + return CR_REGISTRY_ERROR; + } + + dwUsedLength = 0; + dwRemainingLength = *pulLength; + pPtr = pszBuffer; + + for (dwIndex = 0; ; dwIndex++) + { + dwDeviceLength = MAX_DEVICE_ID_LEN; + dwError = RegEnumKeyExW(hEnumeratorKey, + dwIndex, + szDeviceBuffer, + &dwDeviceLength, + NULL, + NULL, + NULL, + NULL); + if (dwError != ERROR_SUCCESS) + break; + + wsprintf(szPathBuffer, L"%s\\%s", pszEnumerator, szDeviceBuffer); + DPRINT("Path: %S\n", szPathBuffer); + + dwPathLength = dwRemainingLength; + ret = GetDeviceInstanceList(szPathBuffer, + pPtr, + &dwPathLength); + if (ret != CR_SUCCESS) + break; + + dwUsedLength += dwPathLength - 1; + dwRemainingLength += dwPathLength - 1; + pPtr += dwPathLength - 1; + } + + RegCloseKey(hEnumeratorKey); + + if (ret == CR_SUCCESS) + *pulLength = dwUsedLength + 1; + else + *pulLength = 0; + + return ret; +} + + /* Function 10 */ DWORD WINAPI @@ -688,7 +759,9 @@ PNP_GetDeviceList( } else { - ret = CR_CALL_NOT_IMPLEMENTED; + ret = GetEnumeratorInstanceList(pszFilter, + Buffer, + pulLength); } } else /* CM_GETIDLIST_FILTER_NONE */ -- 2.17.1