4 * Copyright 1999 Ulrich Weigand
5 * Copyright 2004 Juan Lang
6 * Copyright 2007 Maarten Lankhorst
7 * Copyright 2016 Pierre Schweitzer
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #define WINE_MOUNTMGR_EXTENSIONS
34 #include "ddk/mountmgr.h"
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mpr
);
42 /* Data structures representing network service providers. Assumes only one
43 * thread creates them, and that they are constant for the life of the process
44 * (and therefore doesn't synchronize access).
45 * FIXME: only basic provider data and enumeration-related data are implemented
46 * so far, need to implement the rest too.
48 typedef struct _WNetProvider
56 PF_NPOpenEnum openEnum
;
57 PF_NPEnumResource enumResource
;
58 PF_NPCloseEnum closeEnum
;
59 PF_NPGetResourceInformation getResourceInformation
;
60 PF_NPAddConnection addConnection
;
61 PF_NPAddConnection3 addConnection3
;
62 PF_NPCancelConnection cancelConnection
;
63 } WNetProvider
, *PWNetProvider
;
65 typedef struct _WNetProviderTable
70 WNetProvider table
[1];
71 } WNetProviderTable
, *PWNetProviderTable
;
73 #define WNET_ENUMERATOR_TYPE_NULL 0
74 #define WNET_ENUMERATOR_TYPE_GLOBAL 1
75 #define WNET_ENUMERATOR_TYPE_PROVIDER 2
76 #define WNET_ENUMERATOR_TYPE_CONTEXT 3
77 #define WNET_ENUMERATOR_TYPE_CONNECTED 4
79 /* An WNet enumerator. Note that the type doesn't correspond to the scope of
80 * the enumeration; it represents one of the following types:
81 * - a 'null' enumeration, one that contains no members
82 * - a global enumeration, one that's executed across all providers
83 * - a provider-specific enumeration, one that's only executed by a single
85 * - a context enumeration. I know this contradicts what I just said about
86 * there being no correspondence between the scope and the type, but it's
87 * necessary for the special case that a "Entire Network" entry needs to
88 * be enumerated in an enumeration of the context scope. Thus an enumeration
89 * of the context scope results in a context type enumerator, which morphs
90 * into a global enumeration (so the enumeration continues across all
93 typedef struct _WNetEnumerator
107 } WNetEnumerator
, *PWNetEnumerator
;
109 #define BAD_PROVIDER_INDEX (DWORD)0xffffffff
111 /* Returns an index (into the global WNetProviderTable) of the provider with
112 * the given name, or BAD_PROVIDER_INDEX if not found.
114 static DWORD
_findProviderIndexW(LPCWSTR lpProvider
);
116 static PWNetProviderTable providerTable
;
119 * Global provider table functions
122 static void _tryLoadProvider(PCWSTR provider
)
124 static const WCHAR servicePrefix
[] = { 'S','y','s','t','e','m','\\',
125 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
126 'S','e','r','v','i','c','e','s','\\',0 };
127 static const WCHAR serviceFmt
[] = { '%','s','%','s','\\',
128 'N','e','t','w','o','r','k','P','r','o','v','i','d','e','r',0 };
129 WCHAR serviceName
[MAX_PATH
];
132 TRACE("%s\n", debugstr_w(provider
));
133 snprintfW(serviceName
, sizeof(serviceName
) / sizeof(WCHAR
), serviceFmt
,
134 servicePrefix
, provider
);
135 serviceName
[sizeof(serviceName
) / sizeof(WCHAR
) - 1] = '\0';
136 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, serviceName
, 0, KEY_READ
, &hKey
) ==
139 static const WCHAR szProviderPath
[] = { 'P','r','o','v','i','d','e','r',
141 WCHAR providerPath
[MAX_PATH
];
142 DWORD type
, size
= sizeof(providerPath
);
144 if (RegQueryValueExW(hKey
, szProviderPath
, NULL
, &type
,
145 (LPBYTE
)providerPath
, &size
) == ERROR_SUCCESS
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
))
147 static const WCHAR szProviderName
[] = { 'N','a','m','e',0 };
150 if (type
== REG_EXPAND_SZ
)
152 WCHAR path
[MAX_PATH
];
153 if (ExpandEnvironmentStringsW(providerPath
, path
, MAX_PATH
)) lstrcpyW( providerPath
, path
);
157 RegQueryValueExW(hKey
, szProviderName
, NULL
, NULL
, NULL
, &size
);
160 name
= HeapAlloc(GetProcessHeap(), 0, size
);
161 if (RegQueryValueExW(hKey
, szProviderName
, NULL
, &type
,
162 (LPBYTE
)name
, &size
) != ERROR_SUCCESS
|| type
!= REG_SZ
)
164 HeapFree(GetProcessHeap(), 0, name
);
170 HMODULE hLib
= LoadLibraryW(providerPath
);
174 #define MPR_GETPROC(proc) ((PF_##proc)GetProcAddress(hLib, #proc))
176 PF_NPGetCaps getCaps
= MPR_GETPROC(NPGetCaps
);
178 TRACE("loaded lib %p\n", hLib
);
181 PWNetProvider provider
=
182 &providerTable
->table
[providerTable
->numProviders
];
184 provider
->hLib
= hLib
;
185 provider
->name
= name
;
186 TRACE("name is %s\n", debugstr_w(name
));
187 provider
->getCaps
= getCaps
;
188 provider
->dwSpecVersion
= getCaps(WNNC_SPEC_VERSION
);
189 provider
->dwNetType
= getCaps(WNNC_NET_TYPE
);
190 TRACE("net type is 0x%08x\n", provider
->dwNetType
);
191 provider
->dwEnumScopes
= getCaps(WNNC_ENUMERATION
);
192 if (provider
->dwEnumScopes
)
194 TRACE("supports enumeration\n");
195 provider
->openEnum
= MPR_GETPROC(NPOpenEnum
);
196 TRACE("NPOpenEnum %p\n", provider
->openEnum
);
197 provider
->enumResource
= MPR_GETPROC(NPEnumResource
);
198 TRACE("NPEnumResource %p\n", provider
->enumResource
);
199 provider
->closeEnum
= MPR_GETPROC(NPCloseEnum
);
200 TRACE("NPCloseEnum %p\n", provider
->closeEnum
);
201 provider
->getResourceInformation
= MPR_GETPROC(NPGetResourceInformation
);
202 TRACE("NPGetResourceInformation %p\n", provider
->getResourceInformation
);
203 if (!provider
->openEnum
||
204 !provider
->enumResource
||
205 !provider
->closeEnum
)
207 provider
->openEnum
= NULL
;
208 provider
->enumResource
= NULL
;
209 provider
->closeEnum
= NULL
;
210 provider
->dwEnumScopes
= 0;
211 WARN("Couldn't load enumeration functions\n");
214 provider
->addConnection
= MPR_GETPROC(NPAddConnection
);
215 provider
->addConnection3
= MPR_GETPROC(NPAddConnection3
);
216 provider
->cancelConnection
= MPR_GETPROC(NPCancelConnection
);
217 TRACE("NPAddConnection %p\n", provider
->addConnection
);
218 TRACE("NPAddConnection3 %p\n", provider
->addConnection3
);
219 TRACE("NPCancelConnection %p\n", provider
->cancelConnection
);
220 providerTable
->numProviders
++;
224 WARN("Provider %s didn't export NPGetCaps\n",
225 debugstr_w(provider
));
226 HeapFree(GetProcessHeap(), 0, name
);
234 WARN("Couldn't load library %s for provider %s\n",
235 debugstr_w(providerPath
), debugstr_w(provider
));
236 HeapFree(GetProcessHeap(), 0, name
);
241 WARN("Couldn't get provider name for provider %s\n",
242 debugstr_w(provider
));
246 WARN("Couldn't open value %s\n", debugstr_w(szProviderPath
));
250 WARN("Couldn't open service key for provider %s\n",
251 debugstr_w(provider
));
254 void wnetInit(HINSTANCE hInstDll
)
256 static const WCHAR providerOrderKey
[] = { 'S','y','s','t','e','m','\\',
257 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
258 'C','o','n','t','r','o','l','\\',
259 'N','e','t','w','o','r','k','P','r','o','v','i','d','e','r','\\',
260 'O','r','d','e','r',0 };
261 static const WCHAR providerOrder
[] = { 'P','r','o','v','i','d','e','r',
262 'O','r','d','e','r',0 };
265 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, providerOrderKey
, 0, KEY_READ
, &hKey
)
270 RegQueryValueExW(hKey
, providerOrder
, NULL
, NULL
, NULL
, &size
);
273 PWSTR providers
= HeapAlloc(GetProcessHeap(), 0, size
);
279 if (RegQueryValueExW(hKey
, providerOrder
, NULL
, &type
,
280 (LPBYTE
)providers
, &size
) == ERROR_SUCCESS
&& type
== REG_SZ
)
285 TRACE("provider order is %s\n", debugstr_w(providers
));
286 /* first count commas as a heuristic for how many to
287 * allocate space for */
288 for (ptr
= providers
, numToAllocate
= 1; ptr
; )
290 ptr
= strchrW(ptr
, ',');
297 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
298 sizeof(WNetProviderTable
)
299 + (numToAllocate
- 1) * sizeof(WNetProvider
));
303 int entireNetworkLen
;
304 LPCWSTR stringresource
;
306 entireNetworkLen
= LoadStringW(hInstDll
,
307 IDS_ENTIRENETWORK
, (LPWSTR
)&stringresource
, 0);
308 providerTable
->entireNetwork
= HeapAlloc(
309 GetProcessHeap(), 0, (entireNetworkLen
+ 1) *
311 if (providerTable
->entireNetwork
)
313 memcpy(providerTable
->entireNetwork
, stringresource
, entireNetworkLen
*sizeof(WCHAR
));
314 providerTable
->entireNetwork
[entireNetworkLen
] = 0;
316 providerTable
->numAllocated
= numToAllocate
;
317 for (ptr
= providers
; ptr
; )
320 ptr
= strchrW(ptr
, ',');
323 _tryLoadProvider(ptrPrev
);
327 HeapFree(GetProcessHeap(), 0, providers
);
340 for (i
= 0; i
< providerTable
->numProviders
; i
++)
342 HeapFree(GetProcessHeap(), 0, providerTable
->table
[i
].name
);
343 FreeModule(providerTable
->table
[i
].hLib
);
345 HeapFree(GetProcessHeap(), 0, providerTable
->entireNetwork
);
346 HeapFree(GetProcessHeap(), 0, providerTable
);
347 providerTable
= NULL
;
351 static DWORD
_findProviderIndexW(LPCWSTR lpProvider
)
353 DWORD ret
= BAD_PROVIDER_INDEX
;
355 if (providerTable
&& providerTable
->numProviders
)
359 for (i
= 0; i
< providerTable
->numProviders
&&
360 ret
== BAD_PROVIDER_INDEX
; i
++)
361 if (!strcmpW(lpProvider
, providerTable
->table
[i
].name
))
371 static LPNETRESOURCEW
_copyNetResourceForEnumW(LPNETRESOURCEW lpNet
)
377 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(NETRESOURCEW
));
383 ret
->lpLocalName
= ret
->lpComment
= ret
->lpProvider
= NULL
;
384 if (lpNet
->lpRemoteName
)
386 len
= strlenW(lpNet
->lpRemoteName
) + 1;
387 ret
->lpRemoteName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
388 if (ret
->lpRemoteName
)
389 strcpyW(ret
->lpRemoteName
, lpNet
->lpRemoteName
);
398 static void _freeEnumNetResource(LPNETRESOURCEW lpNet
)
402 HeapFree(GetProcessHeap(), 0, lpNet
->lpRemoteName
);
403 HeapFree(GetProcessHeap(), 0, lpNet
);
407 static PWNetEnumerator
_createNullEnumerator(void)
409 PWNetEnumerator ret
= HeapAlloc(GetProcessHeap(),
410 HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
413 ret
->enumType
= WNET_ENUMERATOR_TYPE_NULL
;
417 static PWNetEnumerator
_createGlobalEnumeratorW(DWORD dwScope
, DWORD dwType
,
418 DWORD dwUsage
, LPNETRESOURCEW lpNet
)
420 PWNetEnumerator ret
= HeapAlloc(GetProcessHeap(),
421 HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
425 ret
->enumType
= WNET_ENUMERATOR_TYPE_GLOBAL
;
426 ret
->dwScope
= dwScope
;
427 ret
->dwType
= dwType
;
428 ret
->dwUsage
= dwUsage
;
429 ret
->specific
.net
= _copyNetResourceForEnumW(lpNet
);
434 static PWNetEnumerator
_createProviderEnumerator(DWORD dwScope
, DWORD dwType
,
435 DWORD dwUsage
, DWORD index
, HANDLE handle
)
439 if (!providerTable
|| index
>= providerTable
->numProviders
)
443 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
446 ret
->enumType
= WNET_ENUMERATOR_TYPE_PROVIDER
;
447 ret
->providerIndex
= index
;
448 ret
->dwScope
= dwScope
;
449 ret
->dwType
= dwType
;
450 ret
->dwUsage
= dwUsage
;
451 ret
->handle
= handle
;
457 static PWNetEnumerator
_createContextEnumerator(DWORD dwScope
, DWORD dwType
,
460 PWNetEnumerator ret
= HeapAlloc(GetProcessHeap(),
461 HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
465 ret
->enumType
= WNET_ENUMERATOR_TYPE_CONTEXT
;
466 ret
->dwScope
= dwScope
;
467 ret
->dwType
= dwType
;
468 ret
->dwUsage
= dwUsage
;
473 static PWNetEnumerator
_createConnectedEnumerator(DWORD dwScope
, DWORD dwType
,
476 PWNetEnumerator ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
479 ret
->enumType
= WNET_ENUMERATOR_TYPE_CONNECTED
;
480 ret
->dwScope
= dwScope
;
481 ret
->dwType
= dwType
;
482 ret
->dwUsage
= dwUsage
;
483 ret
->specific
.handles
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HANDLE
) * providerTable
->numProviders
);
484 if (!ret
->specific
.handles
)
486 HeapFree(GetProcessHeap(), 0, ret
);
493 /* Thunks the array of wide-string LPNETRESOURCEs lpNetArrayIn into buffer
494 * lpBuffer, with size *lpBufferSize. lpNetArrayIn contains *lpcCount entries
495 * to start. On return, *lpcCount reflects the number thunked into lpBuffer.
496 * Returns WN_SUCCESS on success (all of lpNetArrayIn thunked), WN_MORE_DATA
497 * if not all members of the array could be thunked, and something else on
500 static DWORD
_thunkNetResourceArrayWToA(const NETRESOURCEW
*lpNetArrayIn
,
501 const DWORD
*lpcCount
, LPVOID lpBuffer
, const DWORD
*lpBufferSize
)
503 DWORD i
, numToThunk
, totalBytes
, ret
;
507 return WN_BAD_POINTER
;
509 return WN_BAD_POINTER
;
513 return WN_BAD_POINTER
;
515 return WN_BAD_POINTER
;
517 for (i
= 0, numToThunk
= 0, totalBytes
= 0; i
< *lpcCount
; i
++)
519 const NETRESOURCEW
*lpNet
= lpNetArrayIn
+ i
;
521 totalBytes
+= sizeof(NETRESOURCEA
);
522 if (lpNet
->lpLocalName
)
523 totalBytes
+= WideCharToMultiByte(CP_ACP
, 0, lpNet
->lpLocalName
,
524 -1, NULL
, 0, NULL
, NULL
);
525 if (lpNet
->lpRemoteName
)
526 totalBytes
+= WideCharToMultiByte(CP_ACP
, 0, lpNet
->lpRemoteName
,
527 -1, NULL
, 0, NULL
, NULL
);
528 if (lpNet
->lpComment
)
529 totalBytes
+= WideCharToMultiByte(CP_ACP
, 0, lpNet
->lpComment
,
530 -1, NULL
, 0, NULL
, NULL
);
531 if (lpNet
->lpProvider
)
532 totalBytes
+= WideCharToMultiByte(CP_ACP
, 0, lpNet
->lpProvider
,
533 -1, NULL
, 0, NULL
, NULL
);
534 if (totalBytes
< *lpBufferSize
)
537 strNext
= (LPSTR
)((LPBYTE
)lpBuffer
+ numToThunk
* sizeof(NETRESOURCEA
));
538 for (i
= 0; i
< numToThunk
; i
++)
540 LPNETRESOURCEA lpNetOut
= (LPNETRESOURCEA
)lpBuffer
+ i
;
541 const NETRESOURCEW
*lpNetIn
= lpNetArrayIn
+ i
;
543 memcpy(lpNetOut
, lpNetIn
, sizeof(NETRESOURCEA
));
544 /* lie about string lengths, we already verified how many
545 * we have space for above
547 if (lpNetIn
->lpLocalName
)
549 lpNetOut
->lpLocalName
= strNext
;
550 strNext
+= WideCharToMultiByte(CP_ACP
, 0, lpNetIn
->lpLocalName
, -1,
551 lpNetOut
->lpLocalName
, *lpBufferSize
, NULL
, NULL
);
553 if (lpNetIn
->lpRemoteName
)
555 lpNetOut
->lpRemoteName
= strNext
;
556 strNext
+= WideCharToMultiByte(CP_ACP
, 0, lpNetIn
->lpRemoteName
, -1,
557 lpNetOut
->lpRemoteName
, *lpBufferSize
, NULL
, NULL
);
559 if (lpNetIn
->lpComment
)
561 lpNetOut
->lpComment
= strNext
;
562 strNext
+= WideCharToMultiByte(CP_ACP
, 0, lpNetIn
->lpComment
, -1,
563 lpNetOut
->lpComment
, *lpBufferSize
, NULL
, NULL
);
565 if (lpNetIn
->lpProvider
)
567 lpNetOut
->lpProvider
= strNext
;
568 strNext
+= WideCharToMultiByte(CP_ACP
, 0, lpNetIn
->lpProvider
, -1,
569 lpNetOut
->lpProvider
, *lpBufferSize
, NULL
, NULL
);
572 ret
= numToThunk
< *lpcCount
? WN_MORE_DATA
: WN_SUCCESS
;
573 TRACE("numToThunk is %d, *lpcCount is %d, returning %d\n", numToThunk
,
578 /* Thunks the array of multibyte-string LPNETRESOURCEs lpNetArrayIn into buffer
579 * lpBuffer, with size *lpBufferSize. lpNetArrayIn contains *lpcCount entries
580 * to start. On return, *lpcCount reflects the number thunked into lpBuffer.
581 * Returns WN_SUCCESS on success (all of lpNetArrayIn thunked), WN_MORE_DATA
582 * if not all members of the array could be thunked, and something else on
585 static DWORD
_thunkNetResourceArrayAToW(const NETRESOURCEA
*lpNetArrayIn
,
586 const DWORD
*lpcCount
, LPVOID lpBuffer
, const DWORD
*lpBufferSize
)
588 DWORD i
, numToThunk
, totalBytes
, ret
;
592 return WN_BAD_POINTER
;
594 return WN_BAD_POINTER
;
598 return WN_BAD_POINTER
;
600 return WN_BAD_POINTER
;
602 for (i
= 0, numToThunk
= 0, totalBytes
= 0; i
< *lpcCount
; i
++)
604 const NETRESOURCEA
*lpNet
= lpNetArrayIn
+ i
;
606 totalBytes
+= sizeof(NETRESOURCEW
);
607 if (lpNet
->lpLocalName
)
608 totalBytes
+= MultiByteToWideChar(CP_ACP
, 0, lpNet
->lpLocalName
,
609 -1, NULL
, 0) * sizeof(WCHAR
);
610 if (lpNet
->lpRemoteName
)
611 totalBytes
+= MultiByteToWideChar(CP_ACP
, 0, lpNet
->lpRemoteName
,
612 -1, NULL
, 0) * sizeof(WCHAR
);
613 if (lpNet
->lpComment
)
614 totalBytes
+= MultiByteToWideChar(CP_ACP
, 0, lpNet
->lpComment
,
615 -1, NULL
, 0) * sizeof(WCHAR
);
616 if (lpNet
->lpProvider
)
617 totalBytes
+= MultiByteToWideChar(CP_ACP
, 0, lpNet
->lpProvider
,
618 -1, NULL
, 0) * sizeof(WCHAR
);
619 if (totalBytes
< *lpBufferSize
)
622 strNext
= (LPWSTR
)((LPBYTE
)lpBuffer
+ numToThunk
* sizeof(NETRESOURCEW
));
623 for (i
= 0; i
< numToThunk
; i
++)
625 LPNETRESOURCEW lpNetOut
= (LPNETRESOURCEW
)lpBuffer
+ i
;
626 const NETRESOURCEA
*lpNetIn
= lpNetArrayIn
+ i
;
628 memcpy(lpNetOut
, lpNetIn
, sizeof(NETRESOURCEW
));
629 /* lie about string lengths, we already verified how many
630 * we have space for above
632 if (lpNetIn
->lpLocalName
)
634 lpNetOut
->lpLocalName
= strNext
;
635 strNext
+= MultiByteToWideChar(CP_ACP
, 0, lpNetIn
->lpLocalName
,
636 -1, lpNetOut
->lpLocalName
, *lpBufferSize
);
638 if (lpNetIn
->lpRemoteName
)
640 lpNetOut
->lpRemoteName
= strNext
;
641 strNext
+= MultiByteToWideChar(CP_ACP
, 0, lpNetIn
->lpRemoteName
,
642 -1, lpNetOut
->lpRemoteName
, *lpBufferSize
);
644 if (lpNetIn
->lpComment
)
646 lpNetOut
->lpComment
= strNext
;
647 strNext
+= MultiByteToWideChar(CP_ACP
, 0, lpNetIn
->lpComment
,
648 -1, lpNetOut
->lpComment
, *lpBufferSize
);
650 if (lpNetIn
->lpProvider
)
652 lpNetOut
->lpProvider
= strNext
;
653 strNext
+= MultiByteToWideChar(CP_ACP
, 0, lpNetIn
->lpProvider
,
654 -1, lpNetOut
->lpProvider
, *lpBufferSize
);
657 ret
= numToThunk
< *lpcCount
? WN_MORE_DATA
: WN_SUCCESS
;
658 TRACE("numToThunk is %d, *lpcCount is %d, returning %d\n", numToThunk
,
663 /*********************************************************************
664 * WNetOpenEnumA [MPR.@]
666 * See comments for WNetOpenEnumW.
668 DWORD WINAPI
WNetOpenEnumA( DWORD dwScope
, DWORD dwType
, DWORD dwUsage
,
669 LPNETRESOURCEA lpNet
, LPHANDLE lphEnum
)
673 TRACE( "(%08X, %08X, %08X, %p, %p)\n",
674 dwScope
, dwType
, dwUsage
, lpNet
, lphEnum
);
677 ret
= WN_BAD_POINTER
;
678 else if (!providerTable
|| providerTable
->numProviders
== 0)
687 LPNETRESOURCEW lpNetWide
= NULL
;
689 DWORD size
= sizeof(buf
), count
= 1;
690 BOOL allocated
= FALSE
;
692 ret
= _thunkNetResourceArrayAToW(lpNet
, &count
, buf
, &size
);
693 if (ret
== WN_MORE_DATA
)
695 lpNetWide
= HeapAlloc(GetProcessHeap(), 0,
699 ret
= _thunkNetResourceArrayAToW(lpNet
, &count
, lpNetWide
,
704 ret
= WN_OUT_OF_MEMORY
;
706 else if (ret
== WN_SUCCESS
)
707 lpNetWide
= (LPNETRESOURCEW
)buf
;
708 if (ret
== WN_SUCCESS
)
709 ret
= WNetOpenEnumW(dwScope
, dwType
, dwUsage
, lpNetWide
,
712 HeapFree(GetProcessHeap(), 0, lpNetWide
);
715 ret
= WNetOpenEnumW(dwScope
, dwType
, dwUsage
, NULL
, lphEnum
);
719 TRACE("Returning %d\n", ret
);
723 /*********************************************************************
724 * WNetOpenEnumW [MPR.@]
726 * Network enumeration has way too many parameters, so I'm not positive I got
727 * them right. What I've got so far:
729 * - If the scope is RESOURCE_GLOBALNET, and no LPNETRESOURCE is passed,
730 * all the network providers should be enumerated.
732 * - If the scope is RESOURCE_GLOBALNET, and LPNETRESOURCE is passed, and
733 * and neither the LPNETRESOURCE's lpRemoteName nor the LPNETRESOURCE's
734 * lpProvider is set, all the network providers should be enumerated.
735 * (This means the enumeration is a list of network providers, not that the
736 * enumeration is passed on to the providers.)
738 * - If the scope is RESOURCE_GLOBALNET, and LPNETRESOURCE is passed, and the
739 * resource matches the "Entire Network" resource (no remote name, no
740 * provider, comment is the "Entire Network" string), a RESOURCE_GLOBALNET
741 * enumeration is done on every network provider.
743 * - If the scope is RESOURCE_GLOBALNET, and LPNETRESOURCE is passed, and
744 * the LPNETRESOURCE's lpProvider is set, enumeration will be passed through
745 * only to the given network provider.
747 * - If the scope is RESOURCE_GLOBALNET, and LPNETRESOURCE is passed, and
748 * no lpProvider is set, enumeration will be tried on every network provider,
749 * in the order in which they're loaded.
751 * - The LPNETRESOURCE should be disregarded for scopes besides
752 * RESOURCE_GLOBALNET. MSDN states that lpNet must be NULL if dwScope is not
753 * RESOURCE_GLOBALNET, but Windows doesn't return an error if it isn't NULL.
755 * - If the scope is RESOURCE_CONTEXT, MS includes an "Entire Network" net
756 * resource in the enumerated list, as well as any machines in your
757 * workgroup. The machines in your workgroup come from doing a
758 * RESOURCE_CONTEXT enumeration of every Network Provider.
760 DWORD WINAPI
WNetOpenEnumW( DWORD dwScope
, DWORD dwType
, DWORD dwUsage
,
761 LPNETRESOURCEW lpNet
, LPHANDLE lphEnum
)
765 TRACE( "(%08X, %08X, %08X, %p, %p)\n",
766 dwScope
, dwType
, dwUsage
, lpNet
, lphEnum
);
769 ret
= WN_BAD_POINTER
;
770 else if (!providerTable
|| providerTable
->numProviders
== 0)
779 case RESOURCE_GLOBALNET
:
782 if (lpNet
->lpProvider
)
784 DWORD index
= _findProviderIndexW(lpNet
->lpProvider
);
786 if (index
!= BAD_PROVIDER_INDEX
)
788 if (providerTable
->table
[index
].openEnum
&&
789 providerTable
->table
[index
].dwEnumScopes
& WNNC_ENUM_GLOBAL
)
792 PWSTR RemoteName
= lpNet
->lpRemoteName
;
794 if ((lpNet
->dwUsage
& RESOURCEUSAGE_CONTAINER
) &&
795 RemoteName
&& !strcmpW(RemoteName
, lpNet
->lpProvider
))
796 lpNet
->lpRemoteName
= NULL
;
798 ret
= providerTable
->table
[index
].openEnum(
799 dwScope
, dwType
, dwUsage
, lpNet
, &handle
);
800 if (ret
== WN_SUCCESS
)
802 *lphEnum
= _createProviderEnumerator(
803 dwScope
, dwType
, dwUsage
, index
, handle
);
804 ret
= *lphEnum
? WN_SUCCESS
:
808 lpNet
->lpRemoteName
= RemoteName
;
811 ret
= WN_NOT_SUPPORTED
;
814 ret
= WN_BAD_PROVIDER
;
816 else if (lpNet
->lpRemoteName
)
818 *lphEnum
= _createGlobalEnumeratorW(dwScope
,
819 dwType
, dwUsage
, lpNet
);
820 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
824 if (lpNet
->lpComment
&& !strcmpW(lpNet
->lpComment
,
825 providerTable
->entireNetwork
))
827 /* comment matches the "Entire Network", enumerate
828 * global scope of every provider
830 *lphEnum
= _createGlobalEnumeratorW(dwScope
,
831 dwType
, dwUsage
, lpNet
);
835 /* this is the same as not having passed lpNet */
836 *lphEnum
= _createGlobalEnumeratorW(dwScope
,
837 dwType
, dwUsage
, NULL
);
839 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
844 *lphEnum
= _createGlobalEnumeratorW(dwScope
, dwType
,
846 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
849 case RESOURCE_CONTEXT
:
850 *lphEnum
= _createContextEnumerator(dwScope
, dwType
, dwUsage
);
851 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
853 case RESOURCE_CONNECTED
:
854 *lphEnum
= _createConnectedEnumerator(dwScope
, dwType
, dwUsage
);
855 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
857 case RESOURCE_REMEMBERED
:
858 *lphEnum
= _createNullEnumerator();
859 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
862 WARN("unknown scope 0x%08x\n", dwScope
);
868 TRACE("Returning %d\n", ret
);
872 /*********************************************************************
873 * WNetEnumResourceA [MPR.@]
875 DWORD WINAPI
WNetEnumResourceA( HANDLE hEnum
, LPDWORD lpcCount
,
876 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
880 TRACE( "(%p, %p, %p, %p)\n", hEnum
, lpcCount
, lpBuffer
, lpBufferSize
);
883 ret
= WN_BAD_POINTER
;
885 ret
= WN_BAD_POINTER
;
887 ret
= WN_BAD_POINTER
;
888 else if (!lpBufferSize
)
889 ret
= WN_BAD_POINTER
;
890 else if (*lpBufferSize
< sizeof(NETRESOURCEA
))
892 *lpBufferSize
= sizeof(NETRESOURCEA
);
897 DWORD localCount
= *lpcCount
, localSize
= *lpBufferSize
;
898 LPVOID localBuffer
= HeapAlloc(GetProcessHeap(), 0, localSize
);
902 ret
= WNetEnumResourceW(hEnum
, &localCount
, localBuffer
,
904 if (ret
== WN_SUCCESS
|| (ret
== WN_MORE_DATA
&& localCount
!= -1))
906 /* FIXME: this isn't necessarily going to work in the case of
907 * WN_MORE_DATA, because our enumerator may have moved on to
908 * the next provider. MSDN states that a large (16KB) buffer
909 * size is the appropriate usage of this function, so
910 * hopefully it won't be an issue.
912 ret
= _thunkNetResourceArrayWToA(localBuffer
, &localCount
,
913 lpBuffer
, lpBufferSize
);
914 *lpcCount
= localCount
;
916 HeapFree(GetProcessHeap(), 0, localBuffer
);
919 ret
= WN_OUT_OF_MEMORY
;
923 TRACE("Returning %d\n", ret
);
927 static DWORD
_countProviderBytesW(PWNetProvider provider
)
933 ret
= sizeof(NETRESOURCEW
);
934 ret
+= 2 * (strlenW(provider
->name
) + 1) * sizeof(WCHAR
);
941 static DWORD
_enumerateProvidersW(PWNetEnumerator enumerator
, LPDWORD lpcCount
,
942 LPVOID lpBuffer
, const DWORD
*lpBufferSize
)
947 return WN_BAD_POINTER
;
948 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_GLOBAL
)
951 return WN_BAD_POINTER
;
953 return WN_BAD_POINTER
;
955 return WN_BAD_POINTER
;
956 if (*lpBufferSize
< sizeof(NETRESOURCEA
))
959 if (!providerTable
|| enumerator
->providerIndex
>=
960 providerTable
->numProviders
)
961 ret
= WN_NO_MORE_ENTRIES
;
964 DWORD bytes
= 0, count
= 0, countLimit
, i
;
965 LPNETRESOURCEW resource
;
968 countLimit
= *lpcCount
== -1 ?
969 providerTable
->numProviders
- enumerator
->providerIndex
: *lpcCount
;
970 while (count
< countLimit
&& bytes
< *lpBufferSize
)
972 DWORD bytesNext
= _countProviderBytesW(
973 &providerTable
->table
[count
+ enumerator
->providerIndex
]);
975 if (bytes
+ bytesNext
< *lpBufferSize
)
981 strNext
= (LPWSTR
)((LPBYTE
)lpBuffer
+ count
* sizeof(NETRESOURCEW
));
982 for (i
= 0, resource
= lpBuffer
; i
< count
; i
++, resource
++)
984 resource
->dwScope
= RESOURCE_GLOBALNET
;
985 resource
->dwType
= RESOURCETYPE_ANY
;
986 resource
->dwDisplayType
= RESOURCEDISPLAYTYPE_NETWORK
;
987 resource
->dwUsage
= RESOURCEUSAGE_CONTAINER
|
988 RESOURCEUSAGE_RESERVED
;
989 resource
->lpLocalName
= NULL
;
990 resource
->lpRemoteName
= strNext
;
991 strcpyW(resource
->lpRemoteName
,
992 providerTable
->table
[i
+ enumerator
->providerIndex
].name
);
993 strNext
+= strlenW(resource
->lpRemoteName
) + 1;
994 resource
->lpComment
= NULL
;
995 resource
->lpProvider
= strNext
;
996 strcpyW(resource
->lpProvider
,
997 providerTable
->table
[i
+ enumerator
->providerIndex
].name
);
998 strNext
+= strlenW(resource
->lpProvider
) + 1;
1000 enumerator
->providerIndex
+= count
;
1002 ret
= count
> 0 ? WN_SUCCESS
: WN_MORE_DATA
;
1004 TRACE("Returning %d\n", ret
);
1008 /* Advances the enumerator (assumed to be a global enumerator) to the next
1009 * provider that supports the enumeration scope passed to WNetOpenEnum. Does
1010 * not open a handle with the next provider.
1011 * If the existing handle is NULL, may leave the enumerator unchanged, since
1012 * the current provider may support the desired scope.
1013 * If the existing handle is not NULL, closes it before moving on.
1014 * Returns WN_SUCCESS on success, WN_NO_MORE_ENTRIES if there is no available
1015 * provider, and another error on failure.
1017 static DWORD
_globalEnumeratorAdvance(PWNetEnumerator enumerator
)
1020 return WN_BAD_POINTER
;
1021 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_GLOBAL
)
1022 return WN_BAD_VALUE
;
1023 if (!providerTable
|| enumerator
->providerIndex
>=
1024 providerTable
->numProviders
)
1025 return WN_NO_MORE_ENTRIES
;
1027 if (enumerator
->providerDone
)
1030 enumerator
->providerDone
= FALSE
;
1031 if (enumerator
->handle
)
1033 providerTable
->table
[enumerator
->providerIndex
].closeEnum(
1034 enumerator
->handle
);
1035 enumerator
->handle
= NULL
;
1036 enumerator
->providerIndex
++;
1038 if (enumerator
->dwScope
== RESOURCE_CONNECTED
)
1039 dwEnum
= WNNC_ENUM_LOCAL
;
1040 else if (enumerator
->dwScope
== RESOURCE_GLOBALNET
)
1041 dwEnum
= WNNC_ENUM_GLOBAL
;
1042 else if (enumerator
->dwScope
== RESOURCE_CONTEXT
)
1043 dwEnum
= WNNC_ENUM_CONTEXT
;
1044 for (; enumerator
->providerIndex
< providerTable
->numProviders
&&
1045 !(providerTable
->table
[enumerator
->providerIndex
].dwEnumScopes
1046 & dwEnum
); enumerator
->providerIndex
++)
1049 return enumerator
->providerIndex
< providerTable
->numProviders
?
1050 WN_SUCCESS
: WN_NO_MORE_ENTRIES
;
1053 /* "Passes through" call to the next provider that supports the enumeration
1055 * FIXME: if one call to a provider's enumerator succeeds while there's still
1056 * space in lpBuffer, I don't call to the next provider. The caller may not
1057 * expect that it should call EnumResourceW again with a return value of
1058 * WN_SUCCESS (depending what *lpcCount was to begin with). That means strings
1059 * may have to be moved around a bit, ick.
1061 static DWORD
_enumerateGlobalPassthroughW(PWNetEnumerator enumerator
,
1062 LPDWORD lpcCount
, LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1067 return WN_BAD_POINTER
;
1068 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_GLOBAL
)
1069 return WN_BAD_VALUE
;
1071 return WN_BAD_POINTER
;
1073 return WN_BAD_POINTER
;
1075 return WN_BAD_POINTER
;
1076 if (*lpBufferSize
< sizeof(NETRESOURCEW
))
1077 return WN_MORE_DATA
;
1079 ret
= _globalEnumeratorAdvance(enumerator
);
1080 if (ret
== WN_SUCCESS
)
1082 ret
= providerTable
->table
[enumerator
->providerIndex
].
1083 openEnum(enumerator
->dwScope
, enumerator
->dwType
,
1084 enumerator
->dwUsage
, enumerator
->specific
.net
,
1085 &enumerator
->handle
);
1086 if (ret
== WN_SUCCESS
)
1088 ret
= providerTable
->table
[enumerator
->providerIndex
].
1089 enumResource(enumerator
->handle
, lpcCount
, lpBuffer
,
1091 if (ret
!= WN_MORE_DATA
)
1092 enumerator
->providerDone
= TRUE
;
1095 TRACE("Returning %d\n", ret
);
1099 static DWORD
_enumerateGlobalW(PWNetEnumerator enumerator
, LPDWORD lpcCount
,
1100 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1105 return WN_BAD_POINTER
;
1106 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_GLOBAL
)
1107 return WN_BAD_VALUE
;
1109 return WN_BAD_POINTER
;
1111 return WN_BAD_POINTER
;
1113 return WN_BAD_POINTER
;
1114 if (*lpBufferSize
< sizeof(NETRESOURCEW
))
1115 return WN_MORE_DATA
;
1117 return WN_NO_NETWORK
;
1119 switch (enumerator
->dwScope
)
1121 case RESOURCE_GLOBALNET
:
1122 if (enumerator
->specific
.net
)
1123 ret
= _enumerateGlobalPassthroughW(enumerator
, lpcCount
,
1124 lpBuffer
, lpBufferSize
);
1126 ret
= _enumerateProvidersW(enumerator
, lpcCount
, lpBuffer
,
1129 case RESOURCE_CONTEXT
:
1130 ret
= _enumerateGlobalPassthroughW(enumerator
, lpcCount
, lpBuffer
,
1134 WARN("unexpected scope 0x%08x\n", enumerator
->dwScope
);
1135 ret
= WN_NO_MORE_ENTRIES
;
1137 TRACE("Returning %d\n", ret
);
1141 static DWORD
_enumerateProviderW(PWNetEnumerator enumerator
, LPDWORD lpcCount
,
1142 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1145 return WN_BAD_POINTER
;
1146 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_PROVIDER
)
1147 return WN_BAD_VALUE
;
1148 if (!enumerator
->handle
)
1149 return WN_BAD_VALUE
;
1151 return WN_BAD_POINTER
;
1153 return WN_BAD_POINTER
;
1155 return WN_BAD_POINTER
;
1157 return WN_NO_NETWORK
;
1158 if (enumerator
->providerIndex
>= providerTable
->numProviders
)
1159 return WN_NO_MORE_ENTRIES
;
1160 if (!providerTable
->table
[enumerator
->providerIndex
].enumResource
)
1161 return WN_BAD_VALUE
;
1162 return providerTable
->table
[enumerator
->providerIndex
].enumResource(
1163 enumerator
->handle
, lpcCount
, lpBuffer
, lpBufferSize
);
1166 static DWORD
_enumerateContextW(PWNetEnumerator enumerator
, LPDWORD lpcCount
,
1167 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1170 size_t cchEntireNetworkLen
, bytesNeeded
;
1173 return WN_BAD_POINTER
;
1174 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_CONTEXT
)
1175 return WN_BAD_VALUE
;
1177 return WN_BAD_POINTER
;
1179 return WN_BAD_POINTER
;
1181 return WN_BAD_POINTER
;
1183 return WN_NO_NETWORK
;
1185 cchEntireNetworkLen
= strlenW(providerTable
->entireNetwork
) + 1;
1186 bytesNeeded
= sizeof(NETRESOURCEW
) + cchEntireNetworkLen
* sizeof(WCHAR
);
1187 if (*lpBufferSize
< bytesNeeded
)
1189 *lpBufferSize
= bytesNeeded
;
1194 LPNETRESOURCEW lpNet
= lpBuffer
;
1196 lpNet
->dwScope
= RESOURCE_GLOBALNET
;
1197 lpNet
->dwType
= enumerator
->dwType
;
1198 lpNet
->dwDisplayType
= RESOURCEDISPLAYTYPE_ROOT
;
1199 lpNet
->dwUsage
= RESOURCEUSAGE_CONTAINER
;
1200 lpNet
->lpLocalName
= NULL
;
1201 lpNet
->lpRemoteName
= NULL
;
1202 lpNet
->lpProvider
= NULL
;
1203 /* odd, but correct: put comment at end of buffer, so it won't get
1204 * overwritten by subsequent calls to a provider's enumResource
1206 lpNet
->lpComment
= (LPWSTR
)((LPBYTE
)lpBuffer
+ *lpBufferSize
-
1207 (cchEntireNetworkLen
* sizeof(WCHAR
)));
1208 strcpyW(lpNet
->lpComment
, providerTable
->entireNetwork
);
1211 if (ret
== WN_SUCCESS
)
1213 DWORD bufferSize
= *lpBufferSize
- bytesNeeded
;
1215 /* "Entire Network" entry enumerated--morph this into a global
1216 * enumerator. enumerator->lpNet continues to be NULL, since it has
1217 * no meaning when the scope isn't RESOURCE_GLOBALNET.
1219 enumerator
->enumType
= WNET_ENUMERATOR_TYPE_GLOBAL
;
1220 ret
= _enumerateGlobalW(enumerator
, lpcCount
,
1221 (LPBYTE
)lpBuffer
+ bytesNeeded
, &bufferSize
);
1222 if (ret
== WN_SUCCESS
)
1224 /* reflect the fact that we already enumerated "Entire Network" */
1226 *lpBufferSize
= bufferSize
+ bytesNeeded
;
1230 /* the provider enumeration failed, but we already succeeded in
1231 * enumerating "Entire Network"--leave type as global to allow a
1232 * retry, but indicate success with a count of one.
1236 *lpBufferSize
= bytesNeeded
;
1239 TRACE("Returning %d\n", ret
);
1243 static DWORD
_copyStringToEnumW(const WCHAR
*source
, DWORD
* left
, void** end
)
1246 WCHAR
* local
= *end
;
1248 len
= strlenW(source
) + 1;
1249 len
*= sizeof(WCHAR
);
1251 return WN_MORE_DATA
;
1253 local
-= (len
/ sizeof(WCHAR
));
1254 memcpy(local
, source
, len
);
1261 static DWORD
_enumerateConnectedW(PWNetEnumerator enumerator
, DWORD
* user_count
,
1262 void* user_buffer
, DWORD
* user_size
)
1264 DWORD ret
, index
, count
, size
, i
, left
;
1266 NETRESOURCEW
* curr
, * buffer
;
1270 return WN_BAD_POINTER
;
1271 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_CONNECTED
)
1272 return WN_BAD_VALUE
;
1273 if (!user_count
|| !user_buffer
|| !user_size
)
1274 return WN_BAD_POINTER
;
1276 return WN_NO_NETWORK
;
1278 handles
= enumerator
->specific
.handles
;
1281 buffer
= HeapAlloc(GetProcessHeap(), 0, *user_size
);
1283 return WN_NO_NETWORK
;
1286 end
= (char *)user_buffer
+ size
;
1287 count
= *user_count
;
1289 ret
= WN_NO_MORE_ENTRIES
;
1290 for (index
= 0; index
< providerTable
->numProviders
; index
++)
1292 if (providerTable
->table
[index
].dwEnumScopes
)
1294 if (handles
[index
] == 0)
1296 ret
= providerTable
->table
[index
].openEnum(enumerator
->dwScope
,
1298 enumerator
->dwUsage
,
1299 NULL
, &handles
[index
]);
1300 if (ret
!= WN_SUCCESS
)
1304 ret
= providerTable
->table
[index
].enumResource(handles
[index
],
1307 if (ret
== WN_MORE_DATA
)
1310 if (ret
== WN_SUCCESS
)
1312 for (i
= 0; i
< count
; ++i
)
1314 if (left
< sizeof(NETRESOURCEW
))
1320 memcpy(curr
, &buffer
[i
], sizeof(NETRESOURCEW
));
1321 left
-= sizeof(NETRESOURCEW
);
1323 ret
= _copyStringToEnumW(buffer
[i
].lpLocalName
, &left
, &end
);
1324 if (ret
== WN_MORE_DATA
)
1326 curr
->lpLocalName
= end
;
1328 ret
= _copyStringToEnumW(buffer
[i
].lpRemoteName
, &left
, &end
);
1329 if (ret
== WN_MORE_DATA
)
1331 curr
->lpRemoteName
= end
;
1333 ret
= _copyStringToEnumW(buffer
[i
].lpProvider
, &left
, &end
);
1334 if (ret
== WN_MORE_DATA
)
1336 curr
->lpProvider
= end
;
1341 count
= *user_count
- count
;
1345 if (ret
!= WN_SUCCESS
|| count
== 0)
1351 ret
= WN_NO_MORE_ENTRIES
;
1353 *user_count
= *user_count
- count
;
1354 if (ret
!= WN_MORE_DATA
&& ret
!= WN_NO_MORE_ENTRIES
)
1357 HeapFree(GetProcessHeap(), 0, buffer
);
1359 TRACE("Returning %d\n", ret
);
1363 /*********************************************************************
1364 * WNetEnumResourceW [MPR.@]
1366 DWORD WINAPI
WNetEnumResourceW( HANDLE hEnum
, LPDWORD lpcCount
,
1367 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1371 TRACE( "(%p, %p, %p, %p)\n", hEnum
, lpcCount
, lpBuffer
, lpBufferSize
);
1374 ret
= WN_BAD_POINTER
;
1376 ret
= WN_BAD_POINTER
;
1378 ret
= WN_BAD_POINTER
;
1379 else if (!lpBufferSize
)
1380 ret
= WN_BAD_POINTER
;
1381 else if (*lpBufferSize
< sizeof(NETRESOURCEW
))
1383 *lpBufferSize
= sizeof(NETRESOURCEW
);
1388 PWNetEnumerator enumerator
= (PWNetEnumerator
)hEnum
;
1390 switch (enumerator
->enumType
)
1392 case WNET_ENUMERATOR_TYPE_NULL
:
1393 ret
= WN_NO_MORE_ENTRIES
;
1395 case WNET_ENUMERATOR_TYPE_GLOBAL
:
1396 ret
= _enumerateGlobalW(enumerator
, lpcCount
, lpBuffer
,
1399 case WNET_ENUMERATOR_TYPE_PROVIDER
:
1400 ret
= _enumerateProviderW(enumerator
, lpcCount
, lpBuffer
,
1403 case WNET_ENUMERATOR_TYPE_CONTEXT
:
1404 ret
= _enumerateContextW(enumerator
, lpcCount
, lpBuffer
,
1407 case WNET_ENUMERATOR_TYPE_CONNECTED
:
1408 ret
= _enumerateConnectedW(enumerator
, lpcCount
, lpBuffer
,
1412 WARN("bogus enumerator type!\n");
1413 ret
= WN_NO_NETWORK
;
1418 TRACE("Returning %d\n", ret
);
1422 /*********************************************************************
1423 * WNetCloseEnum [MPR.@]
1425 DWORD WINAPI
WNetCloseEnum( HANDLE hEnum
)
1430 TRACE( "(%p)\n", hEnum
);
1434 PWNetEnumerator enumerator
= (PWNetEnumerator
)hEnum
;
1436 switch (enumerator
->enumType
)
1438 case WNET_ENUMERATOR_TYPE_NULL
:
1441 case WNET_ENUMERATOR_TYPE_GLOBAL
:
1442 if (enumerator
->specific
.net
)
1443 _freeEnumNetResource(enumerator
->specific
.net
);
1444 if (enumerator
->handle
)
1445 providerTable
->table
[enumerator
->providerIndex
].
1446 closeEnum(enumerator
->handle
);
1449 case WNET_ENUMERATOR_TYPE_PROVIDER
:
1450 if (enumerator
->handle
)
1451 providerTable
->table
[enumerator
->providerIndex
].
1452 closeEnum(enumerator
->handle
);
1455 case WNET_ENUMERATOR_TYPE_CONNECTED
:
1456 handles
= enumerator
->specific
.handles
;
1457 for (index
= 0; index
< providerTable
->numProviders
; index
++)
1459 if (providerTable
->table
[index
].dwEnumScopes
&& handles
[index
])
1460 providerTable
->table
[index
].closeEnum(handles
[index
]);
1462 HeapFree(GetProcessHeap(), 0, handles
);
1466 WARN("bogus enumerator type!\n");
1467 ret
= WN_BAD_HANDLE
;
1469 HeapFree(GetProcessHeap(), 0, hEnum
);
1472 ret
= WN_BAD_HANDLE
;
1475 TRACE("Returning %d\n", ret
);
1479 /*********************************************************************
1480 * WNetGetResourceInformationA [MPR.@]
1482 * See WNetGetResourceInformationW
1484 DWORD WINAPI
WNetGetResourceInformationA( LPNETRESOURCEA lpNetResource
,
1485 LPVOID lpBuffer
, LPDWORD cbBuffer
,
1490 TRACE( "(%p, %p, %p, %p)\n",
1491 lpNetResource
, lpBuffer
, cbBuffer
, lplpSystem
);
1493 if (!providerTable
|| providerTable
->numProviders
== 0)
1494 ret
= WN_NO_NETWORK
;
1495 else if (lpNetResource
)
1497 LPNETRESOURCEW lpNetResourceW
= NULL
;
1498 DWORD size
= 1024, count
= 1;
1501 lpNetResourceW
= HeapAlloc(GetProcessHeap(), 0, size
);
1502 ret
= _thunkNetResourceArrayAToW(lpNetResource
, &count
, lpNetResourceW
, &size
);
1503 if (ret
== WN_MORE_DATA
)
1505 HeapFree(GetProcessHeap(), 0, lpNetResourceW
);
1506 lpNetResourceW
= HeapAlloc(GetProcessHeap(), 0, size
);
1508 ret
= _thunkNetResourceArrayAToW(lpNetResource
,
1509 &count
, lpNetResourceW
, &size
);
1511 ret
= WN_OUT_OF_MEMORY
;
1513 if (ret
== WN_SUCCESS
)
1515 LPWSTR lpSystemW
= NULL
;
1518 lpBufferW
= HeapAlloc(GetProcessHeap(), 0, size
);
1521 ret
= WNetGetResourceInformationW(lpNetResourceW
,
1522 lpBufferW
, &size
, &lpSystemW
);
1523 if (ret
== WN_MORE_DATA
)
1525 HeapFree(GetProcessHeap(), 0, lpBufferW
);
1526 lpBufferW
= HeapAlloc(GetProcessHeap(), 0, size
);
1528 ret
= WNetGetResourceInformationW(lpNetResourceW
,
1529 lpBufferW
, &size
, &lpSystemW
);
1531 ret
= WN_OUT_OF_MEMORY
;
1533 if (ret
== WN_SUCCESS
)
1535 ret
= _thunkNetResourceArrayWToA(lpBufferW
,
1536 &count
, lpBuffer
, cbBuffer
);
1537 HeapFree(GetProcessHeap(), 0, lpNetResourceW
);
1538 lpNetResourceW
= lpBufferW
;
1539 size
= sizeof(NETRESOURCEA
);
1540 size
+= WideCharToMultiByte(CP_ACP
, 0, lpNetResourceW
->lpRemoteName
,
1541 -1, NULL
, 0, NULL
, NULL
);
1542 size
+= WideCharToMultiByte(CP_ACP
, 0, lpNetResourceW
->lpProvider
,
1543 -1, NULL
, 0, NULL
, NULL
);
1545 len
= WideCharToMultiByte(CP_ACP
, 0, lpSystemW
,
1546 -1, NULL
, 0, NULL
, NULL
);
1547 if ((len
) && ( size
+ len
< *cbBuffer
))
1549 *lplpSystem
= (char*)lpBuffer
+ *cbBuffer
- len
;
1550 WideCharToMultiByte(CP_ACP
, 0, lpSystemW
, -1,
1551 *lplpSystem
, len
, NULL
, NULL
);
1558 ret
= WN_OUT_OF_MEMORY
;
1559 HeapFree(GetProcessHeap(), 0, lpBufferW
);
1562 ret
= WN_OUT_OF_MEMORY
;
1563 HeapFree(GetProcessHeap(), 0, lpSystemW
);
1565 HeapFree(GetProcessHeap(), 0, lpNetResourceW
);
1568 ret
= WN_NO_NETWORK
;
1572 TRACE("Returning %d\n", ret
);
1576 /*********************************************************************
1577 * WNetGetResourceInformationW [MPR.@]
1579 * WNetGetResourceInformationW function identifies the network provider
1580 * that owns the resource and gets information about the type of the resource.
1583 * lpNetResource [ I] the pointer to NETRESOURCEW structure, that
1584 * defines a network resource.
1585 * lpBuffer [ O] the pointer to buffer, containing result. It
1586 * contains NETRESOURCEW structure and strings to
1587 * which the members of the NETRESOURCEW structure
1589 * cbBuffer [I/O] the pointer to DWORD number - size of buffer
1591 * lplpSystem [ O] the pointer to string in the output buffer,
1592 * containing the part of the resource name without
1593 * names of the server and share.
1596 * NO_ERROR if the function succeeds. System error code if the function fails.
1599 DWORD WINAPI
WNetGetResourceInformationW( LPNETRESOURCEW lpNetResource
,
1600 LPVOID lpBuffer
, LPDWORD cbBuffer
,
1601 LPWSTR
*lplpSystem
)
1603 DWORD ret
= WN_NO_NETWORK
;
1606 TRACE( "(%p, %p, %p, %p)\n",
1607 lpNetResource
, lpBuffer
, cbBuffer
, lplpSystem
);
1610 ret
= WN_OUT_OF_MEMORY
;
1611 else if (providerTable
!= NULL
)
1613 /* FIXME: For function value of a variable is indifferent, it does
1614 * search of all providers in a network.
1616 for (index
= 0; index
< providerTable
->numProviders
; index
++)
1618 if(providerTable
->table
[index
].getCaps(WNNC_DIALOG
) &
1619 WNNC_DLG_GETRESOURCEINFORMATION
)
1621 if (providerTable
->table
[index
].getResourceInformation
)
1622 ret
= providerTable
->table
[index
].getResourceInformation(
1623 lpNetResource
, lpBuffer
, cbBuffer
, lplpSystem
);
1625 ret
= WN_NO_NETWORK
;
1626 if (ret
== WN_SUCCESS
)
1636 /*********************************************************************
1637 * WNetGetResourceParentA [MPR.@]
1639 DWORD WINAPI
WNetGetResourceParentA( LPNETRESOURCEA lpNetResource
,
1640 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1642 FIXME( "(%p, %p, %p): stub\n",
1643 lpNetResource
, lpBuffer
, lpBufferSize
);
1645 SetLastError(WN_NO_NETWORK
);
1646 return WN_NO_NETWORK
;
1649 /*********************************************************************
1650 * WNetGetResourceParentW [MPR.@]
1652 DWORD WINAPI
WNetGetResourceParentW( LPNETRESOURCEW lpNetResource
,
1653 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1655 FIXME( "(%p, %p, %p): stub\n",
1656 lpNetResource
, lpBuffer
, lpBufferSize
);
1658 SetLastError(WN_NO_NETWORK
);
1659 return WN_NO_NETWORK
;
1665 * Connection Functions
1668 /*********************************************************************
1669 * WNetAddConnectionA [MPR.@]
1671 DWORD WINAPI
WNetAddConnectionA( LPCSTR lpRemoteName
, LPCSTR lpPassword
,
1672 LPCSTR lpLocalName
)
1674 NETRESOURCEA resourcesA
;
1676 memset(&resourcesA
, 0, sizeof(resourcesA
));
1677 resourcesA
.lpRemoteName
= (LPSTR
)lpRemoteName
;
1678 resourcesA
.lpLocalName
= (LPSTR
)lpLocalName
;
1679 return WNetUseConnectionA(NULL
, &resourcesA
, lpPassword
, NULL
, 0, NULL
, 0, NULL
);
1682 /*********************************************************************
1683 * WNetAddConnectionW [MPR.@]
1685 DWORD WINAPI
WNetAddConnectionW( LPCWSTR lpRemoteName
, LPCWSTR lpPassword
,
1686 LPCWSTR lpLocalName
)
1688 NETRESOURCEW resourcesW
;
1690 memset(&resourcesW
, 0, sizeof(resourcesW
));
1691 resourcesW
.lpRemoteName
= (LPWSTR
)lpRemoteName
;
1692 resourcesW
.lpLocalName
= (LPWSTR
)lpLocalName
;
1693 return WNetUseConnectionW(NULL
, &resourcesW
, lpPassword
, NULL
, 0, NULL
, 0, NULL
);
1696 /*********************************************************************
1697 * WNetAddConnection2A [MPR.@]
1699 DWORD WINAPI
WNetAddConnection2A( LPNETRESOURCEA lpNetResource
,
1700 LPCSTR lpPassword
, LPCSTR lpUserID
,
1703 return WNetUseConnectionA(NULL
, lpNetResource
, lpPassword
, lpUserID
, dwFlags
,
1707 /*********************************************************************
1708 * WNetAddConnection2W [MPR.@]
1710 DWORD WINAPI
WNetAddConnection2W( LPNETRESOURCEW lpNetResource
,
1711 LPCWSTR lpPassword
, LPCWSTR lpUserID
,
1714 return WNetUseConnectionW(NULL
, lpNetResource
, lpPassword
, lpUserID
, dwFlags
,
1718 /*********************************************************************
1719 * WNetAddConnection3A [MPR.@]
1721 DWORD WINAPI
WNetAddConnection3A( HWND hwndOwner
, LPNETRESOURCEA lpNetResource
,
1722 LPCSTR lpPassword
, LPCSTR lpUserID
,
1725 return WNetUseConnectionA(hwndOwner
, lpNetResource
, lpPassword
, lpUserID
,
1726 dwFlags
, NULL
, 0, NULL
);
1729 /*********************************************************************
1730 * WNetAddConnection3W [MPR.@]
1732 DWORD WINAPI
WNetAddConnection3W( HWND hwndOwner
, LPNETRESOURCEW lpNetResource
,
1733 LPCWSTR lpPassword
, LPCWSTR lpUserID
,
1736 return WNetUseConnectionW(hwndOwner
, lpNetResource
, lpPassword
, lpUserID
,
1737 dwFlags
, NULL
, 0, NULL
);
1740 struct use_connection_context
1743 NETRESOURCEW
*resource
;
1744 NETRESOURCEA
*resourceA
; /* only set for WNetUseConnectionA */
1751 DWORD (*pre_set_accessname
)(struct use_connection_context
*, WCHAR
*);
1752 void (*set_accessname
)(struct use_connection_context
*, WCHAR
*);
1755 static DWORD
use_connection_pre_set_accessnameW(struct use_connection_context
*ctxt
, WCHAR
*local_name
)
1757 if (ctxt
->accessname
&& ctxt
->buffer_size
&& *ctxt
->buffer_size
)
1762 len
= strlenW(local_name
);
1764 len
= strlenW(ctxt
->resource
->lpRemoteName
);
1766 if (++len
> *ctxt
->buffer_size
)
1768 *ctxt
->buffer_size
= len
;
1769 return ERROR_MORE_DATA
;
1773 ctxt
->accessname
= NULL
;
1775 return ERROR_SUCCESS
;
1778 static void use_connection_set_accessnameW(struct use_connection_context
*ctxt
, WCHAR
*local_name
)
1780 WCHAR
*accessname
= ctxt
->accessname
;
1783 strcpyW(accessname
, local_name
);
1785 *ctxt
->result
= CONNECT_LOCALDRIVE
;
1788 strcpyW(accessname
, ctxt
->resource
->lpRemoteName
);
1791 static DWORD
wnet_use_provider( struct use_connection_context
*ctxt
, NETRESOURCEW
* netres
, WNetProvider
*provider
, BOOLEAN redirect
)
1795 caps
= provider
->getCaps(WNNC_CONNECTION
);
1796 if (!(caps
& (WNNC_CON_ADDCONNECTION
| WNNC_CON_ADDCONNECTION3
)))
1797 return ERROR_BAD_PROVIDER
;
1799 ret
= WN_ACCESS_DENIED
;
1802 if ((caps
& WNNC_CON_ADDCONNECTION3
) && provider
->addConnection3
)
1803 ret
= provider
->addConnection3(ctxt
->hwndOwner
, netres
, ctxt
->password
, ctxt
->userid
, ctxt
->flags
);
1804 else if ((caps
& WNNC_CON_ADDCONNECTION
) && provider
->addConnection
)
1805 ret
= provider
->addConnection(netres
, ctxt
->password
, ctxt
->userid
);
1807 if (ret
== WN_ALREADY_CONNECTED
&& redirect
)
1808 netres
->lpLocalName
[0] -= 1;
1809 } while (redirect
&& ret
== WN_ALREADY_CONNECTED
&& netres
->lpLocalName
[0] >= 'C');
1811 if (ret
== WN_SUCCESS
&& ctxt
->accessname
)
1812 ctxt
->set_accessname(ctxt
, netres
->lpLocalName
);
1817 static DWORD
wnet_use_connection( struct use_connection_context
*ctxt
)
1819 WNetProvider
*provider
;
1820 DWORD index
, ret
= WN_NO_NETWORK
;
1821 BOOL redirect
= FALSE
;
1822 WCHAR letter
[3] = {'Z', ':', 0};
1823 NETRESOURCEW netres
;
1825 if (!providerTable
|| providerTable
->numProviders
== 0)
1826 return WN_NO_NETWORK
;
1828 if (!ctxt
->resource
)
1829 return ERROR_INVALID_PARAMETER
;
1830 netres
= *ctxt
->resource
;
1832 if (!netres
.lpLocalName
&& (ctxt
->flags
& CONNECT_REDIRECT
))
1834 if (netres
.dwType
!= RESOURCETYPE_DISK
&& netres
.dwType
!= RESOURCETYPE_PRINT
)
1835 return ERROR_BAD_DEV_TYPE
;
1837 if (netres
.dwType
== RESOURCETYPE_PRINT
)
1839 FIXME("Local device selection is not implemented for printers.\n");
1840 return WN_NO_NETWORK
;
1844 netres
.lpLocalName
= letter
;
1847 if (ctxt
->flags
& CONNECT_INTERACTIVE
)
1848 return ERROR_BAD_NET_NAME
;
1850 if ((ret
= ctxt
->pre_set_accessname(ctxt
, netres
.lpLocalName
)))
1853 if (netres
.lpProvider
)
1855 index
= _findProviderIndexW(netres
.lpProvider
);
1856 if (index
== BAD_PROVIDER_INDEX
)
1857 return ERROR_BAD_PROVIDER
;
1859 provider
= &providerTable
->table
[index
];
1860 ret
= wnet_use_provider(ctxt
, &netres
, provider
, redirect
);
1864 for (index
= 0; index
< providerTable
->numProviders
; index
++)
1866 provider
= &providerTable
->table
[index
];
1867 ret
= wnet_use_provider(ctxt
, &netres
, provider
, redirect
);
1868 if (ret
== WN_SUCCESS
|| ret
== WN_ALREADY_CONNECTED
)
1876 /*****************************************************************
1877 * WNetUseConnectionW [MPR.@]
1879 DWORD WINAPI
WNetUseConnectionW( HWND hwndOwner
, NETRESOURCEW
*resource
, LPCWSTR password
,
1880 LPCWSTR userid
, DWORD flags
, LPWSTR accessname
, DWORD
*buffer_size
, DWORD
*result
)
1882 struct use_connection_context ctxt
;
1884 TRACE( "(%p, %p, %p, %s, 0x%08X, %p, %p, %p)\n",
1885 hwndOwner
, resource
, password
, debugstr_w(userid
), flags
,
1886 accessname
, buffer_size
, result
);
1888 ctxt
.hwndOwner
= hwndOwner
;
1889 ctxt
.resource
= resource
;
1890 ctxt
.resourceA
= NULL
;
1891 ctxt
.password
= (WCHAR
*)password
;
1892 ctxt
.userid
= (WCHAR
*)userid
;
1894 ctxt
.accessname
= accessname
;
1895 ctxt
.buffer_size
= buffer_size
;
1896 ctxt
.result
= result
;
1897 ctxt
.pre_set_accessname
= use_connection_pre_set_accessnameW
;
1898 ctxt
.set_accessname
= use_connection_set_accessnameW
;
1900 return wnet_use_connection(&ctxt
);
1903 static DWORD
use_connection_pre_set_accessnameA(struct use_connection_context
*ctxt
, WCHAR
*local_name
)
1905 if (ctxt
->accessname
&& ctxt
->buffer_size
&& *ctxt
->buffer_size
)
1910 len
= WideCharToMultiByte(CP_ACP
, 0, local_name
, -1, NULL
, 0, NULL
, NULL
) - 1;
1912 len
= strlen(ctxt
->resourceA
->lpRemoteName
);
1914 if (++len
> *ctxt
->buffer_size
)
1916 *ctxt
->buffer_size
= len
;
1917 return ERROR_MORE_DATA
;
1921 ctxt
->accessname
= NULL
;
1923 return ERROR_SUCCESS
;
1926 static void use_connection_set_accessnameA(struct use_connection_context
*ctxt
, WCHAR
*local_name
)
1928 char *accessname
= ctxt
->accessname
;
1931 WideCharToMultiByte(CP_ACP
, 0, local_name
, -1, accessname
, *ctxt
->buffer_size
, NULL
, NULL
);
1933 *ctxt
->result
= CONNECT_LOCALDRIVE
;
1936 strcpy(accessname
, ctxt
->resourceA
->lpRemoteName
);
1939 static LPWSTR
strdupAtoW( LPCSTR str
)
1944 if (!str
) return NULL
;
1945 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
1946 ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1947 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
1951 static void netresource_a_to_w( NETRESOURCEA
*resourceA
, NETRESOURCEW
*resourceW
)
1953 resourceW
->dwScope
= resourceA
->dwScope
;
1954 resourceW
->dwType
= resourceA
->dwType
;
1955 resourceW
->dwDisplayType
= resourceA
->dwDisplayType
;
1956 resourceW
->dwUsage
= resourceA
->dwUsage
;
1957 resourceW
->lpLocalName
= strdupAtoW(resourceA
->lpLocalName
);
1958 resourceW
->lpRemoteName
= strdupAtoW(resourceA
->lpRemoteName
);
1959 resourceW
->lpComment
= strdupAtoW(resourceA
->lpComment
);
1960 resourceW
->lpProvider
= strdupAtoW(resourceA
->lpProvider
);
1963 static void free_netresourceW( NETRESOURCEW
*resource
)
1965 HeapFree(GetProcessHeap(), 0, resource
->lpLocalName
);
1966 HeapFree(GetProcessHeap(), 0, resource
->lpRemoteName
);
1967 HeapFree(GetProcessHeap(), 0, resource
->lpComment
);
1968 HeapFree(GetProcessHeap(), 0, resource
->lpProvider
);
1971 /*****************************************************************
1972 * WNetUseConnectionA [MPR.@]
1974 DWORD WINAPI
WNetUseConnectionA( HWND hwndOwner
, NETRESOURCEA
*resource
,
1975 LPCSTR password
, LPCSTR userid
, DWORD flags
, LPSTR accessname
,
1976 DWORD
*buffer_size
, DWORD
*result
)
1978 struct use_connection_context ctxt
;
1979 NETRESOURCEW resourceW
;
1982 TRACE( "(%p, %p, %p, %s, 0x%08X, %p, %p, %p)\n", hwndOwner
, resource
, password
, debugstr_a(userid
), flags
,
1983 accessname
, buffer_size
, result
);
1985 netresource_a_to_w(resource
, &resourceW
);
1987 ctxt
.hwndOwner
= hwndOwner
;
1988 ctxt
.resource
= &resourceW
;
1989 ctxt
.resourceA
= resource
;
1990 ctxt
.password
= strdupAtoW(password
);
1991 ctxt
.userid
= strdupAtoW(userid
);
1993 ctxt
.accessname
= accessname
;
1994 ctxt
.buffer_size
= buffer_size
;
1995 ctxt
.result
= result
;
1996 ctxt
.pre_set_accessname
= use_connection_pre_set_accessnameA
;
1997 ctxt
.set_accessname
= use_connection_set_accessnameA
;
1999 ret
= wnet_use_connection(&ctxt
);
2001 free_netresourceW(&resourceW
);
2002 HeapFree(GetProcessHeap(), 0, ctxt
.password
);
2003 HeapFree(GetProcessHeap(), 0, ctxt
.userid
);
2008 /*********************************************************************
2009 * WNetCancelConnectionA [MPR.@]
2011 DWORD WINAPI
WNetCancelConnectionA( LPCSTR lpName
, BOOL fForce
)
2013 return WNetCancelConnection2A(lpName
, 0, fForce
);
2016 /*********************************************************************
2017 * WNetCancelConnectionW [MPR.@]
2019 DWORD WINAPI
WNetCancelConnectionW( LPCWSTR lpName
, BOOL fForce
)
2021 return WNetCancelConnection2W(lpName
, 0, fForce
);
2024 /*********************************************************************
2025 * WNetCancelConnection2A [MPR.@]
2027 DWORD WINAPI
WNetCancelConnection2A( LPCSTR lpName
, DWORD dwFlags
, BOOL fForce
)
2030 WCHAR
* name
= strdupAtoW(lpName
);
2032 return ERROR_NOT_CONNECTED
;
2034 ret
= WNetCancelConnection2W(name
, dwFlags
, fForce
);
2035 HeapFree(GetProcessHeap(), 0, name
);
2040 /*********************************************************************
2041 * WNetCancelConnection2W [MPR.@]
2043 DWORD WINAPI
WNetCancelConnection2W( LPCWSTR lpName
, DWORD dwFlags
, BOOL fForce
)
2045 DWORD ret
= WN_NO_NETWORK
;
2048 if (providerTable
!= NULL
)
2050 for (index
= 0; index
< providerTable
->numProviders
; index
++)
2052 if(providerTable
->table
[index
].getCaps(WNNC_CONNECTION
) &
2053 WNNC_CON_CANCELCONNECTION
)
2055 if (providerTable
->table
[index
].cancelConnection
)
2056 ret
= providerTable
->table
[index
].cancelConnection((LPWSTR
)lpName
, fForce
);
2058 ret
= WN_NO_NETWORK
;
2059 if (ret
== WN_SUCCESS
|| ret
== WN_OPEN_FILES
)
2067 /*****************************************************************
2068 * WNetRestoreConnectionA [MPR.@]
2070 DWORD WINAPI
WNetRestoreConnectionA( HWND hwndOwner
, LPCSTR lpszDevice
)
2072 FIXME( "(%p, %s), stub\n", hwndOwner
, debugstr_a(lpszDevice
) );
2074 SetLastError(WN_NO_NETWORK
);
2075 return WN_NO_NETWORK
;
2078 /*****************************************************************
2079 * WNetRestoreConnectionW [MPR.@]
2081 DWORD WINAPI
WNetRestoreConnectionW( HWND hwndOwner
, LPCWSTR lpszDevice
)
2083 FIXME( "(%p, %s), stub\n", hwndOwner
, debugstr_w(lpszDevice
) );
2085 SetLastError(WN_NO_NETWORK
);
2086 return WN_NO_NETWORK
;
2089 /**************************************************************************
2090 * WNetGetConnectionA [MPR.@]
2093 * - WN_BAD_LOCALNAME lpLocalName makes no sense
2094 * - WN_NOT_CONNECTED drive is a local drive
2095 * - WN_MORE_DATA buffer isn't big enough
2096 * - WN_SUCCESS success (net path in buffer)
2098 * FIXME: need to test return values under different errors
2100 DWORD WINAPI
WNetGetConnectionA( LPCSTR lpLocalName
,
2101 LPSTR lpRemoteName
, LPDWORD lpBufferSize
)
2106 ret
= WN_BAD_POINTER
;
2107 else if (!lpBufferSize
)
2108 ret
= WN_BAD_POINTER
;
2109 else if (!lpRemoteName
&& *lpBufferSize
)
2110 ret
= WN_BAD_POINTER
;
2113 int len
= MultiByteToWideChar(CP_ACP
, 0, lpLocalName
, -1, NULL
, 0);
2117 PWSTR wideLocalName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2121 WCHAR wideRemoteStatic
[MAX_PATH
];
2122 DWORD wideRemoteSize
= sizeof(wideRemoteStatic
) / sizeof(WCHAR
);
2124 MultiByteToWideChar(CP_ACP
, 0, lpLocalName
, -1, wideLocalName
, len
);
2126 /* try once without memory allocation */
2127 ret
= WNetGetConnectionW(wideLocalName
, wideRemoteStatic
,
2129 if (ret
== WN_SUCCESS
)
2131 int len
= WideCharToMultiByte(CP_ACP
, 0, wideRemoteStatic
,
2132 -1, NULL
, 0, NULL
, NULL
);
2134 if (len
<= *lpBufferSize
)
2136 WideCharToMultiByte(CP_ACP
, 0, wideRemoteStatic
, -1,
2137 lpRemoteName
, *lpBufferSize
, NULL
, NULL
);
2142 *lpBufferSize
= len
;
2146 else if (ret
== WN_MORE_DATA
)
2148 PWSTR wideRemote
= HeapAlloc(GetProcessHeap(), 0,
2149 wideRemoteSize
* sizeof(WCHAR
));
2153 ret
= WNetGetConnectionW(wideLocalName
, wideRemote
,
2155 if (ret
== WN_SUCCESS
)
2157 if (len
<= *lpBufferSize
)
2159 WideCharToMultiByte(CP_ACP
, 0, wideRemoteStatic
,
2160 -1, lpRemoteName
, *lpBufferSize
, NULL
, NULL
);
2165 *lpBufferSize
= len
;
2169 HeapFree(GetProcessHeap(), 0, wideRemote
);
2172 ret
= WN_OUT_OF_MEMORY
;
2174 HeapFree(GetProcessHeap(), 0, wideLocalName
);
2177 ret
= WN_OUT_OF_MEMORY
;
2180 ret
= WN_BAD_LOCALNAME
;
2184 TRACE("Returning %d\n", ret
);
2188 /* find the network connection for a given drive; helper for WNetGetConnection */
2189 static DWORD
get_drive_connection( WCHAR letter
, LPWSTR remote
, LPDWORD size
)
2192 struct mountmgr_unix_drive
*data
= (struct mountmgr_unix_drive
*)buffer
;
2194 DWORD ret
= WN_NOT_CONNECTED
;
2195 DWORD bytes_returned
;
2197 if ((mgr
= CreateFileW( MOUNTMGR_DOS_DEVICE_NAME
, GENERIC_READ
|GENERIC_WRITE
,
2198 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
2199 0, 0 )) == INVALID_HANDLE_VALUE
)
2201 ERR( "failed to open mount manager err %u\n", GetLastError() );
2204 memset( data
, 0, sizeof(*data
) );
2205 data
->letter
= letter
;
2206 if (DeviceIoControl( mgr
, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE
, data
, sizeof(*data
),
2207 data
, sizeof(buffer
), &bytes_returned
, NULL
))
2209 char *p
, *mount_point
= buffer
+ data
->mount_point_offset
;
2212 if (data
->mount_point_offset
&& !strncmp( mount_point
, "unc/", 4 ))
2215 mount_point
[0] = '\\';
2216 for (p
= mount_point
; *p
; p
++) if (*p
== '/') *p
= '\\';
2218 len
= MultiByteToWideChar( CP_UNIXCP
, 0, mount_point
, -1, NULL
, 0 );
2226 *size
= MultiByteToWideChar( CP_UNIXCP
, 0, mount_point
, -1, remote
, *size
);
2235 /**************************************************************************
2236 * WNetGetConnectionW [MPR.@]
2238 * FIXME: need to test return values under different errors
2240 DWORD WINAPI
WNetGetConnectionW( LPCWSTR lpLocalName
,
2241 LPWSTR lpRemoteName
, LPDWORD lpBufferSize
)
2245 TRACE("(%s, %p, %p)\n", debugstr_w(lpLocalName
), lpRemoteName
,
2249 ret
= WN_BAD_POINTER
;
2250 else if (!lpBufferSize
)
2251 ret
= WN_BAD_POINTER
;
2252 else if (!lpRemoteName
&& *lpBufferSize
)
2253 ret
= WN_BAD_POINTER
;
2254 else if (!lpLocalName
[0])
2255 ret
= WN_BAD_LOCALNAME
;
2258 if (lpLocalName
[1] == ':')
2260 switch(GetDriveTypeW(lpLocalName
))
2263 ret
= get_drive_connection( lpLocalName
[0], lpRemoteName
, lpBufferSize
);
2265 case DRIVE_REMOVABLE
:
2268 TRACE("file is local\n");
2269 ret
= WN_NOT_CONNECTED
;
2272 ret
= WN_BAD_LOCALNAME
;
2276 ret
= WN_BAD_LOCALNAME
;
2280 TRACE("Returning %d\n", ret
);
2284 /**************************************************************************
2285 * WNetSetConnectionA [MPR.@]
2287 DWORD WINAPI
WNetSetConnectionA( LPCSTR lpName
, DWORD dwProperty
,
2290 FIXME( "(%s, %08X, %p): stub\n", debugstr_a(lpName
), dwProperty
, pvValue
);
2292 SetLastError(WN_NO_NETWORK
);
2293 return WN_NO_NETWORK
;
2296 /**************************************************************************
2297 * WNetSetConnectionW [MPR.@]
2299 DWORD WINAPI
WNetSetConnectionW( LPCWSTR lpName
, DWORD dwProperty
,
2302 FIXME( "(%s, %08X, %p): stub\n", debugstr_w(lpName
), dwProperty
, pvValue
);
2304 SetLastError(WN_NO_NETWORK
);
2305 return WN_NO_NETWORK
;
2308 /*****************************************************************
2309 * WNetGetUniversalNameA [MPR.@]
2311 DWORD WINAPI
WNetGetUniversalNameA ( LPCSTR lpLocalPath
, DWORD dwInfoLevel
,
2312 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
2316 FIXME( "(%s, 0x%08X, %p, %p): stub\n",
2317 debugstr_a(lpLocalPath
), dwInfoLevel
, lpBuffer
, lpBufferSize
);
2319 switch (dwInfoLevel
)
2321 case UNIVERSAL_NAME_INFO_LEVEL
:
2323 LPUNIVERSAL_NAME_INFOA info
= lpBuffer
;
2325 if (GetDriveTypeA(lpLocalPath
) != DRIVE_REMOTE
)
2327 err
= ERROR_NOT_CONNECTED
;
2331 size
= sizeof(*info
) + lstrlenA(lpLocalPath
) + 1;
2332 if (*lpBufferSize
< size
)
2337 info
->lpUniversalName
= (char *)info
+ sizeof(*info
);
2338 lstrcpyA(info
->lpUniversalName
, lpLocalPath
);
2342 case REMOTE_NAME_INFO_LEVEL
:
2343 err
= WN_NO_NETWORK
;
2355 /*****************************************************************
2356 * WNetGetUniversalNameW [MPR.@]
2358 DWORD WINAPI
WNetGetUniversalNameW ( LPCWSTR lpLocalPath
, DWORD dwInfoLevel
,
2359 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
2363 FIXME( "(%s, 0x%08X, %p, %p): stub\n",
2364 debugstr_w(lpLocalPath
), dwInfoLevel
, lpBuffer
, lpBufferSize
);
2366 switch (dwInfoLevel
)
2368 case UNIVERSAL_NAME_INFO_LEVEL
:
2370 LPUNIVERSAL_NAME_INFOW info
= lpBuffer
;
2372 if (GetDriveTypeW(lpLocalPath
) != DRIVE_REMOTE
)
2374 err
= ERROR_NOT_CONNECTED
;
2378 size
= sizeof(*info
) + (lstrlenW(lpLocalPath
) + 1) * sizeof(WCHAR
);
2379 if (*lpBufferSize
< size
)
2384 info
->lpUniversalName
= (LPWSTR
)((char *)info
+ sizeof(*info
));
2385 lstrcpyW(info
->lpUniversalName
, lpLocalPath
);
2389 case REMOTE_NAME_INFO_LEVEL
:
2390 err
= WN_NO_NETWORK
;
2398 if (err
!= WN_NO_ERROR
) SetLastError(err
);
2408 /**************************************************************************
2409 * WNetGetUserA [MPR.@]
2411 * FIXME: we should not return ourselves, but the owner of the drive lpName
2413 DWORD WINAPI
WNetGetUserA( LPCSTR lpName
, LPSTR lpUserID
, LPDWORD lpBufferSize
)
2415 if (GetUserNameA( lpUserID
, lpBufferSize
)) return WN_SUCCESS
;
2416 return GetLastError();
2419 /*****************************************************************
2420 * WNetGetUserW [MPR.@]
2422 * FIXME: we should not return ourselves, but the owner of the drive lpName
2424 DWORD WINAPI
WNetGetUserW( LPCWSTR lpName
, LPWSTR lpUserID
, LPDWORD lpBufferSize
)
2426 if (GetUserNameW( lpUserID
, lpBufferSize
)) return WN_SUCCESS
;
2427 return GetLastError();
2430 /*********************************************************************
2431 * WNetConnectionDialog [MPR.@]
2433 DWORD WINAPI
WNetConnectionDialog( HWND hwnd
, DWORD dwType
)
2435 FIXME( "(%p, %08X): stub\n", hwnd
, dwType
);
2437 SetLastError(WN_NO_NETWORK
);
2438 return WN_NO_NETWORK
;
2441 /*********************************************************************
2442 * WNetConnectionDialog1A [MPR.@]
2444 DWORD WINAPI
WNetConnectionDialog1A( LPCONNECTDLGSTRUCTA lpConnDlgStruct
)
2446 FIXME( "(%p): stub\n", lpConnDlgStruct
);
2448 SetLastError(WN_NO_NETWORK
);
2449 return WN_NO_NETWORK
;
2452 /*********************************************************************
2453 * WNetConnectionDialog1W [MPR.@]
2455 DWORD WINAPI
WNetConnectionDialog1W( LPCONNECTDLGSTRUCTW lpConnDlgStruct
)
2457 FIXME( "(%p): stub\n", lpConnDlgStruct
);
2459 SetLastError(WN_NO_NETWORK
);
2460 return WN_NO_NETWORK
;
2463 /*********************************************************************
2464 * WNetDisconnectDialog [MPR.@]
2466 DWORD WINAPI
WNetDisconnectDialog( HWND hwnd
, DWORD dwType
)
2468 FIXME( "(%p, %08X): stub\n", hwnd
, dwType
);
2470 SetLastError(WN_NO_NETWORK
);
2471 return WN_NO_NETWORK
;
2474 /*********************************************************************
2475 * WNetDisconnectDialog1A [MPR.@]
2477 DWORD WINAPI
WNetDisconnectDialog1A( LPDISCDLGSTRUCTA lpConnDlgStruct
)
2479 FIXME( "(%p): stub\n", lpConnDlgStruct
);
2481 SetLastError(WN_NO_NETWORK
);
2482 return WN_NO_NETWORK
;
2485 /*********************************************************************
2486 * WNetDisconnectDialog1W [MPR.@]
2488 DWORD WINAPI
WNetDisconnectDialog1W( LPDISCDLGSTRUCTW lpConnDlgStruct
)
2490 FIXME( "(%p): stub\n", lpConnDlgStruct
);
2492 SetLastError(WN_NO_NETWORK
);
2493 return WN_NO_NETWORK
;
2496 /*********************************************************************
2497 * WNetGetLastErrorA [MPR.@]
2499 DWORD WINAPI
WNetGetLastErrorA( LPDWORD lpError
,
2500 LPSTR lpErrorBuf
, DWORD nErrorBufSize
,
2501 LPSTR lpNameBuf
, DWORD nNameBufSize
)
2503 FIXME( "(%p, %p, %d, %p, %d): stub\n",
2504 lpError
, lpErrorBuf
, nErrorBufSize
, lpNameBuf
, nNameBufSize
);
2506 SetLastError(WN_NO_NETWORK
);
2507 return WN_NO_NETWORK
;
2510 /*********************************************************************
2511 * WNetGetLastErrorW [MPR.@]
2513 DWORD WINAPI
WNetGetLastErrorW( LPDWORD lpError
,
2514 LPWSTR lpErrorBuf
, DWORD nErrorBufSize
,
2515 LPWSTR lpNameBuf
, DWORD nNameBufSize
)
2517 FIXME( "(%p, %p, %d, %p, %d): stub\n",
2518 lpError
, lpErrorBuf
, nErrorBufSize
, lpNameBuf
, nNameBufSize
);
2520 SetLastError(WN_NO_NETWORK
);
2521 return WN_NO_NETWORK
;
2524 /*********************************************************************
2525 * WNetGetNetworkInformationA [MPR.@]
2527 DWORD WINAPI
WNetGetNetworkInformationA( LPCSTR lpProvider
,
2528 LPNETINFOSTRUCT lpNetInfoStruct
)
2532 TRACE( "(%s, %p)\n", debugstr_a(lpProvider
), lpNetInfoStruct
);
2535 ret
= WN_BAD_POINTER
;
2540 len
= MultiByteToWideChar(CP_ACP
, 0, lpProvider
, -1, NULL
, 0);
2543 LPWSTR wideProvider
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2547 MultiByteToWideChar(CP_ACP
, 0, lpProvider
, -1, wideProvider
,
2549 ret
= WNetGetNetworkInformationW(wideProvider
, lpNetInfoStruct
);
2550 HeapFree(GetProcessHeap(), 0, wideProvider
);
2553 ret
= WN_OUT_OF_MEMORY
;
2556 ret
= GetLastError();
2560 TRACE("Returning %d\n", ret
);
2564 /*********************************************************************
2565 * WNetGetNetworkInformationW [MPR.@]
2567 DWORD WINAPI
WNetGetNetworkInformationW( LPCWSTR lpProvider
,
2568 LPNETINFOSTRUCT lpNetInfoStruct
)
2572 TRACE( "(%s, %p)\n", debugstr_w(lpProvider
), lpNetInfoStruct
);
2575 ret
= WN_BAD_POINTER
;
2576 else if (!lpNetInfoStruct
)
2577 ret
= WN_BAD_POINTER
;
2578 else if (lpNetInfoStruct
->cbStructure
< sizeof(NETINFOSTRUCT
))
2582 if (providerTable
&& providerTable
->numProviders
)
2584 DWORD providerIndex
= _findProviderIndexW(lpProvider
);
2586 if (providerIndex
!= BAD_PROVIDER_INDEX
)
2588 lpNetInfoStruct
->cbStructure
= sizeof(NETINFOSTRUCT
);
2589 lpNetInfoStruct
->dwProviderVersion
=
2590 providerTable
->table
[providerIndex
].dwSpecVersion
;
2591 lpNetInfoStruct
->dwStatus
= NO_ERROR
;
2592 lpNetInfoStruct
->dwCharacteristics
= 0;
2593 lpNetInfoStruct
->dwHandle
= 0;
2594 lpNetInfoStruct
->wNetType
=
2595 HIWORD(providerTable
->table
[providerIndex
].dwNetType
);
2596 lpNetInfoStruct
->dwPrinters
= -1;
2597 lpNetInfoStruct
->dwDrives
= -1;
2601 ret
= WN_BAD_PROVIDER
;
2604 ret
= WN_NO_NETWORK
;
2608 TRACE("Returning %d\n", ret
);
2612 /*****************************************************************
2613 * WNetGetProviderNameA [MPR.@]
2615 DWORD WINAPI
WNetGetProviderNameA( DWORD dwNetType
,
2616 LPSTR lpProvider
, LPDWORD lpBufferSize
)
2620 TRACE("(0x%08x, %s, %p)\n", dwNetType
, debugstr_a(lpProvider
),
2624 ret
= WN_BAD_POINTER
;
2625 else if (!lpBufferSize
)
2626 ret
= WN_BAD_POINTER
;
2633 ret
= WN_NO_NETWORK
;
2634 for (i
= 0; i
< providerTable
->numProviders
&&
2635 HIWORD(providerTable
->table
[i
].dwNetType
) != HIWORD(dwNetType
);
2638 if (i
< providerTable
->numProviders
)
2640 DWORD sizeNeeded
= WideCharToMultiByte(CP_ACP
, 0,
2641 providerTable
->table
[i
].name
, -1, NULL
, 0, NULL
, NULL
);
2643 if (*lpBufferSize
< sizeNeeded
)
2645 *lpBufferSize
= sizeNeeded
;
2650 WideCharToMultiByte(CP_ACP
, 0, providerTable
->table
[i
].name
,
2651 -1, lpProvider
, *lpBufferSize
, NULL
, NULL
);
2653 /* FIXME: is *lpBufferSize set to the number of characters
2659 ret
= WN_NO_NETWORK
;
2663 TRACE("Returning %d\n", ret
);
2667 /*****************************************************************
2668 * WNetGetProviderNameW [MPR.@]
2670 DWORD WINAPI
WNetGetProviderNameW( DWORD dwNetType
,
2671 LPWSTR lpProvider
, LPDWORD lpBufferSize
)
2675 TRACE("(0x%08x, %s, %p)\n", dwNetType
, debugstr_w(lpProvider
),
2679 ret
= WN_BAD_POINTER
;
2680 else if (!lpBufferSize
)
2681 ret
= WN_BAD_POINTER
;
2688 ret
= WN_NO_NETWORK
;
2689 for (i
= 0; i
< providerTable
->numProviders
&&
2690 HIWORD(providerTable
->table
[i
].dwNetType
) != HIWORD(dwNetType
);
2693 if (i
< providerTable
->numProviders
)
2695 DWORD sizeNeeded
= strlenW(providerTable
->table
[i
].name
) + 1;
2697 if (*lpBufferSize
< sizeNeeded
)
2699 *lpBufferSize
= sizeNeeded
;
2704 strcpyW(lpProvider
, providerTable
->table
[i
].name
);
2706 /* FIXME: is *lpBufferSize set to the number of characters
2712 ret
= WN_NO_NETWORK
;
2716 TRACE("Returning %d\n", ret
);