349f7acd803af022db780a87f59e92cff72265b8
[reactos.git] / reactos / dll / win32 / mpr / mpr_ros.diff
1 Index: mpr.spec
2 ===================================================================
3 --- mpr.spec (revision 49877)
4 +++ mpr.spec (working copy)
5 @@ -1,23 +1,23 @@
6 # ordinal exports
7 - 1 stub @
8 - 2 stub @
9 - 3 stub @
10 - 4 stub @
11 - 5 stub @
12 - 6 stub @
13 - 7 stub @
14 - 8 stub @
15 - 9 stub @
16 -12 stub @
17 -13 stub @
18 -14 stub @
19 -15 stub @
20 -16 stub @
21 -17 stub @
22 -18 stub @
23 -19 stub @
24 -20 stub @
25 -21 stub @
26 + 1 stub MPR_1
27 + 2 stub MPR_2
28 + 3 stub MPR_3
29 + 4 stub MPR_4
30 + 5 stub MPR_5
31 + 6 stub MPR_6
32 + 7 stub MPR_7
33 + 8 stub MPR_8
34 + 9 stub MPR_9
35 +12 stub MPR_12
36 +13 stub MPR_13
37 +14 stub MPR_14
38 +15 stub MPR_15
39 +16 stub MPR_16
40 +17 stub MPR_17
41 +18 stub MPR_18
42 +19 stub MPR_19
43 +20 stub MPR_20
44 +21 stub MPR_21
45 22 stdcall @(long) MPR_Alloc
46 23 stdcall @(ptr long) MPR_ReAlloc
47 24 stdcall @(ptr) MPR_Free
48 Index: wnet.c
49 ===================================================================
50 --- wnet.c (revision 71983)
51 +++ wnet.c (working copy)
52 @@ -60,6 +50,9 @@
53 PF_NPAddConnection addConnection;
54 PF_NPAddConnection3 addConnection3;
55 PF_NPCancelConnection cancelConnection;
56 +#ifdef __REACTOS__
57 + PF_NPGetConnection getConnection;
58 +#endif
59 } WNetProvider, *PWNetProvider;
60
61 typedef struct _WNetProviderTable
62 @@ -214,6 +207,9 @@
63 provider->addConnection = MPR_GETPROC(NPAddConnection);
64 provider->addConnection3 = MPR_GETPROC(NPAddConnection3);
65 provider->cancelConnection = MPR_GETPROC(NPCancelConnection);
66 +#ifdef __REACTOS__
67 + provider->getConnection = MPR_GETPROC(NPGetConnection);
68 +#endif
69 TRACE("NPAddConnection %p\n", provider->addConnection);
70 TRACE("NPAddConnection3 %p\n", provider->addConnection3);
71 TRACE("NPCancelConnection %p\n", provider->cancelConnection);
72 @@ -251,6 +247,85 @@
73 debugstr_w(provider));
74 }
75
76 +#ifdef __REACTOS__
77 +static void _restoreSavedConnection(HKEY connection, WCHAR * local)
78 +{
79 + NETRESOURCEW net;
80 + DWORD type, prov, index, size;
81 +
82 + net.lpProvider = NULL;
83 + net.lpRemoteName = NULL;
84 + net.lpLocalName = NULL;
85 +
86 + TRACE("Restoring: %S\n", local);
87 +
88 + size = sizeof(DWORD);
89 + if (RegQueryValueExW(connection, L"ConnectionType", NULL, &type, (BYTE *)&net.dwType, &size) != ERROR_SUCCESS)
90 + return;
91 +
92 + if (type != REG_DWORD || size != sizeof(DWORD))
93 + return;
94 +
95 + if (RegQueryValueExW(connection, L"ProviderName", NULL, &type, NULL, &size) != ERROR_SUCCESS)
96 + return;
97 +
98 + if (type != REG_SZ)
99 + return;
100 +
101 + net.lpProvider = HeapAlloc(GetProcessHeap(), 0, size);
102 + if (!net.lpProvider)
103 + return;
104 +
105 + if (RegQueryValueExW(connection, L"ProviderName", NULL, NULL, (BYTE *)net.lpProvider, &size) != ERROR_SUCCESS)
106 + goto cleanup;
107 +
108 + size = sizeof(DWORD);
109 + if (RegQueryValueExW(connection, L"ProviderType", NULL, &type, (BYTE *)&prov, &size) != ERROR_SUCCESS)
110 + goto cleanup;
111 +
112 + if (type != REG_DWORD || size != sizeof(DWORD))
113 + goto cleanup;
114 +
115 + index = _findProviderIndexW(net.lpProvider);
116 + if (index == BAD_PROVIDER_INDEX)
117 + goto cleanup;
118 +
119 + if (providerTable->table[index].dwNetType != prov)
120 + goto cleanup;
121 +
122 + if (RegQueryValueExW(connection, L"RemotePath", NULL, &type, NULL, &size) != ERROR_SUCCESS)
123 + goto cleanup;
124 +
125 + if (type != REG_SZ)
126 + goto cleanup;
127 +
128 + net.lpRemoteName = HeapAlloc(GetProcessHeap(), 0, size);
129 + if (!net.lpRemoteName)
130 + goto cleanup;
131 +
132 + if (RegQueryValueExW(connection, L"RemotePath", NULL, NULL, (BYTE *)net.lpRemoteName, &size) != ERROR_SUCCESS)
133 + goto cleanup;
134 +
135 + size = strlenW(local);
136 + net.lpLocalName = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR) + 2 * sizeof(WCHAR));
137 + if (!net.lpLocalName)
138 + goto cleanup;
139 +
140 + strcpyW(net.lpLocalName, local);
141 + net.lpLocalName[size] = ':';
142 + net.lpLocalName[size + 1] = 0;
143 +
144 + TRACE("Attempting connection\n");
145 +
146 + WNetAddConnection2W(&net, NULL, NULL, 0);
147 +
148 +cleanup:
149 + HeapFree(GetProcessHeap(), 0, net.lpProvider);
150 + HeapFree(GetProcessHeap(), 0, net.lpRemoteName);
151 + HeapFree(GetProcessHeap(), 0, net.lpLocalName);
152 +}
153 +#endif
154 +
155 void wnetInit(HINSTANCE hInstDll)
156 {
157 static const WCHAR providerOrderKey[] = { 'S','y','s','t','e','m','\\',
158 @@ -329,6 +404,64 @@
159 }
160 RegCloseKey(hKey);
161 }
162 +
163 +#ifdef __REACTOS__
164 + if (providerTable)
165 + {
166 + HKEY user_profile;
167 +
168 + if (RegOpenCurrentUser(KEY_ALL_ACCESS, &user_profile) == ERROR_SUCCESS)
169 + {
170 + HKEY network;
171 + WCHAR subkey[8] = {'N', 'e', 't', 'w', 'o', 'r', 'k', 0};
172 +
173 + if (RegOpenKeyExW(user_profile, subkey, 0, KEY_READ, &network) == ERROR_SUCCESS)
174 + {
175 + DWORD size, max;
176 +
177 + TRACE("Enumerating remembered connections\n");
178 +
179 + if (RegQueryInfoKey(network, NULL, NULL, NULL, &max, &size, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
180 + {
181 + WCHAR *local;
182 +
183 + TRACE("There are %lu connections\n", max);
184 +
185 + local = HeapAlloc(GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR));
186 + if (local)
187 + {
188 + DWORD index;
189 +
190 + for (index = 0; index < max; ++index)
191 + {
192 + DWORD len = size + 1;
193 + HKEY connection;
194 +
195 + TRACE("Trying connection %lu\n", index);
196 +
197 + if (RegEnumKeyExW(network, index, local, &len, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
198 + continue;
199 +
200 + TRACE("It is %S\n", local);
201 +
202 + if (RegOpenKeyExW(network, local, 0, KEY_READ, &connection) != ERROR_SUCCESS)
203 + continue;
204 +
205 + _restoreSavedConnection(connection, local);
206 + RegCloseKey(connection);
207 + }
208 +
209 + HeapFree(GetProcessHeap(), 0, local);
210 + }
211 + }
212 +
213 + RegCloseKey(network);
214 + }
215 +
216 + RegCloseKey(user_profile);
217 + }
218 + }
219 +#endif
220 }
221
222 void wnetFree(void)
223 @@ -1870,6 +2003,43 @@
224 }
225 }
226
227 +#ifdef __REACTOS__
228 + if (ret == WN_SUCCESS && ctxt->flags & CONNECT_UPDATE_PROFILE)
229 + {
230 + HKEY user_profile;
231 +
232 + if (netres.dwType == RESOURCETYPE_PRINT)
233 + {
234 + FIXME("Persistent connection are not supported for printers\n");
235 + return ret;
236 + }
237 +
238 + if (RegOpenCurrentUser(KEY_ALL_ACCESS, &user_profile) == ERROR_SUCCESS)
239 + {
240 + HKEY network;
241 + WCHAR subkey[10] = {'N', 'e', 't', 'w', 'o', 'r', 'k', '\\', netres.lpLocalName[0], 0};
242 +
243 + if (RegCreateKeyExW(user_profile, subkey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &network, NULL) == ERROR_SUCCESS)
244 + {
245 + DWORD dword_arg = RESOURCETYPE_DISK;
246 + DWORD len = (strlenW(provider->name) + 1) * sizeof(WCHAR);
247 +
248 + RegSetValueExW(network, L"ConnectionType", 0, REG_DWORD, (const BYTE *)&dword_arg, sizeof(DWORD));
249 + RegSetValueExW(network, L"ProviderName", 0, REG_SZ, (const BYTE *)provider->name, len);
250 + dword_arg = provider->dwNetType;
251 + RegSetValueExW(network, L"ProviderType", 0, REG_DWORD, (const BYTE *)&dword_arg, sizeof(DWORD));
252 + len = (strlenW(netres.lpRemoteName) + 1) * sizeof(WCHAR);
253 + RegSetValueExW(network, L"RemotePath", 0, REG_SZ, (const BYTE *)netres.lpRemoteName, len);
254 + len = 0;
255 + RegSetValueExW(network, L"UserName", 0, REG_SZ, (const BYTE *)netres.lpRemoteName, len);
256 + RegCloseKey(network);
257 + }
258 +
259 + RegCloseKey(user_profile);
260 + }
261 + }
262 +#endif
263 +
264 return ret;
265 }
266
267 @@ -2061,6 +2231,37 @@
268 }
269 }
270 }
271 +#ifdef __REACTOS__
272 +
273 + if (dwFlags & CONNECT_UPDATE_PROFILE)
274 + {
275 + HKEY user_profile;
276 + WCHAR *coma = strchrW(lpName, ':');
277 +
278 + if (coma && RegOpenCurrentUser(KEY_ALL_ACCESS, &user_profile) == ERROR_SUCCESS)
279 + {
280 + WCHAR *subkey;
281 + DWORD len;
282 +
283 + len = (ULONG_PTR)coma - (ULONG_PTR)lpName + sizeof(L"Network\\");
284 + subkey = HeapAlloc(GetProcessHeap(), 0, len);
285 + if (subkey)
286 + {
287 + strcpyW(subkey, L"Network\\");
288 + memcpy(subkey + (sizeof(L"Network\\") / sizeof(WCHAR)) - 1, lpName, (ULONG_PTR)coma - (ULONG_PTR)lpName);
289 + subkey[len / sizeof(WCHAR) - 1] = 0;
290 +
291 + TRACE("Removing: %S\n", subkey);
292 +
293 + RegDeleteKeyW(user_profile, subkey);
294 + HeapFree(GetProcessHeap(), 0, subkey);
295 + }
296 +
297 + RegCloseKey(user_profile);
298 + }
299 + }
300 +
301 +#endif
302 return ret;
303 }
304
305 @@ -2188,6 +2389,7 @@
306 /* find the network connection for a given drive; helper for WNetGetConnection */
307 static DWORD get_drive_connection( WCHAR letter, LPWSTR remote, LPDWORD size )
308 {
309 +#ifndef __REACTOS__
310 char buffer[1024];
311 struct mountmgr_unix_drive *data = (struct mountmgr_unix_drive *)buffer;
312 HANDLE mgr;
313 @@ -2230,6 +2432,32 @@
314 }
315 CloseHandle( mgr );
316 return ret;
317 +#else
318 + DWORD ret = WN_NO_NETWORK;
319 + DWORD index;
320 + WCHAR local[3] = {letter, ':', 0};
321 +
322 + if (providerTable != NULL)
323 + {
324 + for (index = 0; index < providerTable->numProviders; index++)
325 + {
326 + if(providerTable->table[index].getCaps(WNNC_CONNECTION) &
327 + WNNC_CON_GETCONNECTIONS)
328 + {
329 + if (providerTable->table[index].getConnection)
330 + ret = providerTable->table[index].getConnection(
331 + local, remote, size);
332 + else
333 + ret = WN_NO_NETWORK;
334 + if (ret == WN_SUCCESS || ret == WN_MORE_DATA)
335 + break;
336 + }
337 + }
338 + }
339 + if (ret)
340 + SetLastError(ret);
341 + return ret;
342 +#endif
343 }
344
345 /**************************************************************************