Misc fixes.
Already sent upstream (d'oh!)

CORE-11757
ROSAPPS-303

svn path=/trunk/; revision=72090
This commit is contained in:
Pierre Schweitzer 2016-08-02 10:21:24 +00:00
parent 8cf6fe72db
commit f3851aaaab

View file

@ -62,10 +62,11 @@ typedef struct _WNetProviderTable
WNetProvider table[1]; WNetProvider table[1];
} WNetProviderTable, *PWNetProviderTable; } WNetProviderTable, *PWNetProviderTable;
#define WNET_ENUMERATOR_TYPE_NULL 0 #define WNET_ENUMERATOR_TYPE_NULL 0
#define WNET_ENUMERATOR_TYPE_GLOBAL 1 #define WNET_ENUMERATOR_TYPE_GLOBAL 1
#define WNET_ENUMERATOR_TYPE_PROVIDER 2 #define WNET_ENUMERATOR_TYPE_PROVIDER 2
#define WNET_ENUMERATOR_TYPE_CONTEXT 3 #define WNET_ENUMERATOR_TYPE_CONTEXT 3
#define WNET_ENUMERATOR_TYPE_CONNECTED 4
/* An WNet enumerator. Note that the type doesn't correspond to the scope of /* An WNet enumerator. Note that the type doesn't correspond to the scope of
* the enumeration; it represents one of the following types: * the enumeration; it represents one of the following types:
@ -1756,18 +1757,18 @@ struct use_connection_context
void *accessname; void *accessname;
DWORD *buffer_size; DWORD *buffer_size;
DWORD *result; DWORD *result;
DWORD (*pre_set_accessname)(struct use_connection_context*); DWORD (*pre_set_accessname)(struct use_connection_context*, void *);
void (*set_accessname)(struct use_connection_context*); void (*set_accessname)(struct use_connection_context*, void *);
}; };
static DWORD use_connection_pre_set_accessnameW(struct use_connection_context *ctxt) static DWORD use_connection_pre_set_accessnameW(struct use_connection_context *ctxt, void *local_name)
{ {
if (ctxt->accessname && ctxt->buffer_size && *ctxt->buffer_size) if (ctxt->accessname && ctxt->buffer_size && *ctxt->buffer_size)
{ {
DWORD len; DWORD len;
if (ctxt->resource->lpLocalName) if (local_name)
len = strlenW(ctxt->resource->lpLocalName); len = strlenW(local_name);
else else
len = strlenW(ctxt->resource->lpRemoteName); len = strlenW(ctxt->resource->lpRemoteName);
@ -1783,13 +1784,15 @@ static DWORD use_connection_pre_set_accessnameW(struct use_connection_context *c
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
static void use_connection_set_accessnameW(struct use_connection_context *ctxt) static void use_connection_set_accessnameW(struct use_connection_context *ctxt, void *local_name)
{ {
WCHAR *accessname = ctxt->accessname; WCHAR *accessname = ctxt->accessname;
if (ctxt->resource->lpLocalName) if (local_name)
strcpyW(accessname, ctxt->resource->lpLocalName); {
strcpyW(accessname, local_name);
if (ctxt->result) if (ctxt->result)
*ctxt->result = CONNECT_LOCALDRIVE; *ctxt->result = CONNECT_LOCALDRIVE;
}
else else
strcpyW(accessname, ctxt->resource->lpRemoteName); strcpyW(accessname, ctxt->resource->lpRemoteName);
} }
@ -1799,6 +1802,7 @@ static WCHAR * select_provider(struct use_connection_context *ctxt)
DWORD ret, prov_size = 0x1000, len; DWORD ret, prov_size = 0x1000, len;
LPNETRESOURCEW provider; LPNETRESOURCEW provider;
WCHAR * system; WCHAR * system;
WCHAR * provider_name;
provider = HeapAlloc(GetProcessHeap(), 0, prov_size); provider = HeapAlloc(GetProcessHeap(), 0, prov_size);
if (!provider) if (!provider)
@ -1826,13 +1830,13 @@ static WCHAR * select_provider(struct use_connection_context *ctxt)
} }
len = WideCharToMultiByte(CP_ACP, 0, provider->lpProvider, -1, NULL, 0, NULL, NULL); len = WideCharToMultiByte(CP_ACP, 0, provider->lpProvider, -1, NULL, 0, NULL, NULL);
ctxt->resource->lpProvider = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); provider_name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (ctxt->resource->lpProvider) if (provider_name)
memcpy(ctxt->resource->lpProvider, provider->lpProvider, len * sizeof(WCHAR)); memcpy(provider_name, provider->lpProvider, len * sizeof(WCHAR));
HeapFree(GetProcessHeap(), 0, provider); HeapFree(GetProcessHeap(), 0, provider);
return ctxt->resource->lpProvider; return provider_name;
} }
static DWORD wnet_use_connection( struct use_connection_context *ctxt ) static DWORD wnet_use_connection( struct use_connection_context *ctxt )
@ -1841,49 +1845,52 @@ static DWORD wnet_use_connection( struct use_connection_context *ctxt )
DWORD index, ret, caps; DWORD index, ret, caps;
BOOLEAN redirect = FALSE, prov = FALSE; BOOLEAN redirect = FALSE, prov = FALSE;
WCHAR letter[3] = {'z', ':', 0}; WCHAR letter[3] = {'z', ':', 0};
NETRESOURCEW netres;
if (!providerTable || providerTable->numProviders == 0) if (!providerTable || providerTable->numProviders == 0)
return WN_NO_NETWORK; return WN_NO_NETWORK;
if (!ctxt->resource) if (!ctxt->resource)
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
netres = *ctxt->resource;
if (!ctxt->resource->lpLocalName && (ctxt->flags & CONNECT_REDIRECT)) if (!netres.lpLocalName && (ctxt->flags & CONNECT_REDIRECT))
{ {
if (ctxt->resource->dwType != RESOURCETYPE_DISK && ctxt->resource->dwType != RESOURCETYPE_PRINT) if (netres.dwType != RESOURCETYPE_DISK && netres.dwType != RESOURCETYPE_PRINT)
{ {
return ERROR_BAD_DEV_TYPE; return ERROR_BAD_DEV_TYPE;
} }
if (ctxt->resource->dwType == RESOURCETYPE_PRINT) if (netres.dwType == RESOURCETYPE_PRINT)
{ {
FIXME("Locale device selection is not implemented for printers.\n"); FIXME("Locale device selection is not implemented for printers.\n");
return WN_NO_NETWORK; return WN_NO_NETWORK;
} }
redirect = TRUE; redirect = TRUE;
ctxt->resource->lpLocalName = letter; netres.lpLocalName = letter;
} }
if (ctxt->flags & CONNECT_INTERACTIVE) if (ctxt->flags & CONNECT_INTERACTIVE)
{ {
ret = ERROR_BAD_NET_NAME; return ERROR_BAD_NET_NAME;
goto done;
} }
if (!ctxt->resource->lpProvider) if (ctxt->flags & CONNECT_UPDATE_PROFILE)
FIXME("Connection saving is not implemented\n");
if (!netres.lpProvider)
{ {
ctxt->resource->lpProvider = select_provider(ctxt); netres.lpProvider = select_provider(ctxt);
if (!ctxt->resource->lpProvider) if (!netres.lpProvider)
{ {
ret = ERROR_NO_NET_OR_BAD_PATH; return ERROR_NO_NET_OR_BAD_PATH;
goto done;
} }
prov = TRUE; prov = TRUE;
} }
index = _findProviderIndexW(ctxt->resource->lpProvider); index = _findProviderIndexW(netres.lpProvider);
if (index == BAD_PROVIDER_INDEX) if (index == BAD_PROVIDER_INDEX)
{ {
ret = ERROR_BAD_PROVIDER; ret = ERROR_BAD_PROVIDER;
@ -1898,7 +1905,7 @@ static DWORD wnet_use_connection( struct use_connection_context *ctxt )
goto done; goto done;
} }
if ((ret = ctxt->pre_set_accessname(ctxt))) if ((ret = ctxt->pre_set_accessname(ctxt, netres.lpLocalName)))
{ {
goto done; goto done;
} }
@ -1907,26 +1914,20 @@ static DWORD wnet_use_connection( struct use_connection_context *ctxt )
do do
{ {
if ((caps & WNNC_CON_ADDCONNECTION3) && provider->addConnection3) if ((caps & WNNC_CON_ADDCONNECTION3) && provider->addConnection3)
ret = provider->addConnection3(ctxt->hwndOwner, ctxt->resource, ctxt->password, ctxt->userid, ctxt->flags); ret = provider->addConnection3(ctxt->hwndOwner, &netres, ctxt->password, ctxt->userid, ctxt->flags);
else if ((caps & WNNC_CON_ADDCONNECTION) && provider->addConnection) else if ((caps & WNNC_CON_ADDCONNECTION) && provider->addConnection)
ret = provider->addConnection(ctxt->resource, ctxt->password, ctxt->userid); ret = provider->addConnection(&netres, ctxt->password, ctxt->userid);
if (redirect) if (redirect)
letter[0] -= 1; letter[0] -= 1;
} while (redirect && ret == WN_ALREADY_CONNECTED && letter[0] >= 'c'); } while (redirect && ret == WN_ALREADY_CONNECTED && letter[0] >= 'c');
if (ret == WN_SUCCESS && ctxt->accessname) if (ret == WN_SUCCESS && ctxt->accessname)
ctxt->set_accessname(ctxt); ctxt->set_accessname(ctxt, netres.lpLocalName);
done: done:
if (prov) if (prov)
{ HeapFree(GetProcessHeap(), 0, netres.lpProvider);
HeapFree(GetProcessHeap(), 0, ctxt->resource->lpProvider);
ctxt->resource->lpProvider = NULL;
}
if (redirect)
ctxt->resource->lpLocalName = NULL;
return ret; return ret;
} }
@ -1958,14 +1959,14 @@ DWORD WINAPI WNetUseConnectionW( HWND hwndOwner, NETRESOURCEW *resource, LPCWSTR
return wnet_use_connection(&ctxt); return wnet_use_connection(&ctxt);
} }
static DWORD use_connection_pre_set_accessnameA(struct use_connection_context *ctxt) static DWORD use_connection_pre_set_accessnameA(struct use_connection_context *ctxt, void *local_name)
{ {
if (ctxt->accessname && ctxt->buffer_size && *ctxt->buffer_size) if (ctxt->accessname && ctxt->buffer_size && *ctxt->buffer_size)
{ {
DWORD len; DWORD len;
if (ctxt->resourceA->lpLocalName) if (local_name)
len = strlen(ctxt->resourceA->lpLocalName); len = strlen(local_name);
else else
len = strlen(ctxt->resourceA->lpRemoteName); len = strlen(ctxt->resourceA->lpRemoteName);
@ -1981,13 +1982,15 @@ static DWORD use_connection_pre_set_accessnameA(struct use_connection_context *c
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
static void use_connection_set_accessnameA(struct use_connection_context *ctxt) static void use_connection_set_accessnameA(struct use_connection_context *ctxt, void *local_name)
{ {
char *accessname = ctxt->accessname; char *accessname = ctxt->accessname;
if (ctxt->resourceA->lpLocalName) if (local_name)
strcpy(accessname, ctxt->resourceA->lpLocalName); {
strcpy(accessname, local_name);
if (ctxt->result) if (ctxt->result)
*ctxt->result = CONNECT_LOCALDRIVE; *ctxt->result = CONNECT_LOCALDRIVE;
}
else else
strcpy(accessname, ctxt->resourceA->lpRemoteName); strcpy(accessname, ctxt->resourceA->lpRemoteName);
} }