[SETUPAPI] CM_Open_DevNode_Key_Ex: Add support for remote registry access and the...
authorEric Kohl <eric.kohl@reactos.org>
Sat, 4 Nov 2017 19:00:54 +0000 (20:00 +0100)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 4 Nov 2017 20:19:39 +0000 (21:19 +0100)
dll/win32/setupapi/cfgmgr.c

index b45e6de..362d34e 100644 (file)
@@ -5002,9 +5002,10 @@ CM_Open_Class_Key_ExW(
     }
     else
     {
     }
     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)
     }
 
     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;
     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",
     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);
 
 
     TRACE("pszDevInst: %S\n", pszDevInst);
 
-    pszKeyPath = MyMalloc(1024);
+    pszKeyPath = MyMalloc(512 * sizeof(WCHAR));
     if (pszKeyPath == NULL)
     {
         ret = CR_OUT_OF_MEMORY;
         goto done;
     }
 
     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;
     if (pszInstancePath == NULL)
     {
         ret = CR_OUT_OF_MEMORY;
@@ -5169,14 +5172,42 @@ CM_Open_DevNode_Key_Ex(
 
     TRACE("pszKeyPath: %S\n", pszKeyPath);
 
 
     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;
     if (lError != ERROR_SUCCESS)
     {
         *phkDevice = NULL;
@@ -5184,6 +5215,9 @@ CM_Open_DevNode_Key_Ex(
     }
 
 done:
     }
 
 done:
+    if ((hRootKey != NULL) && (hRootKey != HKEY_LOCAL_MACHINE))
+        RegCloseKey(hRootKey);
+
     if (pszInstancePath != NULL)
         MyFree(pszInstancePath);
 
     if (pszInstancePath != NULL)
         MyFree(pszInstancePath);