[MPR]
authorPierre Schweitzer <pierre@reactos.org>
Mon, 15 Feb 2016 20:32:25 +0000 (20:32 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Mon, 15 Feb 2016 20:32:25 +0000 (20:32 +0000)
Import Wine commit:
d070c263adf840cc14dde84eb8e73b04490d1900, Partially implement WNetUseConnectionW().

This reduces diff to Wine, by providing a cleaner implementation of WNetUseConnectionW().

CORE-10032

svn path=/trunk/; revision=70755

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

index 4d82fe0..0460538 100644 (file)
@@ -156,84 +156,3 @@ Index: wnet.c
  }\r
  \r
  /*****************************************************************\r
-@@ -1577,12 +1659,75 @@\r
-                                  LPWSTR lpAccessName, LPDWORD lpBufferSize,\r
-                                  LPDWORD lpResult )\r
- {\r
--    FIXME( "(%p, %p, %p, %s, 0x%08X, %s, %p, %p), stub\n",\r
--           hwndOwner, lpNetResource, lpPassword, debugstr_w(lpUserID), dwFlags,\r
--           debugstr_w(lpAccessName), lpBufferSize, lpResult );\r
-+    DWORD provider;\r
-+    DWORD cap;\r
-+    char id;\r
-+    DWORD drives;\r
-+    DWORD ret;\r
-+    PF_NPAddConnection3 addConn3;\r
-+    PF_NPAddConnection addConn;\r
\r
--    SetLastError(WN_NO_NETWORK);\r
--    return WN_NO_NETWORK;\r
-+    if (!providerTable || providerTable->numProviders == 0) {\r
-+        SetLastError(WN_NO_NETWORK);\r
-+        return WN_NO_NETWORK;\r
-+    }\r
-+\r
-+    if (!lpNetResource) {\r
-+        SetLastError(ERROR_INVALID_PARAMETER);\r
-+        return ERROR_INVALID_PARAMETER;\r
-+    }\r
-+\r
-+    if (!lpNetResource->lpProvider || !*lpNetResource->lpProvider) {\r
-+        SetLastError(ERROR_BAD_PROVIDER);\r
-+        return ERROR_BAD_PROVIDER;\r
-+    }\r
-+\r
-+    if (!lpNetResource->lpLocalName || !*lpNetResource->lpLocalName) {\r
-+        SetLastError(ERROR_BAD_DEVICE);\r
-+        return ERROR_BAD_DEVICE;\r
-+    }\r
-+\r
-+    if ((!(lpNetResource->lpLocalName[0] >= 'a' && lpNetResource->lpLocalName[0] <= 'z') &&\r
-+        !(lpNetResource->lpLocalName[0] >= 'A' && lpNetResource->lpLocalName[0] <= 'Z')) ||\r
-+        lpNetResource->lpLocalName[1] != ':' || lpNetResource->lpLocalName[2]) {\r
-+        SetLastError(ERROR_BAD_DEVICE);\r
-+        return ERROR_BAD_DEVICE;\r
-+    }\r
-+\r
-+    id = (lpNetResource->lpLocalName[0] >= 'a') ? lpNetResource->lpLocalName[0] - 'a' : lpNetResource->lpLocalName[0] - 'A';\r
-+    drives = GetLogicalDrives();\r
-+    if (drives & (1 << id)) {\r
-+        SetLastError(ERROR_ALREADY_ASSIGNED);\r
-+        return ERROR_ALREADY_ASSIGNED;\r
-+    }\r
-+\r
-+    provider = _findProviderIndexW(lpNetResource->lpProvider);\r
-+    if (provider == BAD_PROVIDER_INDEX) {\r
-+        SetLastError(ERROR_BAD_PROVIDER);\r
-+        return ERROR_BAD_PROVIDER;\r
-+    }\r
-+\r
-+    cap = providerTable->table[provider].getCaps(WNNC_CONNECTION);\r
-+    if (!(cap & WNNC_CON_ADDCONNECTION) && !(cap & WNNC_CON_ADDCONNECTION3)) {\r
-+        SetLastError(ERROR_BAD_PROVIDER);\r
-+        return ERROR_BAD_PROVIDER;\r
-+    }\r
-+\r
-+    ret = WN_ACCESS_DENIED;\r
-+    if (cap & WNNC_CON_ADDCONNECTION3) {\r
-+        addConn3 = (PF_NPAddConnection3)GetProcAddress(providerTable->table[provider].hLib, "NPAddConnection3");\r
-+        if (addConn3) {\r
-+            ret = addConn3(hwndOwner, lpNetResource, (LPWSTR)lpPassword, (LPWSTR)lpUserID, dwFlags);\r
-+        }\r
-+    }\r
-+    else if (cap & WNNC_CON_ADDCONNECTION) {\r
-+        addConn = (PF_NPAddConnection)GetProcAddress(providerTable->table[provider].hLib, "NPAddConnection");\r
-+        if (addConn) {\r
-+            ret = addConn(lpNetResource, (LPWSTR)lpPassword, (LPWSTR)lpUserID);\r
-+        }\r
-+    }\r
-+\r
-+    return ret;\r
- }\r
\r
- /*********************************************************************\r
index fa96dcf..2cf1c8b 100644 (file)
@@ -1654,77 +1654,76 @@ DWORD WINAPI WNetUseConnectionA( HWND hwndOwner, LPNETRESOURCEA lpNetResource,
 /*****************************************************************
  *  WNetUseConnectionW [MPR.@]
  */
-DWORD WINAPI WNetUseConnectionW( HWND hwndOwner, LPNETRESOURCEW lpNetResource,
-                                 LPCWSTR lpPassword, LPCWSTR lpUserID, DWORD dwFlags,
-                                 LPWSTR lpAccessName, LPDWORD lpBufferSize,
-                                 LPDWORD lpResult )
+DWORD WINAPI WNetUseConnectionW( HWND hwndOwner, NETRESOURCEW *resource, LPCWSTR password,
+    LPCWSTR userid, DWORD flags, LPWSTR accessname, DWORD *buffer_size, DWORD *result )
 {
-    DWORD provider;
-    DWORD cap;
-    char id;
-    DWORD drives;
-    DWORD ret;
-    PF_NPAddConnection3 addConn3;
-    PF_NPAddConnection addConn;
+    WNetProvider *provider;
+    DWORD index, ret, caps;
 
-    if (!providerTable || providerTable->numProviders == 0) {
-        SetLastError(WN_NO_NETWORK);
+    TRACE( "(%p, %p, %p, %s, 0x%08X, %p, %p, %p)\n",
+           hwndOwner, resource, password, debugstr_w(userid), flags,
+           accessname, buffer_size, result );
+
+    if (!providerTable || providerTable->numProviders == 0)
         return WN_NO_NETWORK;
-    }
 
-    if (!lpNetResource) {
-        SetLastError(ERROR_INVALID_PARAMETER);
+    if (!resource)
         return ERROR_INVALID_PARAMETER;
-    }
 
-    if (!lpNetResource->lpProvider || !*lpNetResource->lpProvider) {
-        SetLastError(ERROR_BAD_PROVIDER);
-        return ERROR_BAD_PROVIDER;
-    }
-
-    if (!lpNetResource->lpLocalName || !*lpNetResource->lpLocalName) {
-        SetLastError(ERROR_BAD_DEVICE);
-        return ERROR_BAD_DEVICE;
+    if (!resource->lpProvider)
+    {
+        FIXME("Networking provider selection is not implemented.\n");
+        return WN_NO_NETWORK;
     }
 
-    if ((!(lpNetResource->lpLocalName[0] >= 'a' && lpNetResource->lpLocalName[0] <= 'z') &&
-        !(lpNetResource->lpLocalName[0] >= 'A' && lpNetResource->lpLocalName[0] <= 'Z')) ||
-        lpNetResource->lpLocalName[1] != ':' || lpNetResource->lpLocalName[2]) {
-        SetLastError(ERROR_BAD_DEVICE);
-        return ERROR_BAD_DEVICE;
+    if (!resource->lpLocalName && (flags & CONNECT_REDIRECT))
+    {
+        FIXME("Locale device selection is not implemented.\n");
+        return WN_NO_NETWORK;
     }
 
-    id = (lpNetResource->lpLocalName[0] >= 'a') ? lpNetResource->lpLocalName[0] - 'a' : lpNetResource->lpLocalName[0] - 'A';
-    drives = GetLogicalDrives();
-    if (drives & (1 << id)) {
-        SetLastError(ERROR_ALREADY_ASSIGNED);
-        return ERROR_ALREADY_ASSIGNED;
-    }
+    if (flags & CONNECT_INTERACTIVE)
+        return ERROR_BAD_NET_NAME;
 
-    provider = _findProviderIndexW(lpNetResource->lpProvider);
-    if (provider == BAD_PROVIDER_INDEX) {
-        SetLastError(ERROR_BAD_PROVIDER);
+    index = _findProviderIndexW(resource->lpProvider);
+    if (index == BAD_PROVIDER_INDEX)
         return ERROR_BAD_PROVIDER;
-    }
 
-    cap = providerTable->table[provider].getCaps(WNNC_CONNECTION);
-    if (!(cap & WNNC_CON_ADDCONNECTION) && !(cap & WNNC_CON_ADDCONNECTION3)) {
-        SetLastError(ERROR_BAD_PROVIDER);
+    provider = &providerTable->table[index];
+    caps = provider->getCaps(WNNC_CONNECTION);
+    if (!(caps & (WNNC_CON_ADDCONNECTION | WNNC_CON_ADDCONNECTION3)))
         return ERROR_BAD_PROVIDER;
-    }
 
-    ret = WN_ACCESS_DENIED;
-    if (cap & WNNC_CON_ADDCONNECTION3) {
-        addConn3 = (PF_NPAddConnection3)GetProcAddress(providerTable->table[provider].hLib, "NPAddConnection3");
-        if (addConn3) {
-            ret = addConn3(hwndOwner, lpNetResource, (LPWSTR)lpPassword, (LPWSTR)lpUserID, dwFlags);
+    if (accessname && buffer_size && *buffer_size)
+    {
+        DWORD len;
+
+        if (resource->lpLocalName)
+            len = strlenW(resource->lpLocalName);
+        else
+            len = strlenW(resource->lpRemoteName);
+
+        if (++len > *buffer_size)
+        {
+            *buffer_size = len;
+            return ERROR_MORE_DATA;
         }
     }
-    else if (cap & WNNC_CON_ADDCONNECTION) {
-        addConn = (PF_NPAddConnection)GetProcAddress(providerTable->table[provider].hLib, "NPAddConnection");
-        if (addConn) {
-            ret = addConn(lpNetResource, (LPWSTR)lpPassword, (LPWSTR)lpUserID);
-        }
+    else
+        accessname = NULL;
+
+    ret = WN_ACCESS_DENIED;
+    if ((caps & WNNC_CON_ADDCONNECTION3) && provider->addConnection3)
+        ret = provider->addConnection3(hwndOwner, resource, (LPWSTR)password, (LPWSTR)userid, flags);
+    else if ((caps & WNNC_CON_ADDCONNECTION) && provider->addConnection)
+        ret = provider->addConnection(resource, (LPWSTR)password, (LPWSTR)userid);
+
+    if (ret == WN_SUCCESS && accessname)
+    {
+        if (resource->lpLocalName)
+            strcpyW(accessname, resource->lpLocalName);
+        else
+            strcpyW(accessname, resource->lpRemoteName);
     }
 
     return ret;