Author: pschweitzer
Date: Thu Aug 11 16:29:36 2016
New Revision: 72198

URL: http://svn.reactos.org/svn/reactos?rev=72198&view=rev
Log:
[MPR]
Import Wine commit:
- b452e6285915b1ad46920fc8551335ab28bfb4c0, Implement local name automatic 
redirection for disks.
- a65c31e46fa354fc8fbf86c0b9f273f86132a571, Implement provider selection given 
remote name.

CORE-11757

Modified:
    trunk/reactos/dll/win32/mpr/wnet.c

Modified: trunk/reactos/dll/win32/mpr/wnet.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/mpr/wnet.c?rev=72198&r1=72197&r2=72198&view=diff
==============================================================================
--- trunk/reactos/dll/win32/mpr/wnet.c  [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/mpr/wnet.c  [iso-8859-1] Thu Aug 11 16:29:36 2016
@@ -1798,54 +1798,38 @@
         strcpyW(accessname, ctxt->resource->lpRemoteName);
 }
 
-static WCHAR * select_provider(struct use_connection_context *ctxt)
-{
-    DWORD ret, prov_size = 0x1000, len;
-    LPNETRESOURCEW provider;
-    WCHAR * system;
-    WCHAR * provider_name;
-
-    provider = HeapAlloc(GetProcessHeap(), 0, prov_size);
-    if (!provider)
-    {
-        return NULL;
-    }
-
-    ret = WNetGetResourceInformationW(ctxt->resource, provider, &prov_size, 
&system);
-    if (ret == ERROR_MORE_DATA)
-    {
-        HeapFree(GetProcessHeap(), 0, provider);
-        provider = HeapAlloc(GetProcessHeap(), 0, prov_size);
-        if (!provider)
-        {
-            return NULL;
-        }
-
-        ret = WNetGetResourceInformationW(ctxt->resource, provider, 
&prov_size, &system);
-    }
-
-    if (ret != NO_ERROR)
-    {
-        HeapFree(GetProcessHeap(), 0, provider);
-        return NULL;
-    }
-
-    len = WideCharToMultiByte(CP_ACP, 0, provider->lpProvider, -1, NULL, 0, 
NULL, NULL);
-    provider_name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
-    if (provider_name)
-        memcpy(provider_name, provider->lpProvider, len * sizeof(WCHAR));
-
-    HeapFree(GetProcessHeap(), 0, provider);
-
-    return provider_name;
+static DWORD wnet_use_provider( struct use_connection_context *ctxt, 
NETRESOURCEW * netres, WNetProvider *provider, BOOLEAN redirect )
+{
+    DWORD caps, ret;
+
+    caps = provider->getCaps(WNNC_CONNECTION);
+    if (!(caps & (WNNC_CON_ADDCONNECTION | WNNC_CON_ADDCONNECTION3)))
+        return ERROR_BAD_PROVIDER;
+
+    ret = WN_ACCESS_DENIED;
+    do
+    {
+        if ((caps & WNNC_CON_ADDCONNECTION3) && provider->addConnection3)
+            ret = provider->addConnection3(ctxt->hwndOwner, netres, 
ctxt->password, ctxt->userid, ctxt->flags);
+        else if ((caps & WNNC_CON_ADDCONNECTION) && provider->addConnection)
+            ret = provider->addConnection(netres, ctxt->password, 
ctxt->userid);
+
+        if (ret == WN_ALREADY_CONNECTED && redirect)
+            netres->lpLocalName[0] -= 1;
+    } while (redirect && ret == WN_ALREADY_CONNECTED && netres->lpLocalName[0] 
>= 'C');
+
+    if (ret == WN_SUCCESS && ctxt->accessname)
+        ctxt->set_accessname(ctxt, netres->lpLocalName);
+
+    return ret;
 }
 
 static DWORD wnet_use_connection( struct use_connection_context *ctxt )
 {
     WNetProvider *provider;
-    DWORD index, ret, caps;
-    BOOLEAN redirect = FALSE, prov = FALSE;
-    WCHAR letter[3] = {'z', ':', 0};
+    DWORD index, ret = WN_NO_NETWORK;
+    BOOL redirect = FALSE;
+    WCHAR letter[3] = {'Z', ':', 0};
     NETRESOURCEW netres;
 
     if (!providerTable || providerTable->numProviders == 0)
@@ -1858,13 +1842,11 @@
     if (!netres.lpLocalName && (ctxt->flags & CONNECT_REDIRECT))
     {
         if (netres.dwType != RESOURCETYPE_DISK && netres.dwType != 
RESOURCETYPE_PRINT)
-        {
             return ERROR_BAD_DEV_TYPE;
-        }
 
         if (netres.dwType == RESOURCETYPE_PRINT)
         {
-            FIXME("Locale device selection is not implemented for 
printers.\n");
+            FIXME("Local device selection is not implemented for printers.\n");
             return WN_NO_NETWORK;
         }
 
@@ -1873,62 +1855,30 @@
     }
 
     if (ctxt->flags & CONNECT_INTERACTIVE)
-    {
         return ERROR_BAD_NET_NAME;
-    }
-
-    if (ctxt->flags & CONNECT_UPDATE_PROFILE)
-        FIXME("Connection saving is not implemented\n");
-
-    if (!netres.lpProvider)
-    {
-        netres.lpProvider = select_provider(ctxt);
-        if (!netres.lpProvider)
-        {
-            return ERROR_NO_NET_OR_BAD_PATH;
-        }
-
-        prov = TRUE;
-    }
-
-    index = _findProviderIndexW(netres.lpProvider);
-    if (index == BAD_PROVIDER_INDEX)
-    {
-        ret = ERROR_BAD_PROVIDER;
-        goto done;
-    }
-
-    provider = &providerTable->table[index];
-    caps = provider->getCaps(WNNC_CONNECTION);
-    if (!(caps & (WNNC_CON_ADDCONNECTION | WNNC_CON_ADDCONNECTION3)))
-    {
-        ret = ERROR_BAD_PROVIDER;
-        goto done;
-    }
 
     if ((ret = ctxt->pre_set_accessname(ctxt, netres.lpLocalName)))
-    {
-        goto done;
-    }
-
-    ret = WN_ACCESS_DENIED;
-    do
-    {
-        if ((caps & WNNC_CON_ADDCONNECTION3) && provider->addConnection3)
-            ret = provider->addConnection3(ctxt->hwndOwner, &netres, 
ctxt->password, ctxt->userid, ctxt->flags);
-        else if ((caps & WNNC_CON_ADDCONNECTION) && provider->addConnection)
-            ret = provider->addConnection(&netres, ctxt->password, 
ctxt->userid);
-
-        if (ret != NO_ERROR && redirect)
-            letter[0] -= 1;
-    } while (redirect && ret == WN_ALREADY_CONNECTED && letter[0] >= 'c');
-
-    if (ret == WN_SUCCESS && ctxt->accessname)
-        ctxt->set_accessname(ctxt, netres.lpLocalName);
-
-done:
-    if (prov)
-        HeapFree(GetProcessHeap(), 0, netres.lpProvider);
+        return ret;
+
+    if (netres.lpProvider)
+    {
+        index = _findProviderIndexW(netres.lpProvider);
+        if (index == BAD_PROVIDER_INDEX)
+            return ERROR_BAD_PROVIDER;
+
+        provider = &providerTable->table[index];
+        ret = wnet_use_provider(ctxt, &netres, provider, redirect);
+    }
+    else
+    {
+        for (index = 0; index < providerTable->numProviders; index++)
+        {
+            provider = &providerTable->table[index];
+            ret = wnet_use_provider(ctxt, &netres, provider, redirect);
+            if (ret == WN_SUCCESS || ret == WN_ALREADY_CONNECTED)
+                break;
+        }
+    }
 
     return ret;
 }


Reply via email to