From 06f9e1220f87a5ec1a66230609c01533129846c1 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 4 Nov 2017 20:00:54 +0100 Subject: [PATCH] [SETUPAPI] CM_Open_DevNode_Key_Ex: Add support for remote registry access and the Disposition parameter. --- dll/win32/setupapi/cfgmgr.c | 58 +++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/dll/win32/setupapi/cfgmgr.c b/dll/win32/setupapi/cfgmgr.c index b45e6dec7ad..362d34e14e2 100644 --- a/dll/win32/setupapi/cfgmgr.c +++ b/dll/win32/setupapi/cfgmgr.c @@ -5002,9 +5002,10 @@ CM_Open_Class_Key_ExW( } else { - if (RegConnectRegistryW(((PMACHINE_INFO)hMachine)->szMachineName, - HKEY_LOCAL_MACHINE, &hKey)) - return CR_REGISTRY_ERROR; + if (RegConnectRegistryW(((PMACHINE_INFO)hMachine)->szMachineName, + HKEY_LOCAL_MACHINE, + &hKey)) + return CR_REGISTRY_ERROR; } if (ulFlags & CM_OPEN_CLASS_KEY_INTERFACE) @@ -5097,6 +5098,8 @@ CM_Open_DevNode_Key_Ex( HSTRING_TABLE StringTable = NULL; LPWSTR pszDevInst, pszKeyPath = NULL, pszInstancePath = NULL; LONG lError; + DWORD dwDisposition; + HKEY hRootKey = NULL; CONFIGRET ret = CR_CALL_NOT_IMPLEMENTED; FIXME("CM_Open_DevNode_Key_Ex(%lx %lx %lu %lx %p %lx %lx)\n", @@ -5138,14 +5141,14 @@ CM_Open_DevNode_Key_Ex( TRACE("pszDevInst: %S\n", pszDevInst); - pszKeyPath = MyMalloc(1024); + pszKeyPath = MyMalloc(512 * sizeof(WCHAR)); if (pszKeyPath == NULL) { ret = CR_OUT_OF_MEMORY; goto done; } - pszInstancePath = MyMalloc(1024); + pszInstancePath = MyMalloc(512 * sizeof(WCHAR)); if (pszInstancePath == NULL) { ret = CR_OUT_OF_MEMORY; @@ -5169,14 +5172,42 @@ CM_Open_DevNode_Key_Ex( TRACE("pszKeyPath: %S\n", pszKeyPath); - // FIXME: Disposition - // FIXME: hMachine + if (hMachine == NULL) + { + hRootKey = HKEY_LOCAL_MACHINE; + } + else + { + if (RegConnectRegistryW(((PMACHINE_INFO)hMachine)->szMachineName, + HKEY_LOCAL_MACHINE, + &hRootKey)) + { + ret = CR_REGISTRY_ERROR; + goto done; + } + } + + if (Disposition == RegDisposition_OpenAlways) + { + lError = RegCreateKeyExW(hRootKey, + pszKeyPath, + 0, + NULL, + 0, + samDesired, + NULL, + phkDevice, + &dwDisposition); + } + else + { + lError = RegOpenKeyExW(hRootKey, + pszKeyPath, + 0, + samDesired, + phkDevice); + } - lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, - pszKeyPath, - 0, - samDesired, - phkDevice); if (lError != ERROR_SUCCESS) { *phkDevice = NULL; @@ -5184,6 +5215,9 @@ CM_Open_DevNode_Key_Ex( } done: + if ((hRootKey != NULL) && (hRootKey != HKEY_LOCAL_MACHINE)) + RegCloseKey(hRootKey); + if (pszInstancePath != NULL) MyFree(pszInstancePath); -- 2.17.1