[MPR]
authorPierre Schweitzer <pierre@reactos.org>
Mon, 31 Oct 2016 21:20:32 +0000 (21:20 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Mon, 31 Oct 2016 21:20:32 +0000 (21:20 +0000)
Delete saved connection on disconnection if asked (even though the resource wasn't connected).
This allows net use to properly remove connections it may have created.

CORE-11757

svn path=/trunk/; revision=73092

reactos/dll/win32/mpr/mpr_ros.diff
reactos/dll/win32/mpr/wnet.c

index 230e5ed..f7cdf9d 100644 (file)
@@ -113,7 +113,45 @@ Index: wnet.c
      return ret;\r
  }\r
  \r
-@@ -2188,6 +2221,7 @@\r
+@@ -2061,6 +2094,37 @@\r
+             }\r
+         }\r
+     }\r
++#ifdef __REACTOS__\r
++\r
++    if (dwFlags & CONNECT_UPDATE_PROFILE)\r
++    {\r
++        HKEY user_profile;\r
++        WCHAR *coma = strchrW(lpName, ':');\r
++\r
++        if (coma && RegOpenCurrentUser(KEY_ALL_ACCESS, &user_profile) == ERROR_SUCCESS)\r
++        {\r
++            WCHAR  *subkey;\r
++            DWORD len;\r
++\r
++            len = (ULONG_PTR)coma - (ULONG_PTR)lpName + sizeof(L"Network\\");\r
++            subkey = HeapAlloc(GetProcessHeap(), 0, len);\r
++            if (subkey)\r
++            {\r
++                strcpyW(subkey, L"Network\\");\r
++                memcpy(subkey + (sizeof(L"Network\\") / sizeof(WCHAR)) - 1, lpName, (ULONG_PTR)coma - (ULONG_PTR)lpName);\r
++                subkey[len / sizeof(WCHAR) - 1] = 0;\r
++\r
++                TRACE("Removing: %S\n", subkey);\r
++\r
++                RegDeleteKeyW(user_profile, subkey);\r
++                HeapFree(GetProcessHeap(), 0, subkey);\r
++            }\r
++\r
++            RegCloseKey(user_profile);\r
++        }\r
++    }\r
++\r
++#endif\r
+     return ret;\r
+ }\r
\r
+@@ -2188,6 +2252,7 @@\r
  /* find the network connection for a given drive; helper for WNetGetConnection */\r
  static DWORD get_drive_connection( WCHAR letter, LPWSTR remote, LPDWORD size )\r
  {\r
@@ -121,7 +159,7 @@ Index: wnet.c
      char buffer[1024];\r
      struct mountmgr_unix_drive *data = (struct mountmgr_unix_drive *)buffer;\r
      HANDLE mgr;\r
-@@ -2230,6 +2264,32 @@\r
+@@ -2230,6 +2295,32 @@\r
      }\r
      CloseHandle( mgr );\r
      return ret;\r
index ae281e3..07c0844 100644 (file)
@@ -2094,6 +2094,37 @@ DWORD WINAPI WNetCancelConnection2W( LPCWSTR lpName, DWORD dwFlags, BOOL fForce
             }
         }
     }
+#ifdef __REACTOS__
+
+    if (dwFlags & CONNECT_UPDATE_PROFILE)
+    {
+        HKEY user_profile;
+        WCHAR *coma = strchrW(lpName, ':');
+
+        if (coma && RegOpenCurrentUser(KEY_ALL_ACCESS, &user_profile) == ERROR_SUCCESS)
+        {
+            WCHAR  *subkey;
+            DWORD len;
+
+            len = (ULONG_PTR)coma - (ULONG_PTR)lpName + sizeof(L"Network\\");
+            subkey = HeapAlloc(GetProcessHeap(), 0, len);
+            if (subkey)
+            {
+                strcpyW(subkey, L"Network\\");
+                memcpy(subkey + (sizeof(L"Network\\") / sizeof(WCHAR)) - 1, lpName, (ULONG_PTR)coma - (ULONG_PTR)lpName);
+                subkey[len / sizeof(WCHAR) - 1] = 0;
+
+                TRACE("Removing: %S\n", subkey);
+
+                RegDeleteKeyW(user_profile, subkey);
+                HeapFree(GetProcessHeap(), 0, subkey);
+            }
+
+            RegCloseKey(user_profile);
+        }
+    }
+
+#endif
     return ret;
 }